bfg-common 1.5.486 → 1.5.487

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/assets/localization/local_be.json +2 -1
  2. package/assets/localization/local_en.json +2 -1
  3. package/assets/localization/local_hy.json +2 -1
  4. package/assets/localization/local_kk.json +2 -1
  5. package/assets/localization/local_ru.json +2 -1
  6. package/assets/localization/local_zh.json +2 -1
  7. package/assets/scss/common/theme.scss +2 -2
  8. package/components/common/layout/theHeader/feedback/new/New.vue +2 -2
  9. package/components/common/layout/theHeader/feedback/new/description/Description.vue +3 -3
  10. package/components/common/layout/theHeader/feedback/new/tabs/Tabs.vue +4 -2
  11. package/components/common/layout/theHeader/feedback/new/tabs/lib/config/tabs.ts +3 -2
  12. package/components/common/layout/theHeader/feedback/new/tabs/lib/models/interfaces.ts +5 -0
  13. package/components/common/layout/theHeader/helpMenu/aboutNew/AboutNew.vue +96 -95
  14. package/components/common/layout/theHeader/userMenu/modals/changePassword/ChangePasswordNew.vue +1 -2
  15. package/components/common/layout/theHeader/userMenu/modals/preferences/PreferencesNew.vue +9 -0
  16. package/components/common/layout/theHeader/userMenu/modals/preferences/view/ViewNew.vue +6 -2
  17. package/components/common/monitor/advanced/tools/chartOptionsModal/ChartOptionsModalNew.vue +1 -0
  18. package/components/common/monitor/overview/OverviewNew.vue +4 -1
  19. package/components/common/monitor/overview/filters/customIntervalModal/CustomIntervalModal.vue +0 -2
  20. package/components/common/monitor/overview/filters/customIntervalModal/customIntervalModalNew/CustomIntervalModalNew.vue +6 -6
  21. package/components/common/pages/tasks/table/Table.vue +8 -9
  22. package/components/common/vm/actions/add/Add.vue +877 -850
  23. package/components/common/vm/actions/add/New.vue +8 -2
  24. package/components/common/vm/actions/add/Old.vue +8 -2
  25. package/components/common/vm/actions/add/lib/config/steps.ts +14 -3
  26. package/components/common/vm/actions/common/select/name/Name.vue +3 -0
  27. package/components/common/vm/actions/common/select/name/Old.vue +131 -124
  28. package/components/common/vmt/actions/add/Add.vue +549 -548
  29. package/package.json +1 -1
@@ -1,850 +1,877 @@
1
- <template>
2
- <common-vm-actions-add-new
3
- v-if="isNewView"
4
- v-model:vm-form="vmForm"
5
- v-model:selected-create-type="selectedCreateType"
6
- v-model:is-power-on-by-default="isPowerOnByDefault"
7
- :project="props.project"
8
- :nodes="props.nodes"
9
- :files="props.files"
10
- :networks-table="props.networksTable"
11
- :datastore="props.datastore"
12
- :is-datastore-loading="props.isDatastoreLoading"
13
- :error-validation-fields="props.errorValidationFields"
14
- :ready-complete-table-info="props.readyCompleteTableInfo"
15
- :vm-cpu-help-text-second="props.vmCpuHelpTextSecond"
16
- :import-from-v-m-warev-sphere="props.importFromVMWarevSphere"
17
- :get-datastore-table-func="props.getDatastoreTableFunc"
18
- :passthrough-devices="props.passthroughDevices"
19
- :mediated-devices="props.mediatedDevices"
20
- :templates-tree="props.templatesTree"
21
- :wizard="wizard"
22
- :selected-scheme="selectedScheme"
23
- :template-submit="templateSubmit"
24
- :name-form-submit="nameFormSubmit"
25
- :storage-submit="storageSubmit"
26
- :customize-hardware-submit="customizeHardwareSubmit"
27
- :customize-hardware-for-template-submit="customizeHardwareForTemplateSubmit"
28
- :is-sphere="isSphere"
29
- :compatibility="compatibility"
30
- :guestOsFamilies="guestOsFamilies"
31
- :guestOsVersions="guestOsVersions"
32
- :machineTypes="machineTypes"
33
- :virtual-hardware-hard-disks-local="virtualHardwareHardDisksLocal"
34
- :virtual-hardware-cd-dvd-drives-local="virtualHardwareCdDvdDrivesLocal"
35
- :virtual-hardware-networks-local="virtualHardwareNetworksLocal"
36
- :max-cpus="maxCpus"
37
- :max-memory="maxMemory"
38
- :cpu-models="cpuModels"
39
- :selected-nav-item="selectedNavItem"
40
- :compatibility-info="compatibilityInfo"
41
- :is-show-power-on="isShowPowerOn"
42
- :is-show-select-template="isShowSelectTemplate"
43
- :compute-resource-submit="computeResourceSubmit"
44
- :data-center="props.dataCenter"
45
- :compute-resource="props.computeResource"
46
- :compute-resource-tree="props.computeResourceTree"
47
- :vmt-settings="props.vmtSettings"
48
- :is-loading="isLoading"
49
- :selected-template-id="props.selectedTemplateId"
50
- @check-name="emits('check-name', $event)"
51
- @get-storage="emits('get-storage', $event)"
52
- @get-folders-or-files="emits('get-folders-or-files', $event)"
53
- @get-active-device-child="emits('get-active-device-child', $event)"
54
- @show-datastore-child="emits('show-datastore-child', $event)"
55
- @remove-error-by-title="emits('remove-error-by-title', $event)"
56
- @get-networks-table="emits('get-networks-table', $event)"
57
- @get-pci-devices="emits('get-pci-devices')"
58
- @change-steps="onChangeSteps"
59
- @change-template="onChangeTemplate"
60
- @change-name="onChangeName(...$event)"
61
- @change-storage="onChangeStorage"
62
- @change-select-options="onChangeSelectOptions"
63
- @change-compatibility="onChangeCompatibility"
64
- @change-boot-order="onChangeBootOrder"
65
- @change-customize-hardware="onChangeCustomizeHardware"
66
- @clear-compute-resource-tree="emits('clear-compute-resource-tree')"
67
- @change-compute-resource="onChangeComputeResource"
68
- @select-compute-resource-tree="onSelectComputeResourceTree"
69
- @get-compute-resource-tree="emits('get-compute-resource-tree', $event)"
70
- @show-compute-resource-tree="emits('show-compute-resource-tree', $event)"
71
- @finish="onFinish"
72
- @hide="onHideModal"
73
- />
74
- <common-vm-actions-add-old
75
- v-else
76
- v-model:vm-form="vmForm"
77
- v-model:selected-create-type="selectedCreateType"
78
- v-model:is-power-on-by-default="isPowerOnByDefault"
79
- :project="props.project"
80
- :nodes="props.nodes"
81
- :files="props.files"
82
- :networks-table="props.networksTable"
83
- :datastore="props.datastore"
84
- :is-datastore-loading="props.isDatastoreLoading"
85
- :error-validation-fields="props.errorValidationFields"
86
- :ready-complete-table-info="props.readyCompleteTableInfo"
87
- :vm-cpu-help-text-second="props.vmCpuHelpTextSecond"
88
- :import-from-v-m-warev-sphere="props.importFromVMWarevSphere"
89
- :get-datastore-table-func="props.getDatastoreTableFunc"
90
- :passthrough-devices="props.passthroughDevices"
91
- :mediated-devices="props.mediatedDevices"
92
- :templates-tree="props.templatesTree"
93
- :wizard="wizard"
94
- :selected-scheme="selectedScheme"
95
- :template-submit="templateSubmit"
96
- :name-form-submit="nameFormSubmit"
97
- :storage-submit="storageSubmit"
98
- :customize-hardware-submit="customizeHardwareSubmit"
99
- :customize-hardware-for-template-submit="customizeHardwareForTemplateSubmit"
100
- :is-sphere="isSphere"
101
- :compatibility="compatibility"
102
- :guestOsFamilies="guestOsFamilies"
103
- :guestOsVersions="guestOsVersions"
104
- :machineTypes="machineTypes"
105
- :virtual-hardware-hard-disks-local="virtualHardwareHardDisksLocal"
106
- :virtual-hardware-cd-dvd-drives-local="virtualHardwareCdDvdDrivesLocal"
107
- :virtual-hardware-networks-local="virtualHardwareNetworksLocal"
108
- :max-cpus="maxCpus"
109
- :max-memory="maxMemory"
110
- :cpu-models="cpuModels"
111
- :selected-nav-item="selectedNavItem"
112
- :compatibility-info="compatibilityInfo"
113
- :is-show-power-on="isShowPowerOn"
114
- :compute-resource-submit="computeResourceSubmit"
115
- :data-center="props.dataCenter"
116
- :compute-resource="props.computeResource"
117
- :compute-resource-tree="props.computeResourceTree"
118
- :vmt-settings="props.vmtSettings"
119
- :is-loading="isLoading"
120
- @check-name="emits('check-name', $event)"
121
- @get-storage="emits('get-storage', $event)"
122
- @get-folders-or-files="emits('get-folders-or-files', $event)"
123
- @get-active-device-child="emits('get-active-device-child', $event)"
124
- @show-datastore-child="emits('show-datastore-child', $event)"
125
- @remove-error-by-title="emits('remove-error-by-title', $event)"
126
- @get-networks-table="emits('get-networks-table', $event)"
127
- @get-pci-devices="emits('get-pci-devices')"
128
- @change-steps="onChangeSteps"
129
- @change-template="onChangeTemplate"
130
- @change-name="onChangeName(...$event)"
131
- @change-storage="onChangeStorage"
132
- @change-select-options="onChangeSelectOptions"
133
- @change-compatibility="onChangeCompatibility"
134
- @change-boot-order="onChangeBootOrder"
135
- @change-customize-hardware="onChangeCustomizeHardware"
136
- @clear-compute-resource-tree="emits('clear-compute-resource-tree')"
137
- @change-compute-resource="onChangeComputeResource"
138
- @select-compute-resource-tree="onSelectComputeResourceTree"
139
- @get-compute-resource-tree="emits('get-compute-resource-tree', $event)"
140
- @show-compute-resource-tree="emits('show-compute-resource-tree', $event)"
141
- @finish="onFinish"
142
- @hide="onHideModal"
143
- />
144
- </template>
145
-
146
- <script setup lang="ts">
147
- import type {
148
- UI_I_ValidationReturn,
149
- UI_I_WizardStep,
150
- } from '~/node_modules/bfg-uikit/components/ui/wizard/lib/models/interfaces'
151
- import Wizard from '~/node_modules/bfg-uikit/components/ui/wizard/lib/utils/utils'
152
- import type {
153
- UI_I_Localization,
154
- UI_I_ArbitraryObject,
155
- } from '~/lib/models/interfaces'
156
- import type { UI_T_Project } from '~/lib/models/types'
157
- import type { UI_I_FileTreeNode } from '~/components/lib/models/interfaces'
158
- import type { UI_I_NetworkTableItem } from '~/lib/models/store/network/interfaces'
159
- import type {
160
- UI_I_DatastoreTableItem,
161
- UI_I_FolderOrFileTreePayload,
162
- } from '~/lib/models/store/storage/interfaces'
163
- import type {
164
- API_UI_I_Error,
165
- UI_I_ErrorValidationField,
166
- } from '~/lib/models/store/interfaces'
167
- import type { UI_I_TablePayload } from '~/lib/models/table/interfaces'
168
- import type { UI_I_TableInfoItem } from '~/components/atoms/table/info/lib/models/interfaces'
169
- import type {
170
- UI_T_AddVmFinishFunc,
171
- UI_T_SelectedNavItem,
172
- } from '~/components/common/vm/actions/common/lib/models/types'
173
- import type { UI_I_TreeNode } from '~/components/common/recursionTree/lib/models/interfaces'
174
- import type {
175
- UI_I_Capabilities,
176
- UI_I_VmForm,
177
- UI_I_VmFormCash,
178
- } from '~/components/common/vm/actions/common/lib/models/interfaces'
179
- import type { UI_I_SendDataCustomizeHardware } from '~/components/common/vm/actions/common/customizeHardware/lib/models/interfaces'
180
- import type {
181
- UI_I_SendDataCpu,
182
- UI_I_SendDataMemory,
183
- UI_I_SendDataNewCdDvdDrive,
184
- UI_I_SendDataNewHardDisk,
185
- UI_I_SendDataNewNetwork,
186
- } from '~/components/common/vm/actions/common/customizeHardware/virtualHardware/lib/models/interfaces'
187
- import type { UI_I_OptionItem } from '~/components/atoms/lib/models/interfaces'
188
- import type { UI_T_ChangeBootOrder } from '~/components/common/vm/actions/lib/models/types'
189
- import type {
190
- UI_I_MediatedDevice,
191
- UI_I_PciDevice,
192
- UI_I_VmSettings,
193
- } from '~/lib/models/store/vm/interfaces'
194
- import { capabilities } from '~/components/common/vm/actions/common/lib/config/capabilities'
195
- import {
196
- stepsSchemeInitial,
197
- stepsFunc,
198
- dynamicSteps,
199
- } from '~/components/common/vm/actions/add/lib/config/steps'
200
- import { mapCapabilities } from '~/components/common/vm/actions/common/lib/utils/capabilities'
201
-
202
- const props = withDefaults(
203
- defineProps<{
204
- project: UI_T_Project
205
- nodes: UI_I_FileTreeNode[]
206
- files: UI_I_FileTreeNode[]
207
- networksTable: UI_I_NetworkTableItem[]
208
- datastore: UI_I_DatastoreTableItem[]
209
- isDatastoreLoading: boolean
210
- errorValidationFields: UI_I_ErrorValidationField[]
211
- readyCompleteTableInfo: UI_I_TableInfoItem[]
212
- vmCpuHelpTextSecond: string
213
- importFromVMWarevSphere: string
214
- finishFunc: UI_T_AddVmFinishFunc
215
- getDatastoreTableFunc: (payload: UI_I_TablePayload) => Promise<void>
216
- validateSendDataFunc: UI_T_AddVmFinishFunc<
217
- [UI_T_SelectedNavItem, null | number] | null
218
- >
219
- passthroughDevices: UI_I_PciDevice[]
220
- mediatedDevices: UI_I_MediatedDevice[]
221
- vmNameInWizard: string
222
- templatesTree: UI_I_TreeNode[]
223
- capabilities?: UI_I_Capabilities
224
- vmtSettings?: UI_I_VmSettings | null
225
- dataCenter?: UI_I_TreeNode // для сферы
226
- computeResource?: UI_I_TreeNode // для сферы
227
- computeResourceTree?: UI_I_TreeNode[] // для сферы
228
- selectedTemplateId?: string // для сферы
229
- }>(),
230
- {
231
- capabilities: undefined,
232
- vmtSettings: undefined,
233
- dataCenter: undefined,
234
- computeResource: undefined,
235
- computeResourceTree: undefined,
236
- selectedTemplateId: '',
237
- }
238
- )
239
-
240
- const emits = defineEmits<{
241
- (event: 'check-name', value: [string, (error: API_UI_I_Error) => void]): void
242
- (event: 'get-storage', value: UI_I_TablePayload): void
243
- (event: 'get-folders-or-files', value: UI_I_FolderOrFileTreePayload): void
244
- (event: 'get-active-device-child', value: UI_I_FileTreeNode): void
245
- (event: 'show-datastore-child', value: UI_I_FileTreeNode): void
246
- (event: 'remove-error-by-title', value: string): void
247
- (event: 'get-networks-table', value: UI_I_TablePayload): void
248
- (event: 'get-pci-devices'): void
249
- (event: 'get-pci-devices'): void
250
- (event: 'hide'): void
251
- (event: 'select-template', value: string): void
252
- (
253
- event: 'get-compute-resource-tree',
254
- value: { id: string | number; cb: () => void }
255
- ): void // для сферы
256
- (event: 'show-compute-resource-tree', value: UI_I_TreeNode): void // для сферы
257
- (event: 'select-compute-resource-tree', value: UI_I_TreeNode): void // для сферы
258
- (event: 'clear-compute-resource-tree'): void // для сферы
259
- }>()
260
-
261
- const { $store, $recursion }: any = useNuxtApp()
262
- const isNewView = computed<boolean>(() => $store.getters['main/getIsNewView'])
263
-
264
- const localization = computed<UI_I_Localization>(() => useLocal())
265
-
266
- const isSphere = computed<boolean>(() => props.project === 'sphere')
267
-
268
- watch(
269
- () => props.capabilities,
270
- () => {
271
- if (props.capabilities) mapCapabilities(props.capabilities)
272
- },
273
- { deep: true, immediate: true }
274
- )
275
-
276
- const selectedCreateType = ref<string>('0')
277
-
278
- const wizard: Wizard = new Wizard(
279
- stepsFunc(localization.value),
280
- stepsSchemeInitial
281
- )
282
- watch(
283
- selectedCreateType,
284
- (newValue) => {
285
- switch (newValue) {
286
- case '0':
287
- wizard.changeScheme(isSphere.value ? 1 : 0)
288
- break
289
- case '1':
290
- wizard.changeScheme(isSphere.value ? 6 : 2)
291
- }
292
- },
293
- { immediate: true }
294
- )
295
- // if (isSphere.value) wizard.changeScheme(1)
296
- const selectedScheme = computed<number[]>(() => wizard.selectedScheme.value)
297
- // const alertMessages = computed<string[][]>(() => wizard.alertMessages.value)
298
-
299
- const isShowSelectTemplate = computed<boolean>(
300
- () =>
301
- wizard.selectedStepId === dynamicSteps.selectTemplate &&
302
- selectedCreateType.value === '1'
303
- )
304
-
305
- const isShowPowerOn = computed<boolean>(
306
- () =>
307
- wizard.selectedStepId > dynamicSteps.customizeHardware &&
308
- selectedCreateType.value !== '1'
309
- )
310
-
311
- const onChangeSteps = async (value: UI_I_WizardStep[]): Promise<void> => {
312
- wizard.changeSteps(value, validationFunc, validateSendData)
313
- }
314
- const validationFunc = async (
315
- value: UI_I_WizardStep[],
316
- currentStep: UI_I_WizardStep,
317
- nextStep: UI_I_WizardStep
318
- ): Promise<UI_I_ValidationReturn> => {
319
- let stepHasError = false
320
- let stepShouldStop = {
321
- ifOnCurrentStep: false,
322
- ifFromAnyStep: false,
323
- stoppageStepId: -1,
324
- }
325
-
326
- wizard.setLoader(true)
327
- if (
328
- wizard.isValidateForStep(
329
- dynamicSteps.selectTemplate,
330
- currentStep.id,
331
- nextStep.id
332
- )
333
- ) {
334
- const templateValidation = await checkTemplate(value)
335
-
336
- value = templateValidation.newValue
337
- stepHasError = stepHasError || templateValidation.stepHasError
338
- } else if (
339
- wizard.isValidateForStep(
340
- isSphere.value ? dynamicSteps.selectNameFolder : dynamicSteps.selectName,
341
- currentStep.id,
342
- nextStep.id
343
- )
344
- ) {
345
- const nameValidation = await onCheckName(value)
346
-
347
- value = nameValidation.newValue
348
- stepHasError = stepHasError || nameValidation.stepHasError
349
- } else if (
350
- isSphere.value &&
351
- wizard.isValidateForStep(
352
- dynamicSteps.selectComputeResource,
353
- currentStep.id,
354
- nextStep.id
355
- )
356
- ) {
357
- const computeResourceValidation = await checkComputeResource(value)
358
-
359
- value = computeResourceValidation.newValue
360
- stepHasError = stepHasError || computeResourceValidation.stepHasError
361
- } else if (
362
- wizard.isValidateForStep(
363
- dynamicSteps.selectStorage,
364
- currentStep.id,
365
- nextStep.id
366
- )
367
- ) {
368
- const storageValidation = await checkStorage(value)
369
-
370
- value = storageValidation.newValue
371
-
372
- stepHasError = stepHasError || storageValidation.stepHasError
373
- } else if (
374
- wizard.isValidateForStep(
375
- dynamicSteps.customizeHardware,
376
- currentStep.id,
377
- nextStep.id
378
- )
379
- ) {
380
- const validation = await checkCustomizeHardware(value)
381
-
382
- value = validation.newValue
383
-
384
- stepHasError = stepHasError || validation.stepHasError
385
- } else if (
386
- wizard.isValidateForStep(
387
- dynamicSteps.customizeHardwareTemplate,
388
- currentStep.id,
389
- nextStep.id
390
- )
391
- ) {
392
- const validation = await checkCustomizeHardwareForTemplate(value)
393
-
394
- value = validation.newValue
395
-
396
- stepHasError = stepHasError || validation.stepHasError
397
- }
398
- wizard.setLoader(false)
399
-
400
- return {
401
- newValue: value,
402
- stepHasError,
403
- stepShouldStop,
404
- }
405
- }
406
-
407
- const checkTemplate = async (
408
- value: UI_I_WizardStep[]
409
- ): Promise<UI_I_ValidationReturn> => {
410
- let stepHasError = false
411
-
412
- return new Promise((resolve) => {
413
- templateSubmit.value = (isValid: boolean) => {
414
- if (!isValid) {
415
- stepHasError = wizard.setValidation(
416
- dynamicSteps.selectTemplate,
417
- 'template',
418
- {
419
- fieldMessage: 'aaa',
420
- alertMessage: 'aaa',
421
- }
422
- )
423
- } else if (wizard.hasMessage(dynamicSteps.selectTemplate, 'template')) {
424
- value = wizard.removeValidation(
425
- dynamicSteps.selectTemplate,
426
- 'template',
427
- value
428
- )
429
- }
430
-
431
- resolve({
432
- stepHasError,
433
- newValue: value,
434
- })
435
- templateSubmit.value = null
436
- }
437
- })
438
- }
439
- const onCheckName = async (
440
- value: UI_I_WizardStep[]
441
- ): Promise<UI_I_ValidationReturn> => {
442
- let stepHasError = false
443
-
444
- return new Promise((resolve) => {
445
- const step = isSphere.value
446
- ? dynamicSteps.selectNameFolder
447
- : dynamicSteps.selectName
448
- nameFormSubmit.value = (isValid: boolean) => {
449
- if (!isValid) {
450
- stepHasError = wizard.setValidation(step, 'name', {
451
- fieldMessage: 'aaa',
452
- alertMessage: 'aaa',
453
- })
454
- } else if (wizard.hasMessage(step, 'name')) {
455
- value = wizard.removeValidation(step, 'name', value)
456
- }
457
-
458
- resolve({
459
- stepHasError,
460
- newValue: value,
461
- })
462
- nameFormSubmit.value = null
463
- }
464
- })
465
- }
466
- const checkComputeResource = async (
467
- value: UI_I_WizardStep[]
468
- ): Promise<UI_I_ValidationReturn> => {
469
- let stepHasError = false
470
-
471
- return new Promise((resolve) => {
472
- computeResourceSubmit.value = (isValid: boolean) => {
473
- if (!isValid) {
474
- stepHasError = wizard.setValidation(
475
- dynamicSteps.selectComputeResource,
476
- 'computeResource',
477
- {
478
- fieldMessage: 'aaa',
479
- alertMessage: 'aaa',
480
- }
481
- )
482
- } else if (
483
- wizard.hasMessage(dynamicSteps.selectComputeResource, 'computeResource')
484
- ) {
485
- value = wizard.removeValidation(
486
- dynamicSteps.selectComputeResource,
487
- 'computeResource',
488
- value
489
- )
490
- }
491
-
492
- resolve({
493
- stepHasError,
494
- newValue: value,
495
- })
496
- computeResourceSubmit.value = null
497
- }
498
- })
499
- }
500
- const checkStorage = async (
501
- value: UI_I_WizardStep[]
502
- ): Promise<UI_I_ValidationReturn> => {
503
- let stepHasError = false
504
-
505
- return new Promise((resolve) => {
506
- storageSubmit.value = (isValid: boolean) => {
507
- if (!isValid) {
508
- stepHasError = wizard.setValidation(
509
- dynamicSteps.selectStorage,
510
- 'storage',
511
- {
512
- fieldMessage: 'aaa',
513
- alertMessage: 'aaa',
514
- }
515
- )
516
- } else if (wizard.hasMessage(dynamicSteps.selectStorage, 'storage')) {
517
- value = wizard.removeValidation(
518
- dynamicSteps.selectStorage,
519
- 'storage',
520
- value
521
- )
522
- }
523
-
524
- resolve({
525
- stepHasError,
526
- newValue: value,
527
- })
528
- storageSubmit.value = null
529
- }
530
- })
531
- }
532
- const checkCustomizeHardware = async (
533
- value: UI_I_WizardStep[]
534
- ): Promise<UI_I_ValidationReturn> => {
535
- let stepHasError = false
536
- isLoading.value = true
537
-
538
- return new Promise((resolve) => {
539
- customizeHardwareSubmit.value = (isValid: boolean) => {
540
- if (!isValid) {
541
- stepHasError = wizard.setValidation(
542
- dynamicSteps.customizeHardware,
543
- 'customizeHardware',
544
- {
545
- fieldMessage: 'aaa',
546
- alertMessage: 'aaa',
547
- }
548
- )
549
- } else if (
550
- wizard.hasMessage(dynamicSteps.customizeHardware, 'customizeHardware')
551
- ) {
552
- wizard.removeValidationLocal(
553
- dynamicSteps.customizeHardware,
554
- 'customizeHardware'
555
- )
556
- value = wizard.removeValidation(
557
- dynamicSteps.customizeHardware,
558
- 'customizeHardware',
559
- value
560
- )
561
- }
562
-
563
- resolve({
564
- stepHasError,
565
- newValue: value,
566
- })
567
- storageSubmit.value = null
568
- isLoading.value = false
569
- }
570
- })
571
- }
572
- const checkCustomizeHardwareForTemplate = async (
573
- value: UI_I_WizardStep[]
574
- ): Promise<UI_I_ValidationReturn> => {
575
- let stepHasError = false
576
-
577
- return new Promise((resolve) => {
578
- customizeHardwareForTemplateSubmit.value = (isValid: boolean) => {
579
- if (!isValid) {
580
- stepHasError = wizard.setValidation(
581
- dynamicSteps.customizeHardwareTemplate,
582
- 'customizeHardwareForTemplate',
583
- {
584
- fieldMessage: 'aaa',
585
- alertMessage: 'aaa',
586
- }
587
- )
588
- } else if (
589
- wizard.hasMessage(
590
- dynamicSteps.customizeHardwareTemplate,
591
- 'customizeHardwareForTemplate'
592
- )
593
- ) {
594
- value = wizard.removeValidation(
595
- dynamicSteps.customizeHardwareTemplate,
596
- 'customizeHardwareForTemplate',
597
- value
598
- )
599
- }
600
-
601
- resolve({
602
- stepHasError,
603
- newValue: value,
604
- })
605
- storageSubmit.value = null
606
- }
607
- })
608
- }
609
-
610
- const storageIdCash = ref<string | null>(null)
611
- const vmForm = ref<UI_I_VmForm>({
612
- name: '',
613
- compatibility: '',
614
- guestMachineType: null,
615
- guestOsFamily: null,
616
- guestOsVersion: null,
617
- computeResource: null,
618
- storage: null,
619
- locationPath: '',
620
- dataCenter: null,
621
- })
622
-
623
- // TODO remove (not used)
624
- const vmFormCash = ref<UI_I_VmFormCash>({
625
- dataCenterId: null,
626
- computeResourceTypeAndId: null,
627
- })
628
-
629
- const onChangeName = (name: string, node: UI_I_TreeNode | null): void => {
630
- vmForm.value.name = name
631
- if (isSphere.value) {
632
- vmForm.value.locationPath = node.id
633
- vmForm.value.dataCenter = $recursion.findParentByValue(
634
- node,
635
- 'datacenter',
636
- 'type',
637
- 'parent'
638
- )
639
- vmFormCash.value.dataCenterId = vmForm.value.dataCenter?.id || null
640
- }
641
- }
642
- // // Для сферы
643
- const computeResourcePath = ref<string>('')
644
- const onSelectComputeResourceTree = (node: UI_I_TreeNode): void => {
645
- emits('select-compute-resource-tree', node)
646
- computeResourcePath.value = node.id
647
- }
648
- const onChangeComputeResource = (node: UI_I_TreeNode): void => {
649
- vmForm.value.computeResource = node
650
- // const type = node.type.toUpperCase()
651
- // schedRequirementsTemplate.value = `sched_requirements="(${type}_ID=${node.id})"\\`
652
- vmFormCash.value.computeResourceTypeAndId = `${node.type}${node.id}` || null
653
- }
654
- const onChangeStorage = (storage: UI_I_DatastoreTableItem | null): void => {
655
- if (!storage) return
656
-
657
- vmForm.value.storage = storage
658
- storageIdCash.value = storage.id
659
- }
660
- const compatibilityInfo = ref<string>('')
661
- const onChangeCompatibility = (compatibility: UI_I_OptionItem): void => {
662
- vmForm.value.compatibility = compatibility.value
663
-
664
- const version = compatibility.value.split('-')[1]
665
- compatibilityInfo.value = `${localization.value.common.compatibility}: ${compatibility.text} (${localization.value.common.vmVersion} ${version})`
666
- }
667
- const customizeHardware = ref<UI_I_SendDataCustomizeHardware | null>(null)
668
- const onChangeCustomizeHardware = (
669
- data: UI_I_SendDataCustomizeHardware
670
- ): void => {
671
- customizeHardware.value = data
672
- }
673
-
674
- const virtualHardwareHardDisksLocal = computed<
675
- UI_I_SendDataNewHardDisk[] | null
676
- >(() => customizeHardware.value?.virtualHardware?.hardDisks || null)
677
- const virtualHardwareNetworksLocal = computed<UI_I_SendDataNewNetwork[] | null>(
678
- () => customizeHardware.value?.virtualHardware?.networks || null
679
- )
680
- const virtualHardwareCdDvdDrivesLocal = computed<
681
- UI_I_SendDataNewCdDvdDrive[] | null
682
- >(() => customizeHardware.value?.virtualHardware?.cdDvdDrives || null)
683
-
684
- const virtualHardwareCpu = computed<UI_I_SendDataCpu | null>(
685
- () => customizeHardware.value?.virtualHardware?.cpu || null
686
- )
687
- const virtualHardwareMemory = computed<UI_I_SendDataMemory | null>(
688
- () => customizeHardware.value?.virtualHardware?.memory || null
689
- )
690
- const virtualHardwareHardDisks = ref<UI_I_SendDataNewHardDisk[] | null>(null)
691
- const virtualHardwareCdDvdDrives = ref<UI_I_SendDataNewCdDvdDrive[] | null>(
692
- null
693
- )
694
- const virtualHardwareNetworks = ref<UI_I_SendDataNewNetwork[] | null>(null)
695
- const onChangeBootOrder = (data: UI_T_ChangeBootOrder): void => {
696
- virtualHardwareHardDisks.value = data[0]
697
- virtualHardwareCdDvdDrives.value = data[1]
698
- virtualHardwareNetworks.value = data[2]
699
- }
700
-
701
- const isPowerOnByDefault = ref<boolean>(true)
702
-
703
- watch(
704
- () => props.vmNameInWizard,
705
- (newValue) => {
706
- vmForm.value.name = newValue
707
- }
708
- )
709
-
710
- const validateSendData = async (
711
- value: UI_I_WizardStep[]
712
- ): Promise<UI_I_ValidationReturn> => {
713
- wizard.setLoader(true)
714
- let stepHasError = false
715
- isLoading.value = true
716
-
717
- const data = await props.validateSendDataFunc(
718
- vmForm.value,
719
- virtualHardwareCpu.value,
720
- virtualHardwareMemory.value,
721
- customizeHardware.value,
722
- virtualHardwareNetworks.value,
723
- virtualHardwareHardDisks.value,
724
- virtualHardwareCdDvdDrives.value,
725
- isPowerOnByDefault.value,
726
- localization.value,
727
- vmForm.value.locationPath, // для сферы
728
- computeResourcePath.value // для сферы
729
- )
730
-
731
- isLoading.value = false
732
- wizard.setLoader(false)
733
- if (data) {
734
- stepHasError = true
735
- selectedNavItem.value = data[0]
736
- data[1] !== null && wizard.selectStepHard(data[1])
737
- }
738
-
739
- return {
740
- stepHasError,
741
- newValue: value,
742
- }
743
- }
744
-
745
- const isLoading = ref<boolean>(false)
746
- const onFinish = (): void => {
747
- isLoading.value = true
748
- wizard.setLoader(false)
749
- props
750
- .finishFunc(
751
- vmForm.value,
752
- virtualHardwareCpu.value,
753
- virtualHardwareMemory.value,
754
- customizeHardware.value,
755
- virtualHardwareNetworks.value,
756
- virtualHardwareHardDisks.value,
757
- virtualHardwareCdDvdDrives.value,
758
- isPowerOnByDefault.value,
759
- localization.value,
760
- vmForm.value.locationPath, // для сферы
761
- computeResourcePath.value, // для сферы
762
- false,
763
- selectedTemplate.value,
764
- selectedCreateType.value
765
- )
766
- .then(() => {
767
- onHideModal()
768
- wizard.setLoader(false)
769
- isLoading.value = false
770
- })
771
- }
772
-
773
- const selectedNavItem = ref<UI_T_SelectedNavItem>(0)
774
-
775
- const nameFormSubmit = ref<null | Function>(null)
776
- const templateSubmit = ref<null | Function>(null)
777
- const computeResourceSubmit = ref<null | Function>(null)
778
- const storageSubmit = ref<null | Function>(null)
779
- const customizeHardwareSubmit = ref<null | Function>(null)
780
- const customizeHardwareForTemplateSubmit = ref<null | Function>(null)
781
- const compatibility = ref<UI_I_OptionItem[]>(capabilities.value.compatibility)
782
- const guestOsFamilies = ref<UI_I_OptionItem[]>(
783
- capabilities.value.guestOsFamilies
784
- )
785
- const guestOsVersions = ref<UI_I_ArbitraryObject<UI_I_OptionItem[]>>(
786
- capabilities.value.guestOsVersions
787
- )
788
- const machineTypes = ref<UI_I_OptionItem[]>(capabilities.value.machineTypes)
789
- const cpuModels = ref<UI_I_OptionItem[]>(capabilities.value.cpuModels)
790
- const maxCpus = ref<number>(capabilities.value.maxCpus)
791
- const maxMemory = ref<number>(capabilities.value.maxMemory)
792
-
793
- const selectedTemplate = ref<string>('')
794
- const onChangeTemplate = (node: UI_I_TreeNode): void => {
795
- selectedTemplate.value = node.id.toString()
796
- emits('select-template', node.id.toString())
797
- }
798
- const selectedOptions = ref<string[]>([])
799
- const onChangeSelectOptions = (options: string[]) => {
800
- selectedOptions.value = options
801
- if (
802
- options.includes('customize-os') &&
803
- options.includes('customize-hardware')
804
- ) {
805
- wizard.changeScheme(isSphere.value ? 9 : 5)
806
- } else if (options.includes('customize-os')) {
807
- wizard.changeScheme(isSphere.value ? 7 : 3)
808
- } else if (options.includes('customize-hardware')) {
809
- wizard.changeScheme(isSphere.value ? 8 : 4)
810
- } else {
811
- wizard.changeScheme(isSphere.value ? 6 : 2)
812
- }
813
-
814
- isPowerOnByDefault.value = options.includes('power-on')
815
- }
816
-
817
- const onHideModal = (): void => {
818
- emits('hide')
819
- }
820
-
821
- watch(
822
- () => props.vmtSettings,
823
- (newValue) => {
824
- if (newValue) {
825
- vmForm.value.name = newValue.name
826
- vmForm.value.compatibility =
827
- newValue.compatibility || vmForm.value.compatibility
828
- vmForm.value.storage = newValue.storage
829
- if (customizeHardware.value?.virtualHardware) {
830
- customizeHardware.value.virtualHardware.cdDvdDrives =
831
- newValue.cdDvdDrives
832
- customizeHardware.value.virtualHardware.hardDisks = newValue.hardDisks
833
- customizeHardware.value.virtualHardware.networks = newValue.networks
834
- customizeHardware.value.virtualHardware.cpu = newValue.cpu
835
- customizeHardware.value.virtualHardware.memory = newValue.memory
836
- customizeHardware.value.virtualHardware.videoCard = newValue.videoCard
837
- customizeHardware.value.virtualHardware.usbController =
838
- newValue.usbController
839
- customizeHardware.value.virtualHardware.pciDevices = newValue.pciDevices
840
- customizeHardware.value.vmOptions = newValue.options
841
- }
842
- maxCpus.value = newValue.cpu.max_vcpus
843
- cpuModels.value = newValue.cpu.model
844
- isPowerOnByDefault.value = false
845
- }
846
- }
847
- )
848
- </script>
849
-
850
- <style scoped lang="scss"></style>
1
+ <template>
2
+ <common-vm-actions-add-new
3
+ v-if="isNewView"
4
+ v-model:vm-form="vmForm"
5
+ v-model:selected-create-type="selectedCreateType"
6
+ v-model:is-power-on-by-default="isPowerOnByDefault"
7
+ :project="props.project"
8
+ :is-vmt="props.isVmt"
9
+ :nodes="props.nodes"
10
+ :files="props.files"
11
+ :networks-table="props.networksTable"
12
+ :datastore="props.datastore"
13
+ :is-datastore-loading="props.isDatastoreLoading"
14
+ :error-validation-fields="props.errorValidationFields"
15
+ :ready-complete-table-info="props.readyCompleteTableInfo"
16
+ :vm-cpu-help-text-second="props.vmCpuHelpTextSecond"
17
+ :import-from-v-m-warev-sphere="props.importFromVMWarevSphere"
18
+ :get-datastore-table-func="props.getDatastoreTableFunc"
19
+ :passthrough-devices="props.passthroughDevices"
20
+ :mediated-devices="props.mediatedDevices"
21
+ :templates-tree="props.templatesTree"
22
+ :wizard="wizard"
23
+ :selected-scheme="selectedScheme"
24
+ :template-submit="templateSubmit"
25
+ :name-form-submit="nameFormSubmit"
26
+ :storage-submit="storageSubmit"
27
+ :customize-hardware-submit="customizeHardwareSubmit"
28
+ :customize-hardware-for-template-submit="customizeHardwareForTemplateSubmit"
29
+ :is-sphere="isSphere"
30
+ :compatibility="compatibility"
31
+ :guestOsFamilies="guestOsFamilies"
32
+ :guestOsVersions="guestOsVersions"
33
+ :machineTypes="machineTypes"
34
+ :virtual-hardware-hard-disks-local="virtualHardwareHardDisksLocal"
35
+ :virtual-hardware-cd-dvd-drives-local="virtualHardwareCdDvdDrivesLocal"
36
+ :virtual-hardware-networks-local="virtualHardwareNetworksLocal"
37
+ :max-cpus="maxCpus"
38
+ :max-memory="maxMemory"
39
+ :cpu-models="cpuModels"
40
+ :selected-nav-item="selectedNavItem"
41
+ :compatibility-info="compatibilityInfo"
42
+ :is-show-power-on="isShowPowerOn"
43
+ :is-show-select-template="isShowSelectTemplate"
44
+ :compute-resource-submit="computeResourceSubmit"
45
+ :data-center="props.dataCenter"
46
+ :compute-resource="props.computeResource"
47
+ :compute-resource-tree="props.computeResourceTree"
48
+ :vmt-settings="props.vmtSettings"
49
+ :is-loading="isLoading"
50
+ :selected-template-id="props.selectedTemplateId"
51
+ :validate-empty-name="props.validateEmptyName"
52
+ :title="title"
53
+ @check-name="emits('check-name', $event)"
54
+ @get-storage="emits('get-storage', $event)"
55
+ @get-folders-or-files="emits('get-folders-or-files', $event)"
56
+ @get-active-device-child="emits('get-active-device-child', $event)"
57
+ @show-datastore-child="emits('show-datastore-child', $event)"
58
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
59
+ @get-networks-table="emits('get-networks-table', $event)"
60
+ @get-pci-devices="emits('get-pci-devices')"
61
+ @change-steps="onChangeSteps"
62
+ @change-template="onChangeTemplate"
63
+ @change-name="onChangeName(...$event)"
64
+ @change-storage="onChangeStorage"
65
+ @change-select-options="onChangeSelectOptions"
66
+ @change-compatibility="onChangeCompatibility"
67
+ @change-boot-order="onChangeBootOrder"
68
+ @change-customize-hardware="onChangeCustomizeHardware"
69
+ @clear-compute-resource-tree="emits('clear-compute-resource-tree')"
70
+ @change-compute-resource="onChangeComputeResource"
71
+ @select-compute-resource-tree="onSelectComputeResourceTree"
72
+ @get-compute-resource-tree="emits('get-compute-resource-tree', $event)"
73
+ @show-compute-resource-tree="emits('show-compute-resource-tree', $event)"
74
+ @finish="onFinish"
75
+ @hide="onHideModal"
76
+ />
77
+ <common-vm-actions-add-old
78
+ v-else
79
+ v-model:vm-form="vmForm"
80
+ v-model:selected-create-type="selectedCreateType"
81
+ v-model:is-power-on-by-default="isPowerOnByDefault"
82
+ :project="props.project"
83
+ :is-vmt="props.isVmt"
84
+ :nodes="props.nodes"
85
+ :files="props.files"
86
+ :networks-table="props.networksTable"
87
+ :datastore="props.datastore"
88
+ :is-datastore-loading="props.isDatastoreLoading"
89
+ :error-validation-fields="props.errorValidationFields"
90
+ :ready-complete-table-info="props.readyCompleteTableInfo"
91
+ :vm-cpu-help-text-second="props.vmCpuHelpTextSecond"
92
+ :import-from-v-m-warev-sphere="props.importFromVMWarevSphere"
93
+ :get-datastore-table-func="props.getDatastoreTableFunc"
94
+ :passthrough-devices="props.passthroughDevices"
95
+ :mediated-devices="props.mediatedDevices"
96
+ :templates-tree="props.templatesTree"
97
+ :wizard="wizard"
98
+ :selected-scheme="selectedScheme"
99
+ :template-submit="templateSubmit"
100
+ :name-form-submit="nameFormSubmit"
101
+ :storage-submit="storageSubmit"
102
+ :customize-hardware-submit="customizeHardwareSubmit"
103
+ :customize-hardware-for-template-submit="customizeHardwareForTemplateSubmit"
104
+ :is-sphere="isSphere"
105
+ :compatibility="compatibility"
106
+ :guestOsFamilies="guestOsFamilies"
107
+ :guestOsVersions="guestOsVersions"
108
+ :machineTypes="machineTypes"
109
+ :virtual-hardware-hard-disks-local="virtualHardwareHardDisksLocal"
110
+ :virtual-hardware-cd-dvd-drives-local="virtualHardwareCdDvdDrivesLocal"
111
+ :virtual-hardware-networks-local="virtualHardwareNetworksLocal"
112
+ :max-cpus="maxCpus"
113
+ :max-memory="maxMemory"
114
+ :cpu-models="cpuModels"
115
+ :selected-nav-item="selectedNavItem"
116
+ :compatibility-info="compatibilityInfo"
117
+ :is-show-power-on="isShowPowerOn"
118
+ :compute-resource-submit="computeResourceSubmit"
119
+ :data-center="props.dataCenter"
120
+ :compute-resource="props.computeResource"
121
+ :compute-resource-tree="props.computeResourceTree"
122
+ :vmt-settings="props.vmtSettings"
123
+ :is-loading="isLoading"
124
+ :validate-empty-name="props.validateEmptyName"
125
+ :title="title"
126
+ @check-name="emits('check-name', $event)"
127
+ @get-storage="emits('get-storage', $event)"
128
+ @get-folders-or-files="emits('get-folders-or-files', $event)"
129
+ @get-active-device-child="emits('get-active-device-child', $event)"
130
+ @show-datastore-child="emits('show-datastore-child', $event)"
131
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
132
+ @get-networks-table="emits('get-networks-table', $event)"
133
+ @get-pci-devices="emits('get-pci-devices')"
134
+ @change-steps="onChangeSteps"
135
+ @change-template="onChangeTemplate"
136
+ @change-name="onChangeName(...$event)"
137
+ @change-storage="onChangeStorage"
138
+ @change-select-options="onChangeSelectOptions"
139
+ @change-compatibility="onChangeCompatibility"
140
+ @change-boot-order="onChangeBootOrder"
141
+ @change-customize-hardware="onChangeCustomizeHardware"
142
+ @clear-compute-resource-tree="emits('clear-compute-resource-tree')"
143
+ @change-compute-resource="onChangeComputeResource"
144
+ @select-compute-resource-tree="onSelectComputeResourceTree"
145
+ @get-compute-resource-tree="emits('get-compute-resource-tree', $event)"
146
+ @show-compute-resource-tree="emits('show-compute-resource-tree', $event)"
147
+ @finish="onFinish"
148
+ @hide="onHideModal"
149
+ />
150
+ </template>
151
+
152
+ <script setup lang="ts">
153
+ import type {
154
+ UI_I_ValidationReturn,
155
+ UI_I_WizardStep,
156
+ } from '~/node_modules/bfg-uikit/components/ui/wizard/lib/models/interfaces'
157
+ import Wizard from '~/node_modules/bfg-uikit/components/ui/wizard/lib/utils/utils'
158
+ import type {
159
+ UI_I_Localization,
160
+ UI_I_ArbitraryObject,
161
+ } from '~/lib/models/interfaces'
162
+ import type { UI_T_Project } from '~/lib/models/types'
163
+ import type { UI_I_FileTreeNode } from '~/components/lib/models/interfaces'
164
+ import type { UI_I_NetworkTableItem } from '~/lib/models/store/network/interfaces'
165
+ import type {
166
+ UI_I_DatastoreTableItem,
167
+ UI_I_FolderOrFileTreePayload,
168
+ } from '~/lib/models/store/storage/interfaces'
169
+ import type {
170
+ // API_UI_I_Error,
171
+ UI_I_ErrorValidationField,
172
+ } from '~/lib/models/store/interfaces'
173
+ import type { UI_I_TablePayload } from '~/lib/models/table/interfaces'
174
+ import type { UI_I_TableInfoItem } from '~/components/atoms/table/info/lib/models/interfaces'
175
+ import type {
176
+ UI_T_AddVmFinishFunc,
177
+ UI_T_SelectedNavItem,
178
+ } from '~/components/common/vm/actions/common/lib/models/types'
179
+ import type { UI_I_TreeNode } from '~/components/common/recursionTree/lib/models/interfaces'
180
+ import type {
181
+ UI_I_Capabilities,
182
+ UI_I_VmForm,
183
+ UI_I_VmFormCash,
184
+ } from '~/components/common/vm/actions/common/lib/models/interfaces'
185
+ import type { UI_I_SendDataCustomizeHardware } from '~/components/common/vm/actions/common/customizeHardware/lib/models/interfaces'
186
+ import type {
187
+ UI_I_SendDataCpu,
188
+ UI_I_SendDataMemory,
189
+ UI_I_SendDataNewCdDvdDrive,
190
+ UI_I_SendDataNewHardDisk,
191
+ UI_I_SendDataNewNetwork,
192
+ } from '~/components/common/vm/actions/common/customizeHardware/virtualHardware/lib/models/interfaces'
193
+ import type { UI_I_OptionItem } from '~/components/atoms/lib/models/interfaces'
194
+ import type { UI_T_ChangeBootOrder } from '~/components/common/vm/actions/lib/models/types'
195
+ import type {
196
+ UI_I_MediatedDevice,
197
+ UI_I_PciDevice,
198
+ UI_I_VmSettings,
199
+ } from '~/lib/models/store/vm/interfaces'
200
+ import { capabilities } from '~/components/common/vm/actions/common/lib/config/capabilities'
201
+ import {
202
+ stepsSchemeInitial,
203
+ stepsFunc,
204
+ dynamicSteps,
205
+ } from '~/components/common/vm/actions/add/lib/config/steps'
206
+ import { mapCapabilities } from '~/components/common/vm/actions/common/lib/utils/capabilities'
207
+
208
+ const props = withDefaults(
209
+ defineProps<{
210
+ project: UI_T_Project
211
+ nodes: UI_I_FileTreeNode[]
212
+ files: UI_I_FileTreeNode[]
213
+ networksTable: UI_I_NetworkTableItem[]
214
+ datastore: UI_I_DatastoreTableItem[]
215
+ isDatastoreLoading: boolean
216
+ errorValidationFields: UI_I_ErrorValidationField[]
217
+ readyCompleteTableInfo: UI_I_TableInfoItem[]
218
+ vmCpuHelpTextSecond: string
219
+ importFromVMWarevSphere: string
220
+ finishFunc: UI_T_AddVmFinishFunc
221
+ getDatastoreTableFunc: (payload: UI_I_TablePayload) => Promise<void>
222
+ validateSendDataFunc: UI_T_AddVmFinishFunc<
223
+ [UI_T_SelectedNavItem, null | number] | null
224
+ >
225
+ passthroughDevices: UI_I_PciDevice[]
226
+ mediatedDevices: UI_I_MediatedDevice[]
227
+ vmNameInWizard: string
228
+ templatesTree?: UI_I_TreeNode[]
229
+ capabilities?: UI_I_Capabilities
230
+ vmtSettings?: UI_I_VmSettings | null
231
+ validateEmptyName?: boolean
232
+ dataCenter?: UI_I_TreeNode // для сферы
233
+ computeResource?: UI_I_TreeNode // для сферы
234
+ computeResourceTree?: UI_I_TreeNode[] // для сферы
235
+ selectedTemplateId?: string // для сферы
236
+ isVmt?: boolean // для сферы
237
+ }>(),
238
+ {
239
+ templatesTree: [],
240
+ capabilities: undefined,
241
+ vmtSettings: undefined,
242
+ validateEmptyName: false,
243
+ dataCenter: undefined,
244
+ computeResource: undefined,
245
+ computeResourceTree: undefined,
246
+ selectedTemplateId: '',
247
+ isVmt: false,
248
+ }
249
+ )
250
+
251
+ const emits = defineEmits<{
252
+ (
253
+ event: 'check-name',
254
+ value: [[string, UI_I_TreeNode | null], (error: any) => void]
255
+ ): void
256
+ (event: 'get-storage', value: UI_I_TablePayload): void
257
+ (event: 'get-folders-or-files', value: UI_I_FolderOrFileTreePayload): void
258
+ (event: 'get-active-device-child', value: UI_I_FileTreeNode): void
259
+ (event: 'show-datastore-child', value: UI_I_FileTreeNode): void
260
+ (event: 'remove-error-by-title', value: string): void
261
+ (event: 'get-networks-table', value: UI_I_TablePayload): void
262
+ (event: 'get-pci-devices'): void
263
+ (event: 'get-pci-devices'): void
264
+ (event: 'hide'): void
265
+ (event: 'select-template', value: string): void
266
+ (
267
+ event: 'get-compute-resource-tree',
268
+ value: { id: string | number; cb: () => void }
269
+ ): void // для сферы
270
+ (event: 'show-compute-resource-tree', value: UI_I_TreeNode): void // для сферы
271
+ (event: 'select-compute-resource-tree', value: UI_I_TreeNode): void // для сферы
272
+ (event: 'clear-compute-resource-tree'): void // для сферы
273
+ }>()
274
+
275
+ const { $store, $recursion }: any = useNuxtApp()
276
+ const isNewView = computed<boolean>(() => $store.getters['main/getIsNewView'])
277
+
278
+ const localization = computed<UI_I_Localization>(() => useLocal())
279
+
280
+ const isSphere = computed<boolean>(() => props.project === 'sphere')
281
+
282
+ const title = computed<string>(() =>
283
+ props.isVmt
284
+ ? localization.value.vmt.newTemplate
285
+ : localization.value.common.newVirtualMachine2
286
+ )
287
+
288
+ watch(
289
+ () => props.capabilities,
290
+ () => {
291
+ if (props.capabilities) mapCapabilities(props.capabilities)
292
+ },
293
+ { deep: true, immediate: true }
294
+ )
295
+
296
+ const selectedCreateType = ref<string>('0')
297
+ if (props.isVmt) selectedCreateType.value = '-1'
298
+
299
+ const wizard: Wizard = new Wizard(
300
+ stepsFunc(localization.value, props.isVmt),
301
+ stepsSchemeInitial
302
+ )
303
+ watch(
304
+ selectedCreateType,
305
+ (newValue) => {
306
+ switch (newValue) {
307
+ case '0':
308
+ wizard.changeScheme(isSphere.value ? 1 : 0)
309
+ break
310
+ case '1':
311
+ wizard.changeScheme(isSphere.value ? 6 : 2)
312
+ break
313
+ case '-1':
314
+ wizard.changeScheme(10)
315
+ break
316
+ }
317
+ },
318
+ { immediate: true }
319
+ )
320
+
321
+ // if (isSphere.value) wizard.changeScheme(1)
322
+ const selectedScheme = computed<number[]>(() => wizard.selectedScheme.value)
323
+ // const alertMessages = computed<string[][]>(() => wizard.alertMessages.value)
324
+
325
+ const isShowSelectTemplate = computed<boolean>(
326
+ () =>
327
+ wizard.selectedStepId === dynamicSteps.selectTemplate &&
328
+ selectedCreateType.value === '1'
329
+ )
330
+
331
+ const isShowPowerOn = computed<boolean>(
332
+ () =>
333
+ wizard.selectedStepId > dynamicSteps.customizeHardware &&
334
+ selectedCreateType.value !== '1' &&
335
+ !props.isVmt
336
+ )
337
+
338
+ const onChangeSteps = async (value: UI_I_WizardStep[]): Promise<void> => {
339
+ wizard.changeSteps(value, validationFunc, validateSendData)
340
+ }
341
+ const validationFunc = async (
342
+ value: UI_I_WizardStep[],
343
+ currentStep: UI_I_WizardStep,
344
+ nextStep: UI_I_WizardStep
345
+ ): Promise<UI_I_ValidationReturn> => {
346
+ let stepHasError = false
347
+ let stepShouldStop = {
348
+ ifOnCurrentStep: false,
349
+ ifFromAnyStep: false,
350
+ stoppageStepId: -1,
351
+ }
352
+
353
+ wizard.setLoader(true)
354
+ if (
355
+ wizard.isValidateForStep(
356
+ dynamicSteps.selectTemplate,
357
+ currentStep.id,
358
+ nextStep.id
359
+ )
360
+ ) {
361
+ const templateValidation = await checkTemplate(value)
362
+
363
+ value = templateValidation.newValue
364
+ stepHasError = stepHasError || templateValidation.stepHasError
365
+ } else if (
366
+ wizard.isValidateForStep(
367
+ isSphere.value ? dynamicSteps.selectNameFolder : dynamicSteps.selectName,
368
+ currentStep.id,
369
+ nextStep.id
370
+ )
371
+ ) {
372
+ const nameValidation = await onCheckName(value)
373
+
374
+ value = nameValidation.newValue
375
+ stepHasError = stepHasError || nameValidation.stepHasError
376
+ } else if (
377
+ isSphere.value &&
378
+ wizard.isValidateForStep(
379
+ dynamicSteps.selectComputeResource,
380
+ currentStep.id,
381
+ nextStep.id
382
+ )
383
+ ) {
384
+ const computeResourceValidation = await checkComputeResource(value)
385
+
386
+ value = computeResourceValidation.newValue
387
+ stepHasError = stepHasError || computeResourceValidation.stepHasError
388
+ } else if (
389
+ wizard.isValidateForStep(
390
+ dynamicSteps.selectStorage,
391
+ currentStep.id,
392
+ nextStep.id
393
+ )
394
+ ) {
395
+ const storageValidation = await checkStorage(value)
396
+
397
+ value = storageValidation.newValue
398
+
399
+ stepHasError = stepHasError || storageValidation.stepHasError
400
+ } else if (
401
+ wizard.isValidateForStep(
402
+ dynamicSteps.customizeHardware,
403
+ currentStep.id,
404
+ nextStep.id
405
+ )
406
+ ) {
407
+ const validation = await checkCustomizeHardware(value)
408
+
409
+ value = validation.newValue
410
+
411
+ stepHasError = stepHasError || validation.stepHasError
412
+ } else if (
413
+ wizard.isValidateForStep(
414
+ dynamicSteps.customizeHardwareTemplate,
415
+ currentStep.id,
416
+ nextStep.id
417
+ )
418
+ ) {
419
+ const validation = await checkCustomizeHardwareForTemplate(value)
420
+
421
+ value = validation.newValue
422
+
423
+ stepHasError = stepHasError || validation.stepHasError
424
+ }
425
+ wizard.setLoader(false)
426
+
427
+ return {
428
+ newValue: value,
429
+ stepHasError,
430
+ stepShouldStop,
431
+ }
432
+ }
433
+
434
+ const checkTemplate = async (
435
+ value: UI_I_WizardStep[]
436
+ ): Promise<UI_I_ValidationReturn> => {
437
+ let stepHasError = false
438
+
439
+ return new Promise((resolve) => {
440
+ templateSubmit.value = (isValid: boolean) => {
441
+ if (!isValid) {
442
+ stepHasError = wizard.setValidation(
443
+ dynamicSteps.selectTemplate,
444
+ 'template',
445
+ {
446
+ fieldMessage: 'aaa',
447
+ alertMessage: 'aaa',
448
+ }
449
+ )
450
+ } else if (wizard.hasMessage(dynamicSteps.selectTemplate, 'template')) {
451
+ value = wizard.removeValidation(
452
+ dynamicSteps.selectTemplate,
453
+ 'template',
454
+ value
455
+ )
456
+ }
457
+
458
+ resolve({
459
+ stepHasError,
460
+ newValue: value,
461
+ })
462
+ templateSubmit.value = null
463
+ }
464
+ })
465
+ }
466
+ const onCheckName = async (
467
+ value: UI_I_WizardStep[]
468
+ ): Promise<UI_I_ValidationReturn> => {
469
+ let stepHasError = false
470
+
471
+ return new Promise((resolve) => {
472
+ const step = isSphere.value
473
+ ? dynamicSteps.selectNameFolder
474
+ : dynamicSteps.selectName
475
+ nameFormSubmit.value = (isValid: boolean) => {
476
+ if (!isValid) {
477
+ stepHasError = wizard.setValidation(step, 'name', {
478
+ fieldMessage: 'aaa',
479
+ alertMessage: 'aaa',
480
+ })
481
+ } else if (wizard.hasMessage(step, 'name')) {
482
+ value = wizard.removeValidation(step, 'name', value)
483
+ }
484
+
485
+ resolve({
486
+ stepHasError,
487
+ newValue: value,
488
+ })
489
+ nameFormSubmit.value = null
490
+ }
491
+ })
492
+ }
493
+ const checkComputeResource = async (
494
+ value: UI_I_WizardStep[]
495
+ ): Promise<UI_I_ValidationReturn> => {
496
+ let stepHasError = false
497
+
498
+ return new Promise((resolve) => {
499
+ computeResourceSubmit.value = (isValid: boolean) => {
500
+ if (!isValid) {
501
+ stepHasError = wizard.setValidation(
502
+ dynamicSteps.selectComputeResource,
503
+ 'computeResource',
504
+ {
505
+ fieldMessage: 'aaa',
506
+ alertMessage: 'aaa',
507
+ }
508
+ )
509
+ } else if (
510
+ wizard.hasMessage(dynamicSteps.selectComputeResource, 'computeResource')
511
+ ) {
512
+ value = wizard.removeValidation(
513
+ dynamicSteps.selectComputeResource,
514
+ 'computeResource',
515
+ value
516
+ )
517
+ }
518
+
519
+ resolve({
520
+ stepHasError,
521
+ newValue: value,
522
+ })
523
+ computeResourceSubmit.value = null
524
+ }
525
+ })
526
+ }
527
+ const checkStorage = async (
528
+ value: UI_I_WizardStep[]
529
+ ): Promise<UI_I_ValidationReturn> => {
530
+ let stepHasError = false
531
+
532
+ return new Promise((resolve) => {
533
+ storageSubmit.value = (isValid: boolean) => {
534
+ if (!isValid) {
535
+ stepHasError = wizard.setValidation(
536
+ dynamicSteps.selectStorage,
537
+ 'storage',
538
+ {
539
+ fieldMessage: 'aaa',
540
+ alertMessage: 'aaa',
541
+ }
542
+ )
543
+ } else if (wizard.hasMessage(dynamicSteps.selectStorage, 'storage')) {
544
+ value = wizard.removeValidation(
545
+ dynamicSteps.selectStorage,
546
+ 'storage',
547
+ value
548
+ )
549
+ }
550
+
551
+ resolve({
552
+ stepHasError,
553
+ newValue: value,
554
+ })
555
+ storageSubmit.value = null
556
+ }
557
+ })
558
+ }
559
+ const checkCustomizeHardware = async (
560
+ value: UI_I_WizardStep[]
561
+ ): Promise<UI_I_ValidationReturn> => {
562
+ let stepHasError = false
563
+ isLoading.value = true
564
+
565
+ return new Promise((resolve) => {
566
+ customizeHardwareSubmit.value = (isValid: boolean) => {
567
+ if (!isValid) {
568
+ stepHasError = wizard.setValidation(
569
+ dynamicSteps.customizeHardware,
570
+ 'customizeHardware',
571
+ {
572
+ fieldMessage: 'aaa',
573
+ alertMessage: 'aaa',
574
+ }
575
+ )
576
+ } else if (
577
+ wizard.hasMessage(dynamicSteps.customizeHardware, 'customizeHardware')
578
+ ) {
579
+ wizard.removeValidationLocal(
580
+ dynamicSteps.customizeHardware,
581
+ 'customizeHardware'
582
+ )
583
+ value = wizard.removeValidation(
584
+ dynamicSteps.customizeHardware,
585
+ 'customizeHardware',
586
+ value
587
+ )
588
+ }
589
+
590
+ resolve({
591
+ stepHasError,
592
+ newValue: value,
593
+ })
594
+ storageSubmit.value = null
595
+ isLoading.value = false
596
+ }
597
+ })
598
+ }
599
+ const checkCustomizeHardwareForTemplate = async (
600
+ value: UI_I_WizardStep[]
601
+ ): Promise<UI_I_ValidationReturn> => {
602
+ let stepHasError = false
603
+
604
+ return new Promise((resolve) => {
605
+ customizeHardwareForTemplateSubmit.value = (isValid: boolean) => {
606
+ if (!isValid) {
607
+ stepHasError = wizard.setValidation(
608
+ dynamicSteps.customizeHardwareTemplate,
609
+ 'customizeHardwareForTemplate',
610
+ {
611
+ fieldMessage: 'aaa',
612
+ alertMessage: 'aaa',
613
+ }
614
+ )
615
+ } else if (
616
+ wizard.hasMessage(
617
+ dynamicSteps.customizeHardwareTemplate,
618
+ 'customizeHardwareForTemplate'
619
+ )
620
+ ) {
621
+ value = wizard.removeValidation(
622
+ dynamicSteps.customizeHardwareTemplate,
623
+ 'customizeHardwareForTemplate',
624
+ value
625
+ )
626
+ }
627
+
628
+ resolve({
629
+ stepHasError,
630
+ newValue: value,
631
+ })
632
+ storageSubmit.value = null
633
+ }
634
+ })
635
+ }
636
+
637
+ const storageIdCash = ref<string | null>(null)
638
+ const vmForm = ref<UI_I_VmForm>({
639
+ name: '',
640
+ compatibility: '',
641
+ guestMachineType: null,
642
+ guestOsFamily: null,
643
+ guestOsVersion: null,
644
+ computeResource: null,
645
+ storage: null,
646
+ locationPath: '',
647
+ dataCenter: null,
648
+ })
649
+
650
+ // TODO remove (not used)
651
+ const vmFormCash = ref<UI_I_VmFormCash>({
652
+ dataCenterId: null,
653
+ computeResourceTypeAndId: null,
654
+ })
655
+
656
+ const onChangeName = (name: string, node: UI_I_TreeNode | null): void => {
657
+ vmForm.value.name = name
658
+ if (isSphere.value) {
659
+ vmForm.value.locationPath = node.id
660
+ vmForm.value.dataCenter = $recursion.findParentByValue(
661
+ node,
662
+ 'datacenter',
663
+ 'type',
664
+ 'parent'
665
+ )
666
+ vmFormCash.value.dataCenterId = vmForm.value.dataCenter?.id || null
667
+ }
668
+ }
669
+ // // Для сферы
670
+ const computeResourcePath = ref<string>('')
671
+ const onSelectComputeResourceTree = (node: UI_I_TreeNode): void => {
672
+ emits('select-compute-resource-tree', node)
673
+ computeResourcePath.value = node.id
674
+ }
675
+ const onChangeComputeResource = (node: UI_I_TreeNode): void => {
676
+ vmForm.value.computeResource = node
677
+ // const type = node.type.toUpperCase()
678
+ // schedRequirementsTemplate.value = `sched_requirements="(${type}_ID=${node.id})"\\`
679
+ vmFormCash.value.computeResourceTypeAndId = `${node.type}${node.id}` || null
680
+ }
681
+ const onChangeStorage = (storage: UI_I_DatastoreTableItem | null): void => {
682
+ if (!storage) return
683
+
684
+ vmForm.value.storage = storage
685
+ storageIdCash.value = storage.id
686
+ }
687
+ const compatibilityInfo = ref<string>('')
688
+ const onChangeCompatibility = (compatibility: UI_I_OptionItem): void => {
689
+ vmForm.value.compatibility = compatibility.value
690
+
691
+ const version = compatibility.value.split('-')[1]
692
+ compatibilityInfo.value = `${localization.value.common.compatibility}: ${compatibility.text} (${localization.value.common.vmVersion} ${version})`
693
+ }
694
+ const customizeHardware = ref<UI_I_SendDataCustomizeHardware | null>(null)
695
+ const onChangeCustomizeHardware = (
696
+ data: UI_I_SendDataCustomizeHardware
697
+ ): void => {
698
+ customizeHardware.value = data
699
+ }
700
+
701
+ const virtualHardwareHardDisksLocal = computed<
702
+ UI_I_SendDataNewHardDisk[] | null
703
+ >(() => customizeHardware.value?.virtualHardware?.hardDisks || null)
704
+ const virtualHardwareNetworksLocal = computed<UI_I_SendDataNewNetwork[] | null>(
705
+ () => customizeHardware.value?.virtualHardware?.networks || null
706
+ )
707
+ const virtualHardwareCdDvdDrivesLocal = computed<
708
+ UI_I_SendDataNewCdDvdDrive[] | null
709
+ >(() => customizeHardware.value?.virtualHardware?.cdDvdDrives || null)
710
+
711
+ const virtualHardwareCpu = computed<UI_I_SendDataCpu | null>(
712
+ () => customizeHardware.value?.virtualHardware?.cpu || null
713
+ )
714
+ const virtualHardwareMemory = computed<UI_I_SendDataMemory | null>(
715
+ () => customizeHardware.value?.virtualHardware?.memory || null
716
+ )
717
+ const virtualHardwareHardDisks = ref<UI_I_SendDataNewHardDisk[] | null>(null)
718
+ const virtualHardwareCdDvdDrives = ref<UI_I_SendDataNewCdDvdDrive[] | null>(
719
+ null
720
+ )
721
+ const virtualHardwareNetworks = ref<UI_I_SendDataNewNetwork[] | null>(null)
722
+ const onChangeBootOrder = (data: UI_T_ChangeBootOrder): void => {
723
+ virtualHardwareHardDisks.value = data[0]
724
+ virtualHardwareCdDvdDrives.value = data[1]
725
+ virtualHardwareNetworks.value = data[2]
726
+ }
727
+
728
+ const isPowerOnByDefault = ref<boolean>(true)
729
+
730
+ watch(
731
+ () => props.vmNameInWizard,
732
+ (newValue) => {
733
+ vmForm.value.name = newValue
734
+ }
735
+ )
736
+
737
+ const validateSendData = async (
738
+ value: UI_I_WizardStep[]
739
+ ): Promise<UI_I_ValidationReturn> => {
740
+ wizard.setLoader(true)
741
+ let stepHasError = false
742
+ isLoading.value = true
743
+
744
+ const data = await props.validateSendDataFunc(
745
+ vmForm.value,
746
+ virtualHardwareCpu.value,
747
+ virtualHardwareMemory.value,
748
+ customizeHardware.value,
749
+ virtualHardwareNetworks.value,
750
+ virtualHardwareHardDisks.value,
751
+ virtualHardwareCdDvdDrives.value,
752
+ isPowerOnByDefault.value,
753
+ localization.value,
754
+ vmForm.value.locationPath, // для сферы
755
+ computeResourcePath.value // для сферы
756
+ )
757
+
758
+ isLoading.value = false
759
+ wizard.setLoader(false)
760
+ if (data) {
761
+ stepHasError = true
762
+ selectedNavItem.value = data[0]
763
+ data[1] !== null && wizard.selectStepHard(data[1])
764
+ }
765
+
766
+ return {
767
+ stepHasError,
768
+ newValue: value,
769
+ }
770
+ }
771
+
772
+ const isLoading = ref<boolean>(false)
773
+ const onFinish = (): void => {
774
+ isLoading.value = true
775
+ wizard.setLoader(false)
776
+ props
777
+ .finishFunc(
778
+ vmForm.value,
779
+ virtualHardwareCpu.value,
780
+ virtualHardwareMemory.value,
781
+ customizeHardware.value,
782
+ virtualHardwareNetworks.value,
783
+ virtualHardwareHardDisks.value,
784
+ virtualHardwareCdDvdDrives.value,
785
+ isPowerOnByDefault.value,
786
+ localization.value,
787
+ vmForm.value.locationPath, // для сферы
788
+ computeResourcePath.value, // для сферы
789
+ false,
790
+ selectedTemplate.value,
791
+ selectedCreateType.value
792
+ )
793
+ .then(() => {
794
+ onHideModal()
795
+ wizard.setLoader(false)
796
+ isLoading.value = false
797
+ })
798
+ }
799
+
800
+ const selectedNavItem = ref<UI_T_SelectedNavItem>(0)
801
+
802
+ const nameFormSubmit = ref<null | Function>(null)
803
+ const templateSubmit = ref<null | Function>(null)
804
+ const computeResourceSubmit = ref<null | Function>(null)
805
+ const storageSubmit = ref<null | Function>(null)
806
+ const customizeHardwareSubmit = ref<null | Function>(null)
807
+ const customizeHardwareForTemplateSubmit = ref<null | Function>(null)
808
+ const compatibility = ref<UI_I_OptionItem[]>(capabilities.value.compatibility)
809
+ const guestOsFamilies = ref<UI_I_OptionItem[]>(
810
+ capabilities.value.guestOsFamilies
811
+ )
812
+ const guestOsVersions = ref<UI_I_ArbitraryObject<UI_I_OptionItem[]>>(
813
+ capabilities.value.guestOsVersions
814
+ )
815
+ const machineTypes = ref<UI_I_OptionItem[]>(capabilities.value.machineTypes)
816
+ const cpuModels = ref<UI_I_OptionItem[]>(capabilities.value.cpuModels)
817
+ const maxCpus = ref<number>(capabilities.value.maxCpus)
818
+ const maxMemory = ref<number>(capabilities.value.maxMemory)
819
+
820
+ const selectedTemplate = ref<string>('')
821
+ const onChangeTemplate = (node: UI_I_TreeNode): void => {
822
+ selectedTemplate.value = node.id.toString()
823
+ emits('select-template', node.id.toString())
824
+ }
825
+ const selectedOptions = ref<string[]>([])
826
+ const onChangeSelectOptions = (options: string[]) => {
827
+ selectedOptions.value = options
828
+ if (
829
+ options.includes('customize-os') &&
830
+ options.includes('customize-hardware')
831
+ ) {
832
+ wizard.changeScheme(isSphere.value ? 9 : 5)
833
+ } else if (options.includes('customize-os')) {
834
+ wizard.changeScheme(isSphere.value ? 7 : 3)
835
+ } else if (options.includes('customize-hardware')) {
836
+ wizard.changeScheme(isSphere.value ? 8 : 4)
837
+ } else {
838
+ wizard.changeScheme(isSphere.value ? 6 : 2)
839
+ }
840
+
841
+ isPowerOnByDefault.value = options.includes('power-on')
842
+ }
843
+
844
+ const onHideModal = (): void => {
845
+ emits('hide')
846
+ }
847
+
848
+ watch(
849
+ () => props.vmtSettings,
850
+ (newValue) => {
851
+ if (newValue) {
852
+ vmForm.value.name = newValue.name
853
+ vmForm.value.compatibility =
854
+ newValue.compatibility || vmForm.value.compatibility
855
+ vmForm.value.storage = newValue.storage
856
+ if (customizeHardware.value?.virtualHardware) {
857
+ customizeHardware.value.virtualHardware.cdDvdDrives =
858
+ newValue.cdDvdDrives
859
+ customizeHardware.value.virtualHardware.hardDisks = newValue.hardDisks
860
+ customizeHardware.value.virtualHardware.networks = newValue.networks
861
+ customizeHardware.value.virtualHardware.cpu = newValue.cpu
862
+ customizeHardware.value.virtualHardware.memory = newValue.memory
863
+ customizeHardware.value.virtualHardware.videoCard = newValue.videoCard
864
+ customizeHardware.value.virtualHardware.usbController =
865
+ newValue.usbController
866
+ customizeHardware.value.virtualHardware.pciDevices = newValue.pciDevices
867
+ customizeHardware.value.vmOptions = newValue.options
868
+ }
869
+ maxCpus.value = newValue.cpu.max_vcpus
870
+ cpuModels.value = newValue.cpu.model
871
+ isPowerOnByDefault.value = false
872
+ }
873
+ }
874
+ )
875
+ </script>
876
+
877
+ <style scoped lang="scss"></style>