bfg-common 1.5.318 → 1.5.319

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.
@@ -1,817 +1,822 @@
1
- <template>
2
- <div class="clone-vm">
3
- <atoms-wizard
4
- show
5
- :wizard="wizard"
6
- :selected-scheme="selectedScheme"
7
- :title="title"
8
- :localization="localization"
9
- @change-steps="onChangeSteps"
10
- @hide="onHideModal"
11
- @submit="onFinish"
12
- >
13
- <template #modalBody="{ selectedStep }">
14
- <atoms-loader v-show="!vmSettings || isLoading" id="loader" />
15
- <div v-if="vmSettings" class="vm-context">
16
- <common-pages-scheduled-tasks-modals-common-new-task-form
17
- v-show="selectedStep.id === dynamicSteps.scheduledTasks"
18
- v-model="newTaskForm"
19
- :target="selectedVirtualMachine"
20
- class="new-task-form"
21
- />
22
- <common-vm-actions-common-select-name
23
- v-show="
24
- selectedStep.id === dynamicSteps.selectName ||
25
- selectedStep.id === dynamicSteps.selectNameFolder
26
- "
27
- :show="
28
- selectedStep.id === dynamicSteps.selectName ||
29
- selectedStep.id === dynamicSteps.selectNameFolder
30
- "
31
- :name-form-submit="nameFormSubmit"
32
- :project="props.project"
33
- :data-center="props.dataCenter"
34
- @submit="onChangeName(...$event)"
35
- @check-name="emits('check-name', $event)"
36
- />
37
- <common-vm-actions-common-select-compute-resource
38
- v-if="isSphere"
39
- v-show="selectedStep.id === dynamicSteps.selectComputeResource"
40
- v-model="computeResource"
41
- :compute-resource-submit="computeResourceSubmit"
42
- :data-center="vmForm.dataCenter"
43
- :compute-resource="props.computeResource"
44
- :compute-resource-tree="props.computeResourceTree"
45
- @submit="onChangeComputeResource"
46
- @select-compute-resource-tree="onSelectComputeResourceTree"
47
- @get-compute-resource-tree="
48
- emits('get-compute-resource-tree', $event)
49
- "
50
- @show-compute-resource-tree="
51
- emits('show-compute-resource-tree', $event)
52
- "
53
- @clear-compute-resource-tree="emits('clear-compute-resource-tree')"
54
- />
55
- <common-vm-actions-common-select-storage
56
- v-show="selectedStep.id === dynamicSteps.selectStorage"
57
- :storage-submit="storageSubmit"
58
- :datastore="props.datastore"
59
- :is-datastore-loading="props.isDatastoreLoading"
60
- :storage="vmForm.storage"
61
- :get-datastore-table-func="props.getDatastoreTableFunc"
62
- @submit="onChangeStorage"
63
- />
64
- <common-vm-actions-common-select-options
65
- v-show="selectedStep.id === dynamicSteps.selectOptions"
66
- @change="onChangeSelectOptions"
67
- />
68
- <common-vm-actions-common-select-os
69
- v-show="selectedStep.id === dynamicSteps.selectGuestOSMachineType"
70
- v-model:machine-type="vmForm.guestMachineType"
71
- v-model:guest-os-family="vmForm.guestOsFamily"
72
- v-model:guest-os-version="vmForm.guestOsVersion"
73
- :families-options="guestOsFamilies"
74
- :versions-options="guestOsVersions"
75
- :machine-types-options="machineTypes"
76
- :error-validation-fields="props.errorValidationFields"
77
- @remove-error-by-title="emits('remove-error-by-title', $event)"
78
- />
79
- <common-vm-actions-common-customize-hardware
80
- v-show="selectedStep.id === dynamicSteps.customizeHardware"
81
- v-model:vm-name="vmName"
82
- v-model:guest-machine-type="vmSettings.guestMachineType"
83
- v-model:guest-os-family="vmSettings.guestOsFamily"
84
- v-model:guest-os-version="vmSettings.guestOsVersion"
85
- :storage="vmForm.storage"
86
- :hard-disks-for-boot-options="virtualHardwareHardDisksLocal"
87
- :cd-dvd-drives-for-boot-options="virtualHardwareCdDvdDrivesLocal"
88
- :networks-for-boot-options="virtualHardwareNetworksLocal"
89
- :cd-dvd-drives="vmSettings.cdDvdDrives"
90
- :hard-disks="vmSettings.hardDisks"
91
- :networks="vmSettings.networks"
92
- :customize-hardware-submit="customizeHardwareSubmit"
93
- :max-cpus="vmSettings.maxCpus"
94
- :max-memory="vmSettings.maxMemory"
95
- :cpu-models="vmSettings.cpuModels"
96
- :cpu="vmSettings.cpu"
97
- :memory="vmSettings.memory"
98
- :video-card="vmSettings.videoCard"
99
- :usb-controller="vmSettings.usbController"
100
- :pci-devices="vmSettings.pciDevices"
101
- :selected-nav-item="selectedNavItem"
102
- :hard-disks-for-edit="vmSettings.hardDisks"
103
- :options="vmSettings.options"
104
- :nodes="props.nodes"
105
- :files="props.files"
106
- :networks-table="props.networksTable"
107
- :error-validation-fields="props.errorValidationFields"
108
- :vm-cpu-help-text-second="props.vmCpuHelpTextSecond"
109
- :passthrough-devices="props.passthroughDevices"
110
- :mediated-devices="props.mediatedDevices"
111
- :get-datastore-table-func="props.getDatastoreTableFunc"
112
- :datastore="props.datastore"
113
- :is-datastore-loading="props.isDatastoreLoading"
114
- :project="props.project"
115
- is-clone
116
- @change-boot-order="onChangeBootOrder"
117
- @send-data="onChangeCustomizeHardware"
118
- @get-storage="emits('get-storage', $event)"
119
- @get-folders-or-files="emits('get-folders-or-files', $event)"
120
- @get-active-device-child="emits('get-active-device-child', $event)"
121
- @show-datastore-child="emits('show-datastore-child', $event)"
122
- @get-networks-table="emits('get-networks-table', $event)"
123
- @get-pci-devices="emits('get-pci-devices')"
124
- />
125
- <common-ready-to-complete
126
- v-show="selectedStep.id === dynamicSteps.readyComplete"
127
- :data="props.readyCompleteTableInfo"
128
- />
129
- </div>
130
- </template>
131
- </atoms-wizard>
132
- </div>
133
- </template>
134
-
135
- <script setup lang="ts">
136
- import type {
137
- UI_I_DatastoreTableItem,
138
- UI_I_FolderOrFileTreePayload,
139
- } from '~/lib/models/store/storage/interfaces'
140
- import type { UI_I_NetworkTableItem } from '~/lib/models/store/network/interfaces'
141
- import type { API_UI_I_Error } from '~/lib/models/store/interfaces'
142
- import type { UI_I_TablePayload } from '~/lib/models/table/interfaces'
143
- import type { UI_I_FileTreeNode } from '~/components/lib/models/interfaces'
144
- import type {
145
- UI_I_ArbitraryObject,
146
- UI_I_Localization,
147
- } from '~/lib/models/interfaces'
148
- import type { UI_I_SendDataCustomizeHardware } from '~/components/common/vm/actions/common/customizeHardware/lib/models/interfaces'
149
- import type { UI_I_ErrorValidationField } from '~/lib/models/store/interfaces'
150
- import type {
151
- UI_I_SendDataCpu,
152
- UI_I_SendDataMemory,
153
- UI_I_SendDataNewCdDvdDrive,
154
- UI_I_SendDataNewHardDisk,
155
- UI_I_SendDataNewNetwork,
156
- } from '~/components/common/vm/actions/common/customizeHardware/virtualHardware/lib/models/interfaces'
157
- import type { UI_T_SelectedNavItem } from '~/components/common/vm/actions/common/lib/models/types'
158
- import type { UI_I_TableInfoItem } from '~/components/atoms/table/info/lib/models/interfaces'
159
- import type { UI_T_ChangeBootOrder } from '~/components/common/vm/actions/lib/models/types'
160
- import type { UI_T_Project } from '~/lib/models/types'
161
- import type {
162
- UI_I_MediatedDevice,
163
- UI_I_PciDevice,
164
- UI_I_VmSettings,
165
- } from '~/lib/models/store/vm/interfaces'
166
- import type { UI_I_VmForm } from '~/components/common/vm/actions/common/lib/models/interfaces'
167
- import type {
168
- UI_I_ValidationReturn,
169
- UI_I_WizardStep,
170
- } from '~/components/atoms/wizard/lib/models/interfaces'
171
- import type { UI_I_Capabilities } from '~/components/common/vm/actions/common/lib/models/interfaces'
172
- import type { UI_I_ScheduleNewTasksForm } from '~/components/common/pages/scheduledTasks/modals/lib/models/interfaces'
173
- import type { UI_I_OptionItem } from '~/components/atoms/lib/models/interfaces'
174
- import type { UI_I_TreeNode } from '~/components/common/recursionTree/lib/models/interfaces'
175
- import {
176
- stepsSchemeInitial,
177
- stepsFunc,
178
- dynamicSteps,
179
- } from '~/components/common/vm/actions/clone/lib/config/steps'
180
- import Wizard from '~/components/atoms/wizard/lib/utils/utils'
181
- import { mapCapabilities } from '~/components/common/vm/actions/common/lib/utils/capabilities'
182
- import { scheduledTaskDefaultFormFunc } from '~/components/common/pages/scheduledTasks/modals/lib/config/createScheduledTask'
183
- import { capabilities } from '~/components/common/vm/actions/common/lib/config/capabilities'
184
-
185
- const props = defineProps<{
186
- project: UI_T_Project
187
- vmSettings: UI_I_VmSettings | null
188
- nodes: UI_I_FileTreeNode[]
189
- files: UI_I_FileTreeNode[]
190
- networksTable: UI_I_NetworkTableItem[]
191
- datastore: UI_I_DatastoreTableItem[]
192
- isDatastoreLoading: boolean
193
- errorValidationFields: UI_I_ErrorValidationField[]
194
- readyCompleteTableInfo: UI_I_TableInfoItem[]
195
- vmCpuHelpTextSecond: string
196
- finishFunc: any
197
- getDatastoreTableFunc: (payload: UI_I_TablePayload) => Promise<void>
198
- validateSendDataFunc: any
199
- passthroughDevices: UI_I_PciDevice[]
200
- mediatedDevices: UI_I_MediatedDevice[]
201
- vmNameInWizard: string
202
- capabilities?: UI_I_Capabilities
203
- schedulerTask?: any // TODO надо interface переместить глобално
204
- selectedVirtualMachine?: UI_I_Capabilities
205
- dataCenter?: UI_I_TreeNode // для сферы
206
- computeResource?: UI_I_TreeNode // для сферы
207
- computeResourceTree?: UI_I_TreeNode[] // для сферы
208
- }>()
209
-
210
- const emits = defineEmits<{
211
- (event: 'check-name', value: [string, (error: API_UI_I_Error) => void]): void
212
- (event: 'get-storage', value: UI_I_TablePayload): void
213
- (event: 'get-folders-or-files', value: UI_I_FolderOrFileTreePayload): void
214
- (event: 'get-active-device-child', value: UI_I_FileTreeNode): void
215
- (event: 'show-datastore-child', value: UI_I_FileTreeNode): void
216
- (event: 'remove-error-by-title', value: string): void
217
- (event: 'get-networks-table', value: UI_I_TablePayload): void
218
- (event: 'get-pci-devices'): void
219
- (event: 'hide'): void
220
- (
221
- event: 'get-compute-resource-tree',
222
- value: { id: string | number; cb: () => void }
223
- ): void // для сферы
224
- (event: 'show-compute-resource-tree', value: UI_I_TreeNode): void // для сферы
225
- (event: 'select-compute-resource-tree', value: UI_I_TreeNode): void // для сферы
226
- (event: 'clear-compute-resource-tree'): void // для сферы
227
- }>()
228
-
229
- const { $recursion } = useNuxtApp()
230
-
231
- const localization = computed<UI_I_Localization>(() => useLocal())
232
-
233
- const isSphere = computed<boolean>(() => props.project === 'sphere')
234
-
235
- const isScheduledTasks = computed<boolean>(
236
- () => props.schedulerTask.isSchedulerTask
237
- )
238
-
239
- const title = computed<string>(() => {
240
- const { scheduleNewTasks, scheduleTaskEdit, cloneExistingVirtualMachine } =
241
- localization.value.common
242
-
243
- let result = cloneExistingVirtualMachine
244
- if (isScheduledTasks.value) {
245
- const schedulerMode = props.schedulerTask.editTask
246
- ? scheduleTaskEdit
247
- : scheduleNewTasks
248
-
249
- result = `${schedulerMode} (${cloneExistingVirtualMachine})`
250
- }
251
-
252
- return result
253
- })
254
-
255
- watch(
256
- () => props.capabilities,
257
- () => {
258
- if (props.capabilities) {
259
- mapCapabilities(props.capabilities)
260
- }
261
- },
262
- { deep: true, immediate: true }
263
- )
264
-
265
- const wizard: Wizard = new Wizard(
266
- stepsFunc(localization.value),
267
- stepsSchemeInitial
268
- )
269
- watch(
270
- isScheduledTasks,
271
- (newValue) => {
272
- if (newValue) {
273
- wizard.changeScheme(isSphere.value ? 12 : 4)
274
- } else {
275
- wizard.changeScheme(isSphere.value ? 8 : 0)
276
- wizard.selectStepHard(isSphere.value ? 2 : 1)
277
- }
278
- },
279
- { immediate: true }
280
- )
281
-
282
- // TODO move to common
283
- const newTaskForm = ref<UI_I_ScheduleNewTasksForm>(
284
- useDeepCopy(scheduledTaskDefaultFormFunc())
285
- )
286
- watch(
287
- newTaskForm,
288
- (newValue: UI_I_ScheduleNewTasksForm) => {
289
- if (isScheduledTasks.value) wizard.setDisabledNextButton(newValue.isValid)
290
- },
291
- { immediate: true, deep: true }
292
- )
293
-
294
- const selectedScheme = computed<number[]>(() => wizard.selectedScheme.value)
295
-
296
- const onChangeSteps = async (value: UI_I_WizardStep[]): Promise<void> => {
297
- wizard.changeSteps(value, validationFunc, validateSendData)
298
- }
299
-
300
- const validationFunc = async (
301
- value: UI_I_WizardStep[],
302
- currentStep: UI_I_WizardStep,
303
- nextStep: UI_I_WizardStep
304
- ): Promise<UI_I_ValidationReturn> => {
305
- let stepHasError = false
306
- let stepShouldStop = {
307
- ifOnCurrentStep: false,
308
- ifFromAnyStep: false,
309
- stoppageStepId: -1,
310
- }
311
-
312
- wizard.setLoader(true)
313
- if (
314
- wizard.isValidateForStep(
315
- isSphere.value ? dynamicSteps.selectNameFolder : dynamicSteps.selectName,
316
- currentStep.id,
317
- nextStep.id
318
- )
319
- ) {
320
- const nameValidation = await checkName(value)
321
-
322
- value = nameValidation.newValue
323
- stepHasError = stepHasError || nameValidation.stepHasError
324
- } else if (
325
- isSphere.value &&
326
- wizard.isValidateForStep(
327
- dynamicSteps.selectComputeResource,
328
- currentStep.id,
329
- nextStep.id
330
- )
331
- ) {
332
- const computeResourceValidation = await checkComputeResource(value)
333
-
334
- value = computeResourceValidation.newValue
335
- stepHasError = stepHasError || computeResourceValidation.stepHasError
336
- } else if (
337
- wizard.isValidateForStep(
338
- dynamicSteps.selectStorage,
339
- currentStep.id,
340
- nextStep.id
341
- )
342
- ) {
343
- const storageValidation = await checkStorage(value)
344
-
345
- value = storageValidation.newValue
346
-
347
- stepHasError = stepHasError || storageValidation.stepHasError
348
- } else if (
349
- wizard.isValidateForStep(
350
- dynamicSteps.customizeHardware,
351
- currentStep.id,
352
- nextStep.id
353
- )
354
- ) {
355
- const customizeHardwareValidation = await checkCustomizeHardware(value)
356
-
357
- value = customizeHardwareValidation.newValue
358
-
359
- stepHasError = stepHasError || customizeHardwareValidation.stepHasError
360
- }
361
- wizard.setLoader(false)
362
-
363
- return {
364
- newValue: value,
365
- stepHasError,
366
- stepShouldStop,
367
- }
368
- }
369
- const checkName = async (
370
- value: UI_I_WizardStep[]
371
- ): Promise<UI_I_ValidationReturn> => {
372
- let stepHasError = false
373
-
374
- return new Promise((resolve) => {
375
- const step = isSphere.value
376
- ? dynamicSteps.selectNameFolder
377
- : dynamicSteps.selectName
378
- nameFormSubmit.value = (isValid: boolean) => {
379
- if (!isValid) {
380
- stepHasError = wizard.setValidation(step, 'name', {
381
- fieldMessage: 'aaa',
382
- alertMessage: 'aaa',
383
- })
384
- } else if (wizard.hasMessage(step, 'name')) {
385
- value = wizard.removeValidation(step, 'name', value)
386
- }
387
-
388
- resolve({
389
- stepHasError,
390
- newValue: value,
391
- })
392
- nameFormSubmit.value = null
393
- }
394
- })
395
- }
396
- const checkComputeResource = async (
397
- value: UI_I_WizardStep[]
398
- ): Promise<UI_I_ValidationReturn> => {
399
- let stepHasError = false
400
-
401
- return new Promise((resolve) => {
402
- computeResourceSubmit.value = (isValid: boolean) => {
403
- if (!isValid) {
404
- stepHasError = wizard.setValidation(
405
- dynamicSteps.selectComputeResource,
406
- 'computeResource',
407
- {
408
- fieldMessage: 'aaa',
409
- alertMessage: 'aaa',
410
- }
411
- )
412
- } else if (
413
- wizard.hasMessage(dynamicSteps.selectComputeResource, 'computeResource')
414
- ) {
415
- value = wizard.removeValidation(
416
- dynamicSteps.selectComputeResource,
417
- 'computeResource',
418
- value
419
- )
420
- }
421
-
422
- resolve({
423
- stepHasError,
424
- newValue: value,
425
- })
426
- computeResourceSubmit.value = null
427
- }
428
- })
429
- }
430
- const checkStorage = async (
431
- value: UI_I_WizardStep[]
432
- ): Promise<UI_I_ValidationReturn> => {
433
- let stepHasError = false
434
-
435
- return new Promise((resolve) => {
436
- storageSubmit.value = (isValid: boolean) => {
437
- if (!isValid) {
438
- stepHasError = wizard.setValidation(
439
- dynamicSteps.selectStorage,
440
- 'storage',
441
- {
442
- fieldMessage: 'aaa',
443
- alertMessage: 'aaa',
444
- }
445
- )
446
- } else if (wizard.hasMessage(dynamicSteps.selectStorage, 'storage')) {
447
- value = wizard.removeValidation(
448
- dynamicSteps.selectStorage,
449
- 'storage',
450
- value
451
- )
452
- }
453
-
454
- resolve({
455
- stepHasError,
456
- newValue: value,
457
- })
458
- storageSubmit.value = null
459
- }
460
- })
461
- }
462
- const checkCustomizeHardware = async (
463
- value: UI_I_WizardStep[]
464
- ): Promise<UI_I_ValidationReturn> => {
465
- let stepHasError = false
466
-
467
- return new Promise((resolve) => {
468
- customizeHardwareSubmit.value = (isValid: boolean) => {
469
- if (!isValid) {
470
- stepHasError = wizard.setValidation(
471
- dynamicSteps.customizeHardware,
472
- 'customizeHardware',
473
- {
474
- fieldMessage: 'aaa',
475
- alertMessage: 'aaa',
476
- }
477
- )
478
- } else if (
479
- wizard.hasMessage(dynamicSteps.customizeHardware, 'customizeHardware')
480
- ) {
481
- value = wizard.removeValidation(
482
- dynamicSteps.customizeHardware,
483
- 'customizeHardware',
484
- value
485
- )
486
- }
487
-
488
- resolve({
489
- stepHasError,
490
- newValue: value,
491
- })
492
- storageSubmit.value = null
493
- }
494
- })
495
- }
496
-
497
- const vmForm = ref<UI_I_VmForm>({
498
- name: '',
499
- compatibility: '',
500
- guestMachineType: null,
501
- guestOsFamily: null,
502
- guestOsVersion: null,
503
- computeResource: null,
504
- storage: null,
505
- locationPath: '',
506
- dataCenter: null,
507
- options: [],
508
- })
509
- const onChangeName = (name: string, node: UI_I_TreeNode): void => {
510
- vmForm.value.name = name
511
- if (isSphere.value) {
512
- vmForm.value.locationPath = node.id
513
- vmForm.value.dataCenter = $recursion.findParentByValue(
514
- node,
515
- 'datacenter',
516
- 'type',
517
- 'parent'
518
- )
519
- }
520
- }
521
- const onChangeStorage = (storage: UI_I_DatastoreTableItem | null): void => {
522
- if (!storage) return
523
-
524
- vmForm.value.storage = storage
525
- }
526
- const onChangeSelectOptions = (options: string[]): void => {
527
- vmForm.value.options = options
528
- if (
529
- options.includes('customize-os') &&
530
- options.includes('customize-hardware')
531
- ) {
532
- let procuratorSchame = isScheduledTasks.value ? 7 : 3
533
- let sphereSchame = isScheduledTasks.value ? 15 : 11
534
- wizard.changeScheme(isSphere.value ? sphereSchame : procuratorSchame)
535
- } else if (options.includes('customize-os')) {
536
- let procuratorSchame = isScheduledTasks.value ? 5 : 1
537
- let sphereSchame = isScheduledTasks.value ? 13 : 9
538
- wizard.changeScheme(isSphere.value ? sphereSchame : procuratorSchame)
539
- } else if (options.includes('customize-hardware')) {
540
- let procuratorSchame = isScheduledTasks.value ? 6 : 2
541
- let sphereSchame = isScheduledTasks.value ? 14 : 10
542
- wizard.changeScheme(isSphere.value ? sphereSchame : procuratorSchame)
543
- } else {
544
- let procuratorSchame = isScheduledTasks.value ? 4 : 0
545
- let sphereSchame = isScheduledTasks.value ? 12 : 8
546
- wizard.changeScheme(isSphere.value ? sphereSchame : procuratorSchame)
547
- }
548
-
549
- // Change power on by default
550
- isPowerOnByDefault.value = options.includes('power-on')
551
- }
552
- const customizeHardware = ref<UI_I_SendDataCustomizeHardware | null>(null)
553
- const onChangeCustomizeHardware = (
554
- data: UI_I_SendDataCustomizeHardware
555
- ): void => {
556
- customizeHardware.value = data
557
- }
558
-
559
- const virtualHardwareHardDisksLocal = computed<
560
- UI_I_SendDataNewHardDisk[] | null
561
- >(() => customizeHardware.value?.virtualHardware?.hardDisks || null)
562
- const virtualHardwareNetworksLocal = computed<UI_I_SendDataNewNetwork[] | null>(
563
- () => customizeHardware.value?.virtualHardware?.networks || null
564
- )
565
- const virtualHardwareCdDvdDrivesLocal = computed<
566
- UI_I_SendDataNewCdDvdDrive[] | null
567
- >(() => customizeHardware.value?.virtualHardware?.cdDvdDrives || null)
568
-
569
- const virtualHardwareCpu = computed<UI_I_SendDataCpu | null>(
570
- () => customizeHardware.value?.virtualHardware?.cpu || null
571
- )
572
- const virtualHardwareMemory = computed<UI_I_SendDataMemory | null>(
573
- () => customizeHardware.value?.virtualHardware?.memory || null
574
- )
575
- const virtualHardwareHardDisks = ref<UI_I_SendDataNewHardDisk[] | null>(null)
576
- const virtualHardwareCdDvdDrives = ref<UI_I_SendDataNewCdDvdDrive[] | null>(
577
- null
578
- )
579
- const virtualHardwareNetworks = ref<UI_I_SendDataNewNetwork[] | null>(null)
580
- const onChangeBootOrder = (data: UI_T_ChangeBootOrder): void => {
581
- virtualHardwareHardDisks.value = data[0]
582
- virtualHardwareCdDvdDrives.value = data[1]
583
- virtualHardwareNetworks.value = data[2]
584
- }
585
-
586
- const isPowerOnByDefault = ref<boolean>(false)
587
-
588
- watch(
589
- () => props.vmNameInWizard,
590
- (newValue) => {
591
- vmForm.value.name = newValue
592
- }
593
- )
594
-
595
- const validateSendData = async (
596
- value: UI_I_WizardStep[]
597
- ): Promise<UI_I_ValidationReturn> => {
598
- wizard.setLoader(true)
599
- let stepHasError = false
600
-
601
- const data = await props.validateSendDataFunc(
602
- vmForm.value,
603
- virtualHardwareCpu.value,
604
- virtualHardwareMemory.value,
605
- customizeHardware.value,
606
- virtualHardwareNetworks.value,
607
- virtualHardwareHardDisks.value,
608
- virtualHardwareCdDvdDrives.value,
609
- isPowerOnByDefault.value,
610
- localization.value,
611
- vmForm.value.locationPath, // для сферы
612
- // computeResourcePath.value // для сферы
613
- vmSettings.value.host_id // для сферы // TODO rollback
614
- )
615
-
616
- wizard.setLoader(false)
617
- if (data) {
618
- stepHasError = true
619
- selectedNavItem.value = data[0]
620
- }
621
-
622
- return {
623
- stepHasError,
624
- newValue: value,
625
- }
626
- }
627
-
628
- const isLoading = ref<boolean>(false)
629
- const onFinish = (): void => {
630
- isLoading.value = true
631
- wizard.setLoader(false)
632
- props
633
- .finishFunc(
634
- vmForm.value,
635
- virtualHardwareCpu.value,
636
- virtualHardwareMemory.value,
637
- customizeHardware.value,
638
- virtualHardwareNetworks.value,
639
- virtualHardwareHardDisks.value,
640
- virtualHardwareCdDvdDrives.value,
641
- isPowerOnByDefault.value,
642
- localization.value,
643
- vmForm.value.locationPath, // для сферы
644
- // computeResourcePath.value, // для сферы
645
- vmSettings.value.host_id, // для сферы // TODO rollback
646
- false,
647
- newTaskForm.value,
648
- props.schedulerTask
649
- )
650
- .then(() => {
651
- isLoading.value = false
652
- onHideModal()
653
- wizard.setLoader(false)
654
- })
655
- }
656
-
657
- const selectedNavItem = ref<UI_T_SelectedNavItem>(0)
658
-
659
- const nameFormSubmit = ref<null | Function>(null)
660
- const computeResourceSubmit = ref<null | Function>(null)
661
- const storageSubmit = ref<null | Function>(null)
662
- const customizeHardwareSubmit = ref<null | Function>(null)
663
-
664
- const vmSettings = computed<UI_I_VmSettings | null>(() => props.vmSettings)
665
- const vmName = ref<string>(vmSettings.value?.name || '')
666
-
667
- const guestOsFamilies = ref<UI_I_OptionItem[]>(
668
- capabilities.value.guestOsFamilies
669
- )
670
- const guestOsVersions = ref<UI_I_ArbitraryObject<UI_I_OptionItem[]>>(
671
- capabilities.value.guestOsVersions
672
- )
673
- const machineTypes = ref<UI_I_OptionItem[]>(capabilities.value.machineTypes)
674
-
675
- const computeResource = ref<UI_I_TreeNode | null>(null)
676
- const onChangeComputeResource = (node: UI_I_TreeNode): void => {
677
- computeResource.value = node
678
- }
679
- // // Для сферы
680
- const computeResourcePath = ref<string>('')
681
- const onSelectComputeResourceTree = (node: UI_I_TreeNode): void => {
682
- emits('select-compute-resource-tree', node)
683
- computeResourcePath.value = node.id
684
- }
685
-
686
- watch(vmSettings, (newValue) => {
687
- vmName.value = newValue?.name || ''
688
-
689
- if (newValue?.guestOsFamily)
690
- vmForm.value.guestOsFamily = newValue.guestOsFamily
691
- if (newValue?.guestMachineType)
692
- vmForm.value.guestMachineType = newValue.guestMachineType
693
- if (newValue?.guestOsVersion)
694
- vmForm.value.guestOsVersion = newValue.guestOsVersion
695
-
696
- if (newValue?.compatibility)
697
- vmForm.value.compatibility = newValue.compatibility
698
-
699
- if (newValue?.storage) {
700
- const datastore = props.datastore.find(
701
- (item) => item.id === newValue.storage.id
702
- )
703
- if (datastore) vmForm.value.storage = datastore
704
- }
705
- })
706
-
707
- const onHideModal = (): void => {
708
- emits('hide')
709
- }
710
- </script>
711
-
712
- <style scoped lang="scss">
713
- :deep(.has-solid.close-icon.clr-icon) {
714
- width: 20px;
715
- top: 0;
716
- }
717
- .vm-context {
718
- padding: 16px 15px 10px 10px;
719
- height: 100%;
720
- display: flex;
721
- flex-direction: column;
722
-
723
- .context-title-wrap {
724
- padding-bottom: 3px;
725
- border-bottom: 1px solid #a6a6a6;
726
-
727
- h4 {
728
- font-weight: 700;
729
- font-size: 13px;
730
- color: var(--vm-context-title);
731
- }
732
- p {
733
- font-weight: 400;
734
- font-size: 13px;
735
- color: var(--vm-context-sub-title);
736
- }
737
- }
738
-
739
- .finish-block {
740
- padding: 18px 24px 24px 24px;
741
-
742
- .add-hosts-ready-to-complete-mt-12 {
743
- margin-top: 12px;
744
-
745
- .add-hosts-ready-to-complete-bold {
746
- line-height: 18px;
747
- font-weight: 700;
748
- }
749
- }
750
- }
751
-
752
- .vm-hardware-version {
753
- align-self: flex-end;
754
- margin-top: auto;
755
- }
756
- }
757
-
758
- :deep(.modal .modal-dialog .modal-content .modal-footer) {
759
- flex: unset;
760
- height: unset;
761
- min-height: unset;
762
- }
763
- :deep(.wizard-modal-titlebar h3) {
764
- color: #000;
765
- font-size: 24px;
766
- font-weight: 200;
767
- line-height: 27px;
768
- margin: 0;
769
- padding: 0;
770
- }
771
- :deep(.clr-wizard-stepnav-item) {
772
- padding-left: 0;
773
- }
774
- :deep(.clr-wizard-stepnav
775
- .clr-wizard-stepnav-item
776
- button
777
- .clr-wizard-stepnav-link-title) {
778
- width: 189px;
779
- font-weight: 700;
780
- font-size: 13px;
781
- }
782
-
783
- #vm-wizard-notification {
784
- h3 {
785
- color: var(--global-font-color7);
786
- margin-top: 6px;
787
- }
788
- p {
789
- color: var(--global-font-color6);
790
- line-height: 16px;
791
- }
792
- }
793
-
794
- .power-on-by-default-wrap {
795
- display: flex;
796
- align-items: center;
797
-
798
- input {
799
- margin-right: 6px;
800
- }
801
- }
802
-
803
- .new-task-form {
804
- padding: 0 25px 0 5px;
805
- }
806
- </style>
807
-
808
- <style>
809
- :root {
810
- --vm-context-title: #333;
811
- --vm-context-sub-title: #000;
812
- }
813
- :root.dark-theme {
814
- --vm-context-title: #adbbc4;
815
- --vm-context-sub-title: #adbbc4;
816
- }
817
- </style>
1
+ <template>
2
+ <div class="clone-vm">
3
+ <atoms-wizard
4
+ show
5
+ :wizard="wizard"
6
+ :selected-scheme="selectedScheme"
7
+ :title="title"
8
+ :localization="localization"
9
+ @change-steps="onChangeSteps"
10
+ @hide="onHideModal"
11
+ @submit="onFinish"
12
+ >
13
+ <template #modalBody="{ selectedStep }">
14
+ <atoms-loader v-show="!vmSettings || isLoading" id="loader" />
15
+ <div v-if="vmSettings" class="vm-context">
16
+ <common-pages-scheduled-tasks-modals-common-new-task-form
17
+ v-show="selectedStep.id === dynamicSteps.scheduledTasks"
18
+ v-model="newTaskForm"
19
+ :target="selectedVirtualMachine"
20
+ class="new-task-form"
21
+ />
22
+ <common-vm-actions-common-select-name
23
+ v-show="
24
+ selectedStep.id === dynamicSteps.selectName ||
25
+ selectedStep.id === dynamicSteps.selectNameFolder
26
+ "
27
+ :show="
28
+ selectedStep.id === dynamicSteps.selectName ||
29
+ selectedStep.id === dynamicSteps.selectNameFolder
30
+ "
31
+ :name-form-submit="nameFormSubmit"
32
+ :project="props.project"
33
+ :data-center="props.dataCenter"
34
+ @submit="onChangeName(...$event)"
35
+ @check-name="emits('check-name', $event)"
36
+ />
37
+ <common-vm-actions-common-select-compute-resource
38
+ v-if="isSphere"
39
+ v-show="selectedStep.id === dynamicSteps.selectComputeResource"
40
+ v-model="computeResource"
41
+ :compute-resource-submit="computeResourceSubmit"
42
+ :data-center="vmForm.dataCenter"
43
+ :compute-resource="props.computeResource"
44
+ :compute-resource-tree="props.computeResourceTree"
45
+ @submit="onChangeComputeResource"
46
+ @select-compute-resource-tree="onSelectComputeResourceTree"
47
+ @get-compute-resource-tree="
48
+ emits('get-compute-resource-tree', $event)
49
+ "
50
+ @show-compute-resource-tree="
51
+ emits('show-compute-resource-tree', $event)
52
+ "
53
+ @clear-compute-resource-tree="emits('clear-compute-resource-tree')"
54
+ />
55
+ <common-vm-actions-common-select-storage
56
+ v-show="selectedStep.id === dynamicSteps.selectStorage"
57
+ :storage-submit="storageSubmit"
58
+ :datastore="props.datastore"
59
+ :is-datastore-loading="props.isDatastoreLoading"
60
+ :storage="vmForm.storage"
61
+ :get-datastore-table-func="props.getDatastoreTableFunc"
62
+ @submit="onChangeStorage"
63
+ />
64
+ <common-vm-actions-common-select-options
65
+ v-show="selectedStep.id === dynamicSteps.selectOptions"
66
+ @change="onChangeSelectOptions"
67
+ />
68
+ <common-vm-actions-common-select-os
69
+ v-show="selectedStep.id === dynamicSteps.selectGuestOSMachineType"
70
+ v-model:machine-type="vmForm.guestMachineType"
71
+ v-model:guest-os-family="vmForm.guestOsFamily"
72
+ v-model:guest-os-version="vmForm.guestOsVersion"
73
+ :families-options="guestOsFamilies"
74
+ :versions-options="guestOsVersions"
75
+ :machine-types-options="machineTypes"
76
+ :error-validation-fields="props.errorValidationFields"
77
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
78
+ />
79
+ <common-vm-actions-common-customize-hardware
80
+ v-show="selectedStep.id === dynamicSteps.customizeHardware"
81
+ v-model:vm-name="vmName"
82
+ v-model:guest-machine-type="vmSettings.guestMachineType"
83
+ v-model:guest-os-family="vmSettings.guestOsFamily"
84
+ v-model:guest-os-version="vmSettings.guestOsVersion"
85
+ :storage="vmForm.storage"
86
+ :hard-disks-for-boot-options="virtualHardwareHardDisksLocal"
87
+ :cd-dvd-drives-for-boot-options="virtualHardwareCdDvdDrivesLocal"
88
+ :networks-for-boot-options="virtualHardwareNetworksLocal"
89
+ :cd-dvd-drives="vmSettings.cdDvdDrives"
90
+ :hard-disks="vmSettings.hardDisks"
91
+ :networks="vmSettings.networks"
92
+ :customize-hardware-submit="customizeHardwareSubmit"
93
+ :max-cpus="vmSettings.maxCpus"
94
+ :max-memory="vmSettings.maxMemory"
95
+ :cpu-models="vmSettings.cpuModels"
96
+ :cpu="vmSettings.cpu"
97
+ :memory="vmSettings.memory"
98
+ :video-card="vmSettings.videoCard"
99
+ :usb-controller="vmSettings.usbController"
100
+ :pci-devices="vmSettings.pciDevices"
101
+ :selected-nav-item="selectedNavItem"
102
+ :hard-disks-for-edit="vmSettings.hardDisks"
103
+ :options="vmSettings.options"
104
+ :nodes="props.nodes"
105
+ :files="props.files"
106
+ :networks-table="props.networksTable"
107
+ :error-validation-fields="props.errorValidationFields"
108
+ :vm-cpu-help-text-second="props.vmCpuHelpTextSecond"
109
+ :passthrough-devices="props.passthroughDevices"
110
+ :mediated-devices="props.mediatedDevices"
111
+ :get-datastore-table-func="props.getDatastoreTableFunc"
112
+ :datastore="props.datastore"
113
+ :is-datastore-loading="props.isDatastoreLoading"
114
+ :project="props.project"
115
+ is-clone
116
+ @change-boot-order="onChangeBootOrder"
117
+ @send-data="onChangeCustomizeHardware"
118
+ @get-storage="emits('get-storage', $event)"
119
+ @get-folders-or-files="emits('get-folders-or-files', $event)"
120
+ @get-active-device-child="emits('get-active-device-child', $event)"
121
+ @show-datastore-child="emits('show-datastore-child', $event)"
122
+ @get-networks-table="emits('get-networks-table', $event)"
123
+ @get-pci-devices="emits('get-pci-devices')"
124
+ />
125
+ <common-ready-to-complete
126
+ v-show="selectedStep.id === dynamicSteps.readyComplete"
127
+ :data="props.readyCompleteTableInfo"
128
+ />
129
+ </div>
130
+ </template>
131
+ </atoms-wizard>
132
+ </div>
133
+ </template>
134
+
135
+ <script setup lang="ts">
136
+ import type {
137
+ UI_I_DatastoreTableItem,
138
+ UI_I_FolderOrFileTreePayload,
139
+ } from '~/lib/models/store/storage/interfaces'
140
+ import type { UI_I_NetworkTableItem } from '~/lib/models/store/network/interfaces'
141
+ import type { API_UI_I_Error } from '~/lib/models/store/interfaces'
142
+ import type { UI_I_TablePayload } from '~/lib/models/table/interfaces'
143
+ import type { UI_I_FileTreeNode } from '~/components/lib/models/interfaces'
144
+ import type {
145
+ UI_I_ArbitraryObject,
146
+ UI_I_Localization,
147
+ } from '~/lib/models/interfaces'
148
+ import type { UI_I_SendDataCustomizeHardware } from '~/components/common/vm/actions/common/customizeHardware/lib/models/interfaces'
149
+ import type { UI_I_ErrorValidationField } from '~/lib/models/store/interfaces'
150
+ import type {
151
+ UI_I_SendDataCpu,
152
+ UI_I_SendDataMemory,
153
+ UI_I_SendDataNewCdDvdDrive,
154
+ UI_I_SendDataNewHardDisk,
155
+ UI_I_SendDataNewNetwork,
156
+ } from '~/components/common/vm/actions/common/customizeHardware/virtualHardware/lib/models/interfaces'
157
+ import type { UI_T_SelectedNavItem } from '~/components/common/vm/actions/common/lib/models/types'
158
+ import type { UI_I_TableInfoItem } from '~/components/atoms/table/info/lib/models/interfaces'
159
+ import type { UI_T_ChangeBootOrder } from '~/components/common/vm/actions/lib/models/types'
160
+ import type { UI_T_Project } from '~/lib/models/types'
161
+ import type {
162
+ UI_I_MediatedDevice,
163
+ UI_I_PciDevice,
164
+ UI_I_VmSettings,
165
+ } from '~/lib/models/store/vm/interfaces'
166
+ import type { UI_I_VmForm } from '~/components/common/vm/actions/common/lib/models/interfaces'
167
+ import type {
168
+ UI_I_ValidationReturn,
169
+ UI_I_WizardStep,
170
+ } from '~/components/atoms/wizard/lib/models/interfaces'
171
+ import type { UI_I_Capabilities } from '~/components/common/vm/actions/common/lib/models/interfaces'
172
+ import type { UI_I_ScheduleNewTasksForm } from '~/components/common/pages/scheduledTasks/modals/lib/models/interfaces'
173
+ import type { UI_I_OptionItem } from '~/components/atoms/lib/models/interfaces'
174
+ import type { UI_I_TreeNode } from '~/components/common/recursionTree/lib/models/interfaces'
175
+ import {
176
+ stepsSchemeInitial,
177
+ stepsFunc,
178
+ dynamicSteps,
179
+ } from '~/components/common/vm/actions/clone/lib/config/steps'
180
+ import Wizard from '~/components/atoms/wizard/lib/utils/utils'
181
+ import { mapCapabilities } from '~/components/common/vm/actions/common/lib/utils/capabilities'
182
+ import { scheduledTaskDefaultFormFunc } from '~/components/common/pages/scheduledTasks/modals/lib/config/createScheduledTask'
183
+ import { capabilities } from '~/components/common/vm/actions/common/lib/config/capabilities'
184
+
185
+ const props = defineProps<{
186
+ project: UI_T_Project
187
+ vmSettings: UI_I_VmSettings | null
188
+ nodes: UI_I_FileTreeNode[]
189
+ files: UI_I_FileTreeNode[]
190
+ networksTable: UI_I_NetworkTableItem[]
191
+ datastore: UI_I_DatastoreTableItem[]
192
+ isDatastoreLoading: boolean
193
+ errorValidationFields: UI_I_ErrorValidationField[]
194
+ readyCompleteTableInfo: UI_I_TableInfoItem[]
195
+ vmCpuHelpTextSecond: string
196
+ finishFunc: any
197
+ getDatastoreTableFunc: (payload: UI_I_TablePayload) => Promise<void>
198
+ validateSendDataFunc: any
199
+ passthroughDevices: UI_I_PciDevice[]
200
+ mediatedDevices: UI_I_MediatedDevice[]
201
+ vmNameInWizard: string
202
+ capabilities?: UI_I_Capabilities
203
+ schedulerTask?: any // TODO надо interface переместить глобално
204
+ selectedVirtualMachine?: UI_I_Capabilities
205
+ isNewVmFromTemplate?: boolean
206
+ dataCenter?: UI_I_TreeNode // для сферы
207
+ computeResource?: UI_I_TreeNode // для сферы
208
+ computeResourceTree?: UI_I_TreeNode[] // для сферы
209
+ }>()
210
+
211
+ const emits = defineEmits<{
212
+ (event: 'check-name', value: [string, (error: API_UI_I_Error) => void]): void
213
+ (event: 'get-storage', value: UI_I_TablePayload): void
214
+ (event: 'get-folders-or-files', value: UI_I_FolderOrFileTreePayload): void
215
+ (event: 'get-active-device-child', value: UI_I_FileTreeNode): void
216
+ (event: 'show-datastore-child', value: UI_I_FileTreeNode): void
217
+ (event: 'remove-error-by-title', value: string): void
218
+ (event: 'get-networks-table', value: UI_I_TablePayload): void
219
+ (event: 'get-pci-devices'): void
220
+ (event: 'hide'): void
221
+ (
222
+ event: 'get-compute-resource-tree',
223
+ value: { id: string | number; cb: () => void }
224
+ ): void // для сферы
225
+ (event: 'show-compute-resource-tree', value: UI_I_TreeNode): void // для сферы
226
+ (event: 'select-compute-resource-tree', value: UI_I_TreeNode): void // для сферы
227
+ (event: 'clear-compute-resource-tree'): void // для сферы
228
+ }>()
229
+
230
+ const { $recursion } = useNuxtApp()
231
+
232
+ const localization = computed<UI_I_Localization>(() => useLocal())
233
+
234
+ const isSphere = computed<boolean>(() => props.project === 'sphere')
235
+
236
+ const isScheduledTasks = computed<boolean>(
237
+ () => props.schedulerTask.isSchedulerTask
238
+ )
239
+
240
+ const title = computed<string>(() => {
241
+ const { scheduleNewTasks, scheduleTaskEdit, cloneExistingVirtualMachine } =
242
+ localization.value.common
243
+
244
+ let result = cloneExistingVirtualMachine
245
+ if (isScheduledTasks.value) {
246
+ const schedulerMode = props.schedulerTask.editTask
247
+ ? scheduleTaskEdit
248
+ : scheduleNewTasks
249
+
250
+ result = `${schedulerMode} (${cloneExistingVirtualMachine})`
251
+ }
252
+
253
+ if (props.isNewVmFromTemplate) {
254
+ result = localization.value.vmWizard.deployFromTemplate
255
+ }
256
+
257
+ return result
258
+ })
259
+
260
+ watch(
261
+ () => props.capabilities,
262
+ () => {
263
+ if (props.capabilities) {
264
+ mapCapabilities(props.capabilities)
265
+ }
266
+ },
267
+ { deep: true, immediate: true }
268
+ )
269
+
270
+ const wizard: Wizard = new Wizard(
271
+ stepsFunc(localization.value),
272
+ stepsSchemeInitial
273
+ )
274
+ watch(
275
+ isScheduledTasks,
276
+ (newValue) => {
277
+ if (newValue) {
278
+ wizard.changeScheme(isSphere.value ? 12 : 4)
279
+ } else {
280
+ wizard.changeScheme(isSphere.value ? 8 : 0)
281
+ wizard.selectStepHard(isSphere.value ? 2 : 1)
282
+ }
283
+ },
284
+ { immediate: true }
285
+ )
286
+
287
+ // TODO move to common
288
+ const newTaskForm = ref<UI_I_ScheduleNewTasksForm>(
289
+ useDeepCopy(scheduledTaskDefaultFormFunc())
290
+ )
291
+ watch(
292
+ newTaskForm,
293
+ (newValue: UI_I_ScheduleNewTasksForm) => {
294
+ if (isScheduledTasks.value) wizard.setDisabledNextButton(newValue.isValid)
295
+ },
296
+ { immediate: true, deep: true }
297
+ )
298
+
299
+ const selectedScheme = computed<number[]>(() => wizard.selectedScheme.value)
300
+
301
+ const onChangeSteps = async (value: UI_I_WizardStep[]): Promise<void> => {
302
+ wizard.changeSteps(value, validationFunc, validateSendData)
303
+ }
304
+
305
+ const validationFunc = async (
306
+ value: UI_I_WizardStep[],
307
+ currentStep: UI_I_WizardStep,
308
+ nextStep: UI_I_WizardStep
309
+ ): Promise<UI_I_ValidationReturn> => {
310
+ let stepHasError = false
311
+ let stepShouldStop = {
312
+ ifOnCurrentStep: false,
313
+ ifFromAnyStep: false,
314
+ stoppageStepId: -1,
315
+ }
316
+
317
+ wizard.setLoader(true)
318
+ if (
319
+ wizard.isValidateForStep(
320
+ isSphere.value ? dynamicSteps.selectNameFolder : dynamicSteps.selectName,
321
+ currentStep.id,
322
+ nextStep.id
323
+ )
324
+ ) {
325
+ const nameValidation = await checkName(value)
326
+
327
+ value = nameValidation.newValue
328
+ stepHasError = stepHasError || nameValidation.stepHasError
329
+ } else if (
330
+ isSphere.value &&
331
+ wizard.isValidateForStep(
332
+ dynamicSteps.selectComputeResource,
333
+ currentStep.id,
334
+ nextStep.id
335
+ )
336
+ ) {
337
+ const computeResourceValidation = await checkComputeResource(value)
338
+
339
+ value = computeResourceValidation.newValue
340
+ stepHasError = stepHasError || computeResourceValidation.stepHasError
341
+ } else if (
342
+ wizard.isValidateForStep(
343
+ dynamicSteps.selectStorage,
344
+ currentStep.id,
345
+ nextStep.id
346
+ )
347
+ ) {
348
+ const storageValidation = await checkStorage(value)
349
+
350
+ value = storageValidation.newValue
351
+
352
+ stepHasError = stepHasError || storageValidation.stepHasError
353
+ } else if (
354
+ wizard.isValidateForStep(
355
+ dynamicSteps.customizeHardware,
356
+ currentStep.id,
357
+ nextStep.id
358
+ )
359
+ ) {
360
+ const customizeHardwareValidation = await checkCustomizeHardware(value)
361
+
362
+ value = customizeHardwareValidation.newValue
363
+
364
+ stepHasError = stepHasError || customizeHardwareValidation.stepHasError
365
+ }
366
+ wizard.setLoader(false)
367
+
368
+ return {
369
+ newValue: value,
370
+ stepHasError,
371
+ stepShouldStop,
372
+ }
373
+ }
374
+ const checkName = async (
375
+ value: UI_I_WizardStep[]
376
+ ): Promise<UI_I_ValidationReturn> => {
377
+ let stepHasError = false
378
+
379
+ return new Promise((resolve) => {
380
+ const step = isSphere.value
381
+ ? dynamicSteps.selectNameFolder
382
+ : dynamicSteps.selectName
383
+ nameFormSubmit.value = (isValid: boolean) => {
384
+ if (!isValid) {
385
+ stepHasError = wizard.setValidation(step, 'name', {
386
+ fieldMessage: 'aaa',
387
+ alertMessage: 'aaa',
388
+ })
389
+ } else if (wizard.hasMessage(step, 'name')) {
390
+ value = wizard.removeValidation(step, 'name', value)
391
+ }
392
+
393
+ resolve({
394
+ stepHasError,
395
+ newValue: value,
396
+ })
397
+ nameFormSubmit.value = null
398
+ }
399
+ })
400
+ }
401
+ const checkComputeResource = async (
402
+ value: UI_I_WizardStep[]
403
+ ): Promise<UI_I_ValidationReturn> => {
404
+ let stepHasError = false
405
+
406
+ return new Promise((resolve) => {
407
+ computeResourceSubmit.value = (isValid: boolean) => {
408
+ if (!isValid) {
409
+ stepHasError = wizard.setValidation(
410
+ dynamicSteps.selectComputeResource,
411
+ 'computeResource',
412
+ {
413
+ fieldMessage: 'aaa',
414
+ alertMessage: 'aaa',
415
+ }
416
+ )
417
+ } else if (
418
+ wizard.hasMessage(dynamicSteps.selectComputeResource, 'computeResource')
419
+ ) {
420
+ value = wizard.removeValidation(
421
+ dynamicSteps.selectComputeResource,
422
+ 'computeResource',
423
+ value
424
+ )
425
+ }
426
+
427
+ resolve({
428
+ stepHasError,
429
+ newValue: value,
430
+ })
431
+ computeResourceSubmit.value = null
432
+ }
433
+ })
434
+ }
435
+ const checkStorage = async (
436
+ value: UI_I_WizardStep[]
437
+ ): Promise<UI_I_ValidationReturn> => {
438
+ let stepHasError = false
439
+
440
+ return new Promise((resolve) => {
441
+ storageSubmit.value = (isValid: boolean) => {
442
+ if (!isValid) {
443
+ stepHasError = wizard.setValidation(
444
+ dynamicSteps.selectStorage,
445
+ 'storage',
446
+ {
447
+ fieldMessage: 'aaa',
448
+ alertMessage: 'aaa',
449
+ }
450
+ )
451
+ } else if (wizard.hasMessage(dynamicSteps.selectStorage, 'storage')) {
452
+ value = wizard.removeValidation(
453
+ dynamicSteps.selectStorage,
454
+ 'storage',
455
+ value
456
+ )
457
+ }
458
+
459
+ resolve({
460
+ stepHasError,
461
+ newValue: value,
462
+ })
463
+ storageSubmit.value = null
464
+ }
465
+ })
466
+ }
467
+ const checkCustomizeHardware = async (
468
+ value: UI_I_WizardStep[]
469
+ ): Promise<UI_I_ValidationReturn> => {
470
+ let stepHasError = false
471
+
472
+ return new Promise((resolve) => {
473
+ customizeHardwareSubmit.value = (isValid: boolean) => {
474
+ if (!isValid) {
475
+ stepHasError = wizard.setValidation(
476
+ dynamicSteps.customizeHardware,
477
+ 'customizeHardware',
478
+ {
479
+ fieldMessage: 'aaa',
480
+ alertMessage: 'aaa',
481
+ }
482
+ )
483
+ } else if (
484
+ wizard.hasMessage(dynamicSteps.customizeHardware, 'customizeHardware')
485
+ ) {
486
+ value = wizard.removeValidation(
487
+ dynamicSteps.customizeHardware,
488
+ 'customizeHardware',
489
+ value
490
+ )
491
+ }
492
+
493
+ resolve({
494
+ stepHasError,
495
+ newValue: value,
496
+ })
497
+ storageSubmit.value = null
498
+ }
499
+ })
500
+ }
501
+
502
+ const vmForm = ref<UI_I_VmForm>({
503
+ name: '',
504
+ compatibility: '',
505
+ guestMachineType: null,
506
+ guestOsFamily: null,
507
+ guestOsVersion: null,
508
+ computeResource: null,
509
+ storage: null,
510
+ locationPath: '',
511
+ dataCenter: null,
512
+ options: [],
513
+ })
514
+ const onChangeName = (name: string, node: UI_I_TreeNode): void => {
515
+ vmForm.value.name = name
516
+ if (isSphere.value) {
517
+ vmForm.value.locationPath = node.id
518
+ vmForm.value.dataCenter = $recursion.findParentByValue(
519
+ node,
520
+ 'datacenter',
521
+ 'type',
522
+ 'parent'
523
+ )
524
+ }
525
+ }
526
+ const onChangeStorage = (storage: UI_I_DatastoreTableItem | null): void => {
527
+ if (!storage) return
528
+
529
+ vmForm.value.storage = storage
530
+ }
531
+ const onChangeSelectOptions = (options: string[]): void => {
532
+ vmForm.value.options = options
533
+ if (
534
+ options.includes('customize-os') &&
535
+ options.includes('customize-hardware')
536
+ ) {
537
+ let procuratorSchame = isScheduledTasks.value ? 7 : 3
538
+ let sphereSchame = isScheduledTasks.value ? 15 : 11
539
+ wizard.changeScheme(isSphere.value ? sphereSchame : procuratorSchame)
540
+ } else if (options.includes('customize-os')) {
541
+ let procuratorSchame = isScheduledTasks.value ? 5 : 1
542
+ let sphereSchame = isScheduledTasks.value ? 13 : 9
543
+ wizard.changeScheme(isSphere.value ? sphereSchame : procuratorSchame)
544
+ } else if (options.includes('customize-hardware')) {
545
+ let procuratorSchame = isScheduledTasks.value ? 6 : 2
546
+ let sphereSchame = isScheduledTasks.value ? 14 : 10
547
+ wizard.changeScheme(isSphere.value ? sphereSchame : procuratorSchame)
548
+ } else {
549
+ let procuratorSchame = isScheduledTasks.value ? 4 : 0
550
+ let sphereSchame = isScheduledTasks.value ? 12 : 8
551
+ wizard.changeScheme(isSphere.value ? sphereSchame : procuratorSchame)
552
+ }
553
+
554
+ // Change power on by default
555
+ isPowerOnByDefault.value = options.includes('power-on')
556
+ }
557
+ const customizeHardware = ref<UI_I_SendDataCustomizeHardware | null>(null)
558
+ const onChangeCustomizeHardware = (
559
+ data: UI_I_SendDataCustomizeHardware
560
+ ): void => {
561
+ customizeHardware.value = data
562
+ }
563
+
564
+ const virtualHardwareHardDisksLocal = computed<
565
+ UI_I_SendDataNewHardDisk[] | null
566
+ >(() => customizeHardware.value?.virtualHardware?.hardDisks || null)
567
+ const virtualHardwareNetworksLocal = computed<UI_I_SendDataNewNetwork[] | null>(
568
+ () => customizeHardware.value?.virtualHardware?.networks || null
569
+ )
570
+ const virtualHardwareCdDvdDrivesLocal = computed<
571
+ UI_I_SendDataNewCdDvdDrive[] | null
572
+ >(() => customizeHardware.value?.virtualHardware?.cdDvdDrives || null)
573
+
574
+ const virtualHardwareCpu = computed<UI_I_SendDataCpu | null>(
575
+ () => customizeHardware.value?.virtualHardware?.cpu || null
576
+ )
577
+ const virtualHardwareMemory = computed<UI_I_SendDataMemory | null>(
578
+ () => customizeHardware.value?.virtualHardware?.memory || null
579
+ )
580
+ const virtualHardwareHardDisks = ref<UI_I_SendDataNewHardDisk[] | null>(null)
581
+ const virtualHardwareCdDvdDrives = ref<UI_I_SendDataNewCdDvdDrive[] | null>(
582
+ null
583
+ )
584
+ const virtualHardwareNetworks = ref<UI_I_SendDataNewNetwork[] | null>(null)
585
+ const onChangeBootOrder = (data: UI_T_ChangeBootOrder): void => {
586
+ virtualHardwareHardDisks.value = data[0]
587
+ virtualHardwareCdDvdDrives.value = data[1]
588
+ virtualHardwareNetworks.value = data[2]
589
+ }
590
+
591
+ const isPowerOnByDefault = ref<boolean>(false)
592
+
593
+ watch(
594
+ () => props.vmNameInWizard,
595
+ (newValue) => {
596
+ vmForm.value.name = newValue
597
+ }
598
+ )
599
+
600
+ const validateSendData = async (
601
+ value: UI_I_WizardStep[]
602
+ ): Promise<UI_I_ValidationReturn> => {
603
+ wizard.setLoader(true)
604
+ let stepHasError = false
605
+
606
+ const data = await props.validateSendDataFunc(
607
+ vmForm.value,
608
+ virtualHardwareCpu.value,
609
+ virtualHardwareMemory.value,
610
+ customizeHardware.value,
611
+ virtualHardwareNetworks.value,
612
+ virtualHardwareHardDisks.value,
613
+ virtualHardwareCdDvdDrives.value,
614
+ isPowerOnByDefault.value,
615
+ localization.value,
616
+ vmForm.value.locationPath, // для сферы
617
+ // computeResourcePath.value // для сферы
618
+ vmSettings.value.host_id // для сферы // TODO rollback
619
+ )
620
+
621
+ wizard.setLoader(false)
622
+ if (data) {
623
+ stepHasError = true
624
+ selectedNavItem.value = data[0]
625
+ }
626
+
627
+ return {
628
+ stepHasError,
629
+ newValue: value,
630
+ }
631
+ }
632
+
633
+ const isLoading = ref<boolean>(false)
634
+ const onFinish = (): void => {
635
+ isLoading.value = true
636
+ wizard.setLoader(false)
637
+ props
638
+ .finishFunc(
639
+ vmForm.value,
640
+ virtualHardwareCpu.value,
641
+ virtualHardwareMemory.value,
642
+ customizeHardware.value,
643
+ virtualHardwareNetworks.value,
644
+ virtualHardwareHardDisks.value,
645
+ virtualHardwareCdDvdDrives.value,
646
+ isPowerOnByDefault.value,
647
+ localization.value,
648
+ vmForm.value.locationPath, // для сферы
649
+ // computeResourcePath.value, // для сферы
650
+ vmSettings.value.host_id, // для сферы // TODO rollback
651
+ false,
652
+ newTaskForm.value,
653
+ props.schedulerTask
654
+ )
655
+ .then(() => {
656
+ isLoading.value = false
657
+ onHideModal()
658
+ wizard.setLoader(false)
659
+ })
660
+ }
661
+
662
+ const selectedNavItem = ref<UI_T_SelectedNavItem>(0)
663
+
664
+ const nameFormSubmit = ref<null | Function>(null)
665
+ const computeResourceSubmit = ref<null | Function>(null)
666
+ const storageSubmit = ref<null | Function>(null)
667
+ const customizeHardwareSubmit = ref<null | Function>(null)
668
+
669
+ const vmSettings = computed<UI_I_VmSettings | null>(() => props.vmSettings)
670
+ const vmName = ref<string>(vmSettings.value?.name || '')
671
+
672
+ const guestOsFamilies = ref<UI_I_OptionItem[]>(
673
+ capabilities.value.guestOsFamilies
674
+ )
675
+ const guestOsVersions = ref<UI_I_ArbitraryObject<UI_I_OptionItem[]>>(
676
+ capabilities.value.guestOsVersions
677
+ )
678
+ const machineTypes = ref<UI_I_OptionItem[]>(capabilities.value.machineTypes)
679
+
680
+ const computeResource = ref<UI_I_TreeNode | null>(null)
681
+ const onChangeComputeResource = (node: UI_I_TreeNode): void => {
682
+ computeResource.value = node
683
+ }
684
+ // // Для сферы
685
+ const computeResourcePath = ref<string>('')
686
+ const onSelectComputeResourceTree = (node: UI_I_TreeNode): void => {
687
+ emits('select-compute-resource-tree', node)
688
+ computeResourcePath.value = node.id
689
+ }
690
+
691
+ watch(vmSettings, (newValue) => {
692
+ vmName.value = newValue?.name || ''
693
+
694
+ if (newValue?.guestOsFamily)
695
+ vmForm.value.guestOsFamily = newValue.guestOsFamily
696
+ if (newValue?.guestMachineType)
697
+ vmForm.value.guestMachineType = newValue.guestMachineType
698
+ if (newValue?.guestOsVersion)
699
+ vmForm.value.guestOsVersion = newValue.guestOsVersion
700
+
701
+ if (newValue?.compatibility)
702
+ vmForm.value.compatibility = newValue.compatibility
703
+
704
+ if (newValue?.storage) {
705
+ const datastore = props.datastore.find(
706
+ (item) => item.id === newValue.storage.id
707
+ )
708
+ if (datastore) vmForm.value.storage = datastore
709
+ }
710
+ })
711
+
712
+ const onHideModal = (): void => {
713
+ emits('hide')
714
+ }
715
+ </script>
716
+
717
+ <style scoped lang="scss">
718
+ :deep(.has-solid.close-icon.clr-icon) {
719
+ width: 20px;
720
+ top: 0;
721
+ }
722
+ .vm-context {
723
+ padding: 16px 15px 10px 10px;
724
+ height: 100%;
725
+ display: flex;
726
+ flex-direction: column;
727
+
728
+ .context-title-wrap {
729
+ padding-bottom: 3px;
730
+ border-bottom: 1px solid #a6a6a6;
731
+
732
+ h4 {
733
+ font-weight: 700;
734
+ font-size: 13px;
735
+ color: var(--vm-context-title);
736
+ }
737
+ p {
738
+ font-weight: 400;
739
+ font-size: 13px;
740
+ color: var(--vm-context-sub-title);
741
+ }
742
+ }
743
+
744
+ .finish-block {
745
+ padding: 18px 24px 24px 24px;
746
+
747
+ .add-hosts-ready-to-complete-mt-12 {
748
+ margin-top: 12px;
749
+
750
+ .add-hosts-ready-to-complete-bold {
751
+ line-height: 18px;
752
+ font-weight: 700;
753
+ }
754
+ }
755
+ }
756
+
757
+ .vm-hardware-version {
758
+ align-self: flex-end;
759
+ margin-top: auto;
760
+ }
761
+ }
762
+
763
+ :deep(.modal .modal-dialog .modal-content .modal-footer) {
764
+ flex: unset;
765
+ height: unset;
766
+ min-height: unset;
767
+ }
768
+ :deep(.wizard-modal-titlebar h3) {
769
+ color: #000;
770
+ font-size: 24px;
771
+ font-weight: 200;
772
+ line-height: 27px;
773
+ margin: 0;
774
+ padding: 0;
775
+ }
776
+ :deep(.clr-wizard-stepnav-item) {
777
+ padding-left: 0;
778
+ }
779
+ :deep(.clr-wizard-stepnav
780
+ .clr-wizard-stepnav-item
781
+ button
782
+ .clr-wizard-stepnav-link-title) {
783
+ width: 189px;
784
+ font-weight: 700;
785
+ font-size: 13px;
786
+ }
787
+
788
+ #vm-wizard-notification {
789
+ h3 {
790
+ color: var(--global-font-color7);
791
+ margin-top: 6px;
792
+ }
793
+ p {
794
+ color: var(--global-font-color6);
795
+ line-height: 16px;
796
+ }
797
+ }
798
+
799
+ .power-on-by-default-wrap {
800
+ display: flex;
801
+ align-items: center;
802
+
803
+ input {
804
+ margin-right: 6px;
805
+ }
806
+ }
807
+
808
+ .new-task-form {
809
+ padding: 0 25px 0 5px;
810
+ }
811
+ </style>
812
+
813
+ <style>
814
+ :root {
815
+ --vm-context-title: #333;
816
+ --vm-context-sub-title: #000;
817
+ }
818
+ :root.dark-theme {
819
+ --vm-context-title: #adbbc4;
820
+ --vm-context-sub-title: #adbbc4;
821
+ }
822
+ </style>