bfg-common 1.0.16 → 1.0.18

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 (28) hide show
  1. package/components/common/adapterManager/AdapterManager.vue +9 -9
  2. package/components/common/adapterManager/ui/table/Table.vue +2 -2
  3. package/components/common/addNetworking/AddNetworking.vue +2 -2
  4. package/components/common/addNetworking/config/sendData.ts +1 -1
  5. package/components/common/addNetworking/mappers/mappers.ts +1 -1
  6. package/components/common/diagramMain/DiagramMain.vue +2 -2
  7. package/components/common/diagramMain/config/initial.ts +1 -1
  8. package/components/common/diagramMain/modals/ManagePhysicalAdaptersModal.vue +236 -236
  9. package/components/common/diagramMain/modals/config/initial.ts +31 -45
  10. package/components/common/diagramMain/modals/editSettings/EditSettings.vue +6 -5
  11. package/components/common/diagramMain/modals/editSettings/tabs/Security.vue +183 -178
  12. package/components/common/diagramMain/modals/editSettings/tabs/TeamingFailover.vue +2 -1
  13. package/components/common/diagramMain/modals/editSettings/tabs/TrafficShaping.vue +393 -392
  14. package/components/common/diagramMain/models/interfaces.ts +53 -74
  15. package/components/common/diagramMain/models/types.ts +1 -1
  16. package/components/common/monitor/models/interfaces.ts +1 -0
  17. package/components/common/vm/actions/add/customizeHardware/virtualHardware/cpu/Cpu.vue +371 -371
  18. package/components/common/vm/actions/add/customizeHardware/virtualHardware/cpu/MaxCpu.vue +105 -105
  19. package/components/common/vm/actions/add/customizeHardware/virtualHardware/cpu/Sa.vue +102 -102
  20. package/components/common/vm/actions/add/customizeHardware/virtualHardware/cpu/shares/Shares.vue +155 -155
  21. package/components/common/vm/actions/add/customizeHardware/virtualHardware/limit/Limit.vue +214 -214
  22. package/components/common/vm/actions/add/customizeHardware/virtualHardware/memory/Memory.vue +282 -282
  23. package/components/common/vm/actions/add/customizeHardware/virtualHardware/newHardDisk/NewHardDisk.vue +451 -451
  24. package/components/common/vm/actions/add/customizeHardware/virtualHardware/newHardDisk/limitIops/LimitIops.vue +151 -151
  25. package/components/common/vm/actions/add/customizeHardware/vmoptions/remoteConsoleOptions/RemoteConsoleOptions.vue +230 -230
  26. package/components/common/vm/actions/add/select/compatibility/Compatibility.vue +151 -151
  27. package/package.json +1 -1
  28. package/public/spice-console/network/spicechannel.js +1 -1
@@ -1,451 +1,451 @@
1
- <template>
2
- <div class="hardware-cpu">
3
- <atoms-stack-block
4
- :has-children="true"
5
- :is-roll-back="props.type === 'removed'"
6
- :removable="isRemovable"
7
- @remove="onRemoveHardDisk"
8
- @roll-back="onRollBackHardDisk"
9
- >
10
- <template #stackBlockKey>
11
- <div class="vm-wizard-toggle-block-hard-disk flex-align-center">
12
- <span>{{ label }}</span>
13
- <atoms-the-icon
14
- v-show="hardDiskInvalid"
15
- width="24px"
16
- height="24px"
17
- class="is-error tooltip-trigger"
18
- name="info"
19
- />
20
- </div>
21
- </template>
22
- <template #stackBlockContent>
23
- <div class="flex-align-center flex-space-between mr-1">
24
- <template v-if="props.type === 'removed'">
25
- <span>{{ localization.deviceWillRemoved }}</span>
26
- <div class="flex-align-center">
27
- <input
28
- id="delete-files-from-datastore"
29
- v-model="deleteFilesFromDatastore"
30
- :disabled="props.disabled"
31
- type="checkbox"
32
- class="pointer"
33
- @click.stop
34
- />
35
- <label
36
- for="delete-files-from-datastore"
37
- :class="[
38
- 'label-text-normal pointer',
39
- props.disabled && 'div-disabled',
40
- ]"
41
- >{{ localization.deleteFilesFromDatastore }}</label
42
- >
43
- </div>
44
- </template>
45
- <template v-else>
46
- <atoms-tooltip-error
47
- :has-error="!!hardDiskLocalAndApiErrorsTexts"
48
- :selector="`#vm-wizard-hard-disk-${props.index}`"
49
- @remove="
50
- emits(
51
- 'remove-error-by-title',
52
- `disk_devices[${props.index}].size`
53
- )
54
- "
55
- >
56
- <template #elem>
57
- <input
58
- :id="`vm-wizard-hard-disk-${props.index}`"
59
- v-model.number="size"
60
- type="number"
61
- :class="[
62
- 'spinfree edit-setting-input',
63
- { 'has-error': hardDiskTypeErrorLocalText },
64
- ]"
65
- :disabled="isDisabledSize"
66
- @blur="onValidateSize"
67
- @click.stop
68
- />
69
- </template>
70
- <template #content>
71
- {{ hardDiskLocalAndApiErrorsTexts }}
72
- </template>
73
- </atoms-tooltip-error>
74
- <div class="select ml-1">
75
- <select
76
- :id="`hard-disk-type-select-${props.index}`"
77
- v-model="hardDiskType"
78
- :disabled="props.type === 'exist'"
79
- @change="onValidateSize"
80
- @click.stop
81
- >
82
- <option
83
- v-for="(item, key) in hardDiskTypeOptions"
84
- :key="key"
85
- :value="item.value"
86
- >
87
- {{ item.text }}
88
- </option>
89
- </select>
90
- </div>
91
- </template>
92
- </div>
93
- </template>
94
- <template #stackChildren>
95
- <common-vm-actions-add-customize-hardware-virtual-hardware-new-hard-disk-maximum-size
96
- :free-mb="maxHardDisk"
97
- />
98
- <common-vm-actions-add-customize-hardware-virtual-hardware-new-hard-disk-location
99
- v-if="props.type === 'new'"
100
- :location="location"
101
- :index="props.index"
102
- :error-validation-fields="props.errorValidationFields"
103
- :get-datastore-table-func="props.getDatastoreTableFunc"
104
- :datastore="props.datastore"
105
- @change="onChangeStorage"
106
- @remove-error-by-title="emits('remove-error-by-title', $event)"
107
- />
108
- <common-vm-actions-add-customize-hardware-virtual-hardware-new-hard-disk-file
109
- v-else
110
- :path="props.hardDisk?.source"
111
- />
112
- <common-vm-actions-add-customize-hardware-virtual-hardware-new-hard-disk-provisioning
113
- v-model:disk-provisioning="diskProvisioning"
114
- :index="props.index"
115
- :error-validation-fields="props.errorValidationFields"
116
- :disabled="(props.isEdit && props.type !== 'new') || isRunning"
117
- @remove-error-by-title="emits('remove-error-by-title', $event)"
118
- />
119
- <common-vm-actions-add-customize-hardware-virtual-hardware-new-hard-disk-sharing
120
- v-model:sharing="sharing"
121
- :index="props.index"
122
- :error-validation-fields="props.errorValidationFields"
123
- :disabled="isRunning && props.type !== 'new'"
124
- @remove-error-by-title="emits('remove-error-by-title', $event)"
125
- />
126
- <common-vm-actions-add-customize-hardware-virtual-hardware-new-hard-disk-limit-iops
127
- v-model:limit-iops="limitIops"
128
- v-model:limit-iops-type="limitIopsType"
129
- :index="props.index"
130
- :error-validation-fields="props.errorValidationFields"
131
- @valid="limitIopsInvalid = $event"
132
- @remove-error-by-title="emits('remove-error-by-title', $event)"
133
- />
134
- <common-vm-actions-add-customize-hardware-virtual-hardware-new-hard-disk-mode
135
- v-model:diskMode="diskMode"
136
- :index="props.index"
137
- :error-validation-fields="props.errorValidationFields"
138
- :disabled="isRunning && props.type !== 'new'"
139
- @remove-error-by-title="emits('remove-error-by-title', $event)"
140
- />
141
- <common-vm-actions-add-customize-hardware-virtual-hardware-new-hard-disk-cache
142
- v-model:cache="cache"
143
- :index="props.index"
144
- :error-validation-fields="props.errorValidationFields"
145
- :disabled="(props.isEdit && props.type !== 'new') || isRunning"
146
- @remove-error-by-title="emits('remove-error-by-title', $event)"
147
- />
148
- <common-vm-actions-add-customize-hardware-virtual-hardware-bus
149
- v-model:bus="bus"
150
- :index="props.index"
151
- :error-validation-fields="props.errorValidationFields"
152
- :disabled="isRunning"
153
- component-type="disk_devices"
154
- @remove-error-by-title="emits('remove-error-by-title', $event)"
155
- />
156
- </template>
157
- </atoms-stack-block>
158
- </div>
159
- </template>
160
-
161
- <script setup lang="ts">
162
- import { UI_I_DatastoreTableItem } from '~/models/store/storage/interfaces'
163
- import {
164
- UI_I_SendDataNewHardDisk,
165
- UI_I_SendDataNewHardDiskStorage,
166
- } from '~/components/common/vm/actions/add/customizeHardware/virtualHardware/models/interfaces'
167
- import { UI_T_HardDiskType } from '~/components/common/vm/actions/add/customizeHardware/virtualHardware/models/types'
168
- import { UI_I_Localization } from '~/models/interfaces'
169
- import {
170
- UI_I_ErrorValidationField,
171
- UI_I_TablePayload,
172
- } from '~/models/store/interfaces'
173
- import { UI_I_OptionItem } from '~/components/atoms/models/interfaces'
174
- import { binaryOptionsFunc } from '~/components/common/vm/actions/add/customizeHardware/virtualHardware/config/binaryOptions'
175
-
176
- const props = defineProps<{
177
- storage: UI_I_DatastoreTableItem | null
178
- hardDisk: UI_I_SendDataNewHardDisk
179
- type: UI_T_HardDiskType
180
- index: number
181
- errorValidationFields: UI_I_ErrorValidationField<string>[]
182
- getDatastoreTableFunc: (payload: UI_I_TablePayload) => Promise<void>
183
- datastore: UI_I_DatastoreTableItem[]
184
- isEdit: boolean
185
- state?: string
186
- }>()
187
- const emits = defineEmits<{
188
- (event: 'send-data', value: UI_I_SendDataNewHardDisk): void
189
- (event: 'invalid', value: boolean): void
190
- (event: 'remove'): void
191
- (event: 'roll-back'): void
192
- (event: 'remove-error-by-title', value: string): void
193
- }>()
194
-
195
- const localization = computed<UI_I_Localization>(() => useLocal())
196
-
197
- const isRunning = computed<boolean>(() => {
198
- return props.state === '1'
199
- })
200
-
201
- const isRemovable = computed<boolean>(() => {
202
- return (
203
- !props.isEdit ||
204
- !isRunning.value ||
205
- (isRunning.value && bus.value === 'virtio')
206
- )
207
- })
208
-
209
- const typeError = computed<string>(() => `disk_devices[${props.index}].size`)
210
-
211
- const apiErrorLocal = computed<string>(() => {
212
- return (
213
- props.errorValidationFields?.find(
214
- (message) => message.field === typeError.value
215
- )?.error_message || ''
216
- )
217
- })
218
-
219
- const { $binary } = useNuxtApp()
220
-
221
- const label = computed<string>(() => {
222
- if (props.type === 'edit' || props.type === 'removed')
223
- return `${localization.value.hardDisk} ${props.index + 1}`
224
-
225
- return `${localization.value.newHardDisk} *`
226
- })
227
-
228
- const maxHardDisk = computed<number>(() => {
229
- if (props.type === 'exist') return $binary.gbToMb(props.hardDisk.size)
230
-
231
- if (!storage.value) return 0
232
-
233
- return storage.value.capacity.free_mb
234
- })
235
- const hardDiskTypeErrorLocalText = computed<string>(() => {
236
- if (
237
- +sizeInMb.value >
238
- maxHardDisk.value + (props.isEdit ? firstSizeInMb : 0)
239
- ) {
240
- return localization.value.diskCapacitySpecifiedGreater
241
- }
242
-
243
- if (+sizeInMb.value <= 0) {
244
- return localization.value.diskCapacityCannotZero
245
- }
246
-
247
- return ''
248
- })
249
-
250
- const hardDiskLocalAndApiErrorsTexts = computed<string>(() => {
251
- const localError = hardDiskTypeErrorLocalText.value
252
- const apiError = apiErrorLocal.value
253
-
254
- let result = ''
255
- if (localError && !apiError) result = localError
256
- if (!localError && apiError) result = apiError
257
- if (localError && apiError) result = localError + ', ' + apiError
258
- if (!localError && apiError) result = apiError
259
-
260
- return result
261
- })
262
-
263
- const deleteFilesFromDatastore = ref<boolean>(false)
264
-
265
- const hardDiskType = ref<string>('gb')
266
- const hardDiskTypeOptions = ref<UI_I_OptionItem[]>(
267
- binaryOptionsFunc(localization.value)
268
- )
269
-
270
- const size = ref<number>(props.hardDisk.size) // Изначально всегда приходит в gb
271
- const sizeInMb = computed<number>(() => {
272
- if (hardDiskType.value === 'mb') {
273
- return size.value
274
- }
275
-
276
- return $binary.universalFromTo(size.value, hardDiskType.value, 'mb')
277
- })
278
- let firstSizeInMb = 0
279
- watch(
280
- sizeInMb,
281
- (newValue) => {
282
- firstSizeInMb = firstSizeInMb || newValue
283
- },
284
- { immediate: true }
285
- )
286
- const onValidateSize = (): void => {
287
- if (props.type !== 'edit') return
288
- if (sizeInMb.value < $binary.gbToMb(props.hardDisk.size)) {
289
- size.value = $binary.universalFromTo(
290
- props.hardDisk.size,
291
- 'gb',
292
- hardDiskType.value
293
- )
294
- }
295
- }
296
-
297
- const isDisabledSize = computed<boolean>(() => {
298
- return props.type === 'exist' || (props.type === 'edit' && readOnly.value)
299
- })
300
-
301
- const onRemoveHardDisk = (): void => {
302
- emits('remove')
303
- }
304
- const onRollBackHardDisk = (): void => {
305
- emits('roll-back')
306
- }
307
-
308
- const location = ref<UI_I_DatastoreTableItem | null>(props.storage || null)
309
- watch(
310
- () => props.storage,
311
- (newValue) => {
312
- location.value = newValue
313
- storage.value = newValue
314
- }
315
- )
316
- const storage = ref<UI_I_DatastoreTableItem | null>(props.storage)
317
- const onChangeStorage = (item: UI_I_DatastoreTableItem): void => {
318
- storage.value = item
319
- }
320
-
321
- const diskProvisioning = ref<string>('thick')
322
- const sharing = ref<string>('')
323
- const shares = ref<number>(0)
324
-
325
- const limitIops = ref<number>(16)
326
- const limitIopsType = ref<string>('unlimited')
327
- const limitIopsInvalid = ref<boolean>(false)
328
-
329
- const diskMode = ref<string>('dependent')
330
-
331
- const cache = ref<string>('none')
332
-
333
- const bus = ref<string>('ide')
334
-
335
- const readOnly = ref<boolean>(false)
336
-
337
- const discard = ref<string>('')
338
-
339
- const io = ref<string>('')
340
-
341
- const target = ref<string>('')
342
-
343
- watch(
344
- [
345
- sizeInMb,
346
- storage,
347
- diskProvisioning,
348
- sharing,
349
- limitIops,
350
- limitIopsType,
351
- diskMode,
352
- cache,
353
- bus,
354
- () => props.type,
355
- ],
356
- () => {
357
- const limitIopsLocal =
358
- limitIopsType.value === 'unlimited' ? 0 : limitIops.value
359
- const storageLocal: UI_I_SendDataNewHardDiskStorage = {
360
- id: storage.value?.id || '',
361
- name: storage.value?.name || '',
362
- type: storage.value?.type_text || '',
363
- pool: storage.value?.pool_name || '',
364
- user: '',
365
- endpoint: '',
366
- password: '',
367
- protocol: '',
368
- options: '',
369
- }
370
-
371
- emits('send-data', {
372
- create: props.hardDisk.create,
373
- source: props.hardDisk.source,
374
- size: sizeInMb.value,
375
- bus: bus.value,
376
- target: target.value,
377
- storage: storageLocal,
378
- device_type: 'disk',
379
- provision_type: diskProvisioning.value,
380
- disk_mode: diskMode.value,
381
- sharing: sharing.value === 'yes',
382
- read_only: readOnly.value,
383
- shares: shares.value,
384
- cache: cache.value,
385
- io: io.value,
386
- limit_iops: limitIopsLocal,
387
- discard: discard.value,
388
- capacity: sizeInMb.value,
389
- boot_order: -1,
390
- detach: props.type === 'removed' && !deleteFilesFromDatastore.value, // Проверяем если удалили диск но не указали Delete files from datastore
391
- remove: props.type === 'removed' && deleteFilesFromDatastore.value, // Проверяем если удалили диск и указали Delete files from datastore
392
- })
393
- },
394
- { immediate: true }
395
- )
396
-
397
- // Добавляем данные для редактирования
398
- watch(
399
- () => props.hardDisk,
400
- (newValue) => {
401
- if (props.type !== 'edit') return
402
-
403
- diskProvisioning.value = newValue.provision_type || 'thick'
404
- sharing.value = newValue.sharing ? 'yes' : ''
405
- shares.value = newValue.shares || 0
406
- limitIopsType.value = newValue.io === 'native' ? 'unlimited' : 'custom'
407
- limitIops.value = newValue.limit_iops || 16
408
- diskMode.value = newValue.disk_mode || 'dependent'
409
- cache.value = newValue.cache || 'none'
410
- bus.value = newValue.bus || 'ide'
411
- readOnly.value = newValue.read_only || false
412
- discard.value = newValue.discard || ''
413
- io.value = newValue.io || ''
414
- target.value = newValue.target || ''
415
- },
416
- { immediate: true }
417
- )
418
- watch(
419
- isRunning,
420
- (newValue) => {
421
- if (newValue && props.type === 'new') {
422
- bus.value = 'virtio'
423
- }
424
- },
425
- { immediate: true }
426
- )
427
-
428
- const hardDiskInvalid = computed<boolean>(() => {
429
- return !!hardDiskTypeErrorLocalText.value || limitIopsInvalid.value
430
- })
431
- watch(
432
- hardDiskInvalid,
433
- (newValue) => {
434
- emits('invalid', newValue)
435
- },
436
- { immediate: true }
437
- )
438
- </script>
439
-
440
- <style scoped lang="scss">
441
- .hardware-cpu {
442
- #hard-disk {
443
- width: 100px;
444
- -webkit-appearance: none;
445
-
446
- &.has-error {
447
- border: 1px solid #db2100;
448
- }
449
- }
450
- }
451
- </style>
1
+ <template>
2
+ <div class="hardware-cpu">
3
+ <atoms-stack-block
4
+ :has-children="true"
5
+ :is-roll-back="props.type === 'removed'"
6
+ :removable="isRemovable"
7
+ @remove="onRemoveHardDisk"
8
+ @roll-back="onRollBackHardDisk"
9
+ >
10
+ <template #stackBlockKey>
11
+ <div class="vm-wizard-toggle-block-hard-disk flex-align-center">
12
+ <span>{{ label }}</span>
13
+ <atoms-the-icon
14
+ v-show="hardDiskInvalid"
15
+ width="24px"
16
+ height="24px"
17
+ class="is-error tooltip-trigger"
18
+ name="info"
19
+ />
20
+ </div>
21
+ </template>
22
+ <template #stackBlockContent>
23
+ <div class="flex-align-center flex-space-between mr-1">
24
+ <template v-if="props.type === 'removed'">
25
+ <span>{{ localization.deviceWillRemoved }}</span>
26
+ <div class="flex-align-center">
27
+ <input
28
+ id="delete-files-from-datastore"
29
+ v-model="deleteFilesFromDatastore"
30
+ :disabled="props.disabled"
31
+ type="checkbox"
32
+ class="pointer"
33
+ @click.stop
34
+ />
35
+ <label
36
+ for="delete-files-from-datastore"
37
+ :class="[
38
+ 'label-text-normal pointer',
39
+ props.disabled && 'div-disabled',
40
+ ]"
41
+ >{{ localization.deleteFilesFromDatastore }}</label
42
+ >
43
+ </div>
44
+ </template>
45
+ <template v-else>
46
+ <atoms-tooltip-error
47
+ :has-error="!!hardDiskLocalAndApiErrorsTexts"
48
+ :selector="`#vm-wizard-hard-disk-${props.index}`"
49
+ @remove="
50
+ emits(
51
+ 'remove-error-by-title',
52
+ `disk_devices[${props.index}].size`
53
+ )
54
+ "
55
+ >
56
+ <template #elem>
57
+ <input
58
+ :id="`vm-wizard-hard-disk-${props.index}`"
59
+ v-model.number="size"
60
+ type="number"
61
+ :class="[
62
+ 'spinfree edit-setting-input',
63
+ { 'has-error': hardDiskTypeErrorLocalText },
64
+ ]"
65
+ :disabled="isDisabledSize"
66
+ @blur="onValidateSize"
67
+ @click.stop
68
+ />
69
+ </template>
70
+ <template #content>
71
+ {{ hardDiskLocalAndApiErrorsTexts }}
72
+ </template>
73
+ </atoms-tooltip-error>
74
+ <div class="select ml-1">
75
+ <select
76
+ :id="`hard-disk-type-select-${props.index}`"
77
+ v-model="hardDiskType"
78
+ :disabled="props.type === 'exist'"
79
+ @change="onValidateSize"
80
+ @click.stop
81
+ >
82
+ <option
83
+ v-for="(item, key) in hardDiskTypeOptions"
84
+ :key="key"
85
+ :value="item.value"
86
+ >
87
+ {{ item.text }}
88
+ </option>
89
+ </select>
90
+ </div>
91
+ </template>
92
+ </div>
93
+ </template>
94
+ <template #stackChildren>
95
+ <common-vm-actions-add-customize-hardware-virtual-hardware-new-hard-disk-maximum-size
96
+ :free-mb="maxHardDisk"
97
+ />
98
+ <common-vm-actions-add-customize-hardware-virtual-hardware-new-hard-disk-location
99
+ v-if="props.type === 'new'"
100
+ :location="location"
101
+ :index="props.index"
102
+ :error-validation-fields="props.errorValidationFields"
103
+ :get-datastore-table-func="props.getDatastoreTableFunc"
104
+ :datastore="props.datastore"
105
+ @change="onChangeStorage"
106
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
107
+ />
108
+ <common-vm-actions-add-customize-hardware-virtual-hardware-new-hard-disk-file
109
+ v-else
110
+ :path="props.hardDisk?.source"
111
+ />
112
+ <common-vm-actions-add-customize-hardware-virtual-hardware-new-hard-disk-provisioning
113
+ v-model:disk-provisioning="diskProvisioning"
114
+ :index="props.index"
115
+ :error-validation-fields="props.errorValidationFields"
116
+ :disabled="(props.isEdit && props.type !== 'new') || isRunning"
117
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
118
+ />
119
+ <common-vm-actions-add-customize-hardware-virtual-hardware-new-hard-disk-sharing
120
+ v-model:sharing="sharing"
121
+ :index="props.index"
122
+ :error-validation-fields="props.errorValidationFields"
123
+ :disabled="isRunning && props.type !== 'new'"
124
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
125
+ />
126
+ <common-vm-actions-add-customize-hardware-virtual-hardware-new-hard-disk-limit-iops
127
+ v-model:limit-iops="limitIops"
128
+ v-model:limit-iops-type="limitIopsType"
129
+ :index="props.index"
130
+ :error-validation-fields="props.errorValidationFields"
131
+ @valid="limitIopsInvalid = $event"
132
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
133
+ />
134
+ <common-vm-actions-add-customize-hardware-virtual-hardware-new-hard-disk-mode
135
+ v-model:diskMode="diskMode"
136
+ :index="props.index"
137
+ :error-validation-fields="props.errorValidationFields"
138
+ :disabled="isRunning && props.type !== 'new'"
139
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
140
+ />
141
+ <common-vm-actions-add-customize-hardware-virtual-hardware-new-hard-disk-cache
142
+ v-model:cache="cache"
143
+ :index="props.index"
144
+ :error-validation-fields="props.errorValidationFields"
145
+ :disabled="(props.isEdit && props.type !== 'new') || isRunning"
146
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
147
+ />
148
+ <common-vm-actions-add-customize-hardware-virtual-hardware-bus
149
+ v-model:bus="bus"
150
+ :index="props.index"
151
+ :error-validation-fields="props.errorValidationFields"
152
+ :disabled="isRunning"
153
+ component-type="disk_devices"
154
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
155
+ />
156
+ </template>
157
+ </atoms-stack-block>
158
+ </div>
159
+ </template>
160
+
161
+ <script setup lang="ts">
162
+ import { UI_I_DatastoreTableItem } from '~/models/store/storage/interfaces'
163
+ import {
164
+ UI_I_SendDataNewHardDisk,
165
+ UI_I_SendDataNewHardDiskStorage,
166
+ } from '~/components/common/vm/actions/add/customizeHardware/virtualHardware/models/interfaces'
167
+ import { UI_T_HardDiskType } from '~/components/common/vm/actions/add/customizeHardware/virtualHardware/models/types'
168
+ import { UI_I_Localization } from '~/models/interfaces'
169
+ import {
170
+ UI_I_ErrorValidationField,
171
+ UI_I_TablePayload,
172
+ } from '~/models/store/interfaces'
173
+ import { UI_I_OptionItem } from '~/components/atoms/models/interfaces'
174
+ import { binaryOptionsFunc } from '~/components/common/vm/actions/add/customizeHardware/virtualHardware/config/binaryOptions'
175
+
176
+ const props = defineProps<{
177
+ storage: UI_I_DatastoreTableItem | null
178
+ hardDisk: UI_I_SendDataNewHardDisk
179
+ type: UI_T_HardDiskType
180
+ index: number
181
+ errorValidationFields: UI_I_ErrorValidationField<string>[]
182
+ getDatastoreTableFunc: (payload: UI_I_TablePayload) => Promise<void>
183
+ datastore: UI_I_DatastoreTableItem[]
184
+ isEdit: boolean
185
+ state?: string
186
+ }>()
187
+ const emits = defineEmits<{
188
+ (event: 'send-data', value: UI_I_SendDataNewHardDisk): void
189
+ (event: 'invalid', value: boolean): void
190
+ (event: 'remove'): void
191
+ (event: 'roll-back'): void
192
+ (event: 'remove-error-by-title', value: string): void
193
+ }>()
194
+
195
+ const localization = computed<UI_I_Localization>(() => useLocal())
196
+
197
+ const isRunning = computed<boolean>(() => {
198
+ return props.state === '1'
199
+ })
200
+
201
+ const isRemovable = computed<boolean>(() => {
202
+ return (
203
+ !props.isEdit ||
204
+ !isRunning.value ||
205
+ (isRunning.value && bus.value === 'virtio')
206
+ )
207
+ })
208
+
209
+ const typeError = computed<string>(() => `disk_devices[${props.index}].size`)
210
+
211
+ const apiErrorLocal = computed<string>(() => {
212
+ return (
213
+ props.errorValidationFields?.find(
214
+ (message) => message.field === typeError.value
215
+ )?.error_message || ''
216
+ )
217
+ })
218
+
219
+ const { $binary } = useNuxtApp()
220
+
221
+ const label = computed<string>(() => {
222
+ if (props.type === 'edit' || props.type === 'removed')
223
+ return `${localization.value.hardDisk} ${props.index + 1}`
224
+
225
+ return `${localization.value.newHardDisk} *`
226
+ })
227
+
228
+ const maxHardDisk = computed<number>(() => {
229
+ if (props.type === 'exist') return $binary.gbToMb(props.hardDisk.size)
230
+
231
+ if (!storage.value) return 0
232
+
233
+ return storage.value.capacity.free_mb
234
+ })
235
+ const hardDiskTypeErrorLocalText = computed<string>(() => {
236
+ if (
237
+ +sizeInMb.value >
238
+ maxHardDisk.value + (props.isEdit ? firstSizeInMb : 0)
239
+ ) {
240
+ return localization.value.diskCapacitySpecifiedGreater
241
+ }
242
+
243
+ if (+sizeInMb.value <= 0) {
244
+ return localization.value.diskCapacityCannotZero
245
+ }
246
+
247
+ return ''
248
+ })
249
+
250
+ const hardDiskLocalAndApiErrorsTexts = computed<string>(() => {
251
+ const localError = hardDiskTypeErrorLocalText.value
252
+ const apiError = apiErrorLocal.value
253
+
254
+ let result = ''
255
+ if (localError && !apiError) result = localError
256
+ if (!localError && apiError) result = apiError
257
+ if (localError && apiError) result = localError + ', ' + apiError
258
+ if (!localError && apiError) result = apiError
259
+
260
+ return result
261
+ })
262
+
263
+ const deleteFilesFromDatastore = ref<boolean>(false)
264
+
265
+ const hardDiskType = ref<string>('gb')
266
+ const hardDiskTypeOptions = ref<UI_I_OptionItem[]>(
267
+ binaryOptionsFunc(localization.value)
268
+ )
269
+
270
+ const size = ref<number>(props.hardDisk.size) // Изначально всегда приходит в gb
271
+ const sizeInMb = computed<number>(() => {
272
+ if (hardDiskType.value === 'mb') {
273
+ return size.value
274
+ }
275
+
276
+ return $binary.universalFromTo(size.value, hardDiskType.value, 'mb')
277
+ })
278
+ let firstSizeInMb = 0
279
+ watch(
280
+ sizeInMb,
281
+ (newValue) => {
282
+ firstSizeInMb = firstSizeInMb || newValue
283
+ },
284
+ { immediate: true }
285
+ )
286
+ const onValidateSize = (): void => {
287
+ if (props.type !== 'edit') return
288
+ if (sizeInMb.value < $binary.gbToMb(props.hardDisk.size)) {
289
+ size.value = $binary.universalFromTo(
290
+ props.hardDisk.size,
291
+ 'gb',
292
+ hardDiskType.value
293
+ )
294
+ }
295
+ }
296
+
297
+ const isDisabledSize = computed<boolean>(() => {
298
+ return props.type === 'exist' || (props.type === 'edit' && readOnly.value)
299
+ })
300
+
301
+ const onRemoveHardDisk = (): void => {
302
+ emits('remove')
303
+ }
304
+ const onRollBackHardDisk = (): void => {
305
+ emits('roll-back')
306
+ }
307
+
308
+ const location = ref<UI_I_DatastoreTableItem | null>(props.storage || null)
309
+ watch(
310
+ () => props.storage,
311
+ (newValue) => {
312
+ location.value = newValue
313
+ storage.value = newValue
314
+ }
315
+ )
316
+ const storage = ref<UI_I_DatastoreTableItem | null>(props.storage)
317
+ const onChangeStorage = (item: UI_I_DatastoreTableItem): void => {
318
+ storage.value = item
319
+ }
320
+
321
+ const diskProvisioning = ref<string>('thick')
322
+ const sharing = ref<string>('')
323
+ const shares = ref<number>(0)
324
+
325
+ const limitIops = ref<number>(16)
326
+ const limitIopsType = ref<string>('unlimited')
327
+ const limitIopsInvalid = ref<boolean>(false)
328
+
329
+ const diskMode = ref<string>('dependent')
330
+
331
+ const cache = ref<string>('none')
332
+
333
+ const bus = ref<string>('ide')
334
+
335
+ const readOnly = ref<boolean>(false)
336
+
337
+ const discard = ref<string>('')
338
+
339
+ const io = ref<string>('')
340
+
341
+ const target = ref<string>('')
342
+
343
+ watch(
344
+ [
345
+ sizeInMb,
346
+ storage,
347
+ diskProvisioning,
348
+ sharing,
349
+ limitIops,
350
+ limitIopsType,
351
+ diskMode,
352
+ cache,
353
+ bus,
354
+ () => props.type,
355
+ ],
356
+ () => {
357
+ const limitIopsLocal =
358
+ limitIopsType.value === 'unlimited' ? 0 : limitIops.value
359
+ const storageLocal: UI_I_SendDataNewHardDiskStorage = {
360
+ id: storage.value?.id || '',
361
+ name: storage.value?.name || '',
362
+ type: storage.value?.type_text || '',
363
+ pool: storage.value?.pool_name || '',
364
+ user: '',
365
+ endpoint: '',
366
+ password: '',
367
+ protocol: '',
368
+ options: '',
369
+ }
370
+
371
+ emits('send-data', {
372
+ create: props.hardDisk.create,
373
+ source: props.hardDisk.source,
374
+ size: sizeInMb.value,
375
+ bus: bus.value,
376
+ target: target.value,
377
+ storage: storageLocal,
378
+ device_type: 'disk',
379
+ provision_type: diskProvisioning.value,
380
+ disk_mode: diskMode.value,
381
+ sharing: sharing.value === 'yes',
382
+ read_only: readOnly.value,
383
+ shares: shares.value,
384
+ cache: cache.value,
385
+ io: io.value,
386
+ limit_iops: limitIopsLocal,
387
+ discard: discard.value,
388
+ capacity: sizeInMb.value,
389
+ boot_order: -1,
390
+ detach: props.type === 'removed' && !deleteFilesFromDatastore.value, // Проверяем если удалили диск но не указали Delete files from datastore
391
+ remove: props.type === 'removed' && deleteFilesFromDatastore.value, // Проверяем если удалили диск и указали Delete files from datastore
392
+ })
393
+ },
394
+ { immediate: true }
395
+ )
396
+
397
+ // Добавляем данные для редактирования
398
+ watch(
399
+ () => props.hardDisk,
400
+ (newValue) => {
401
+ if (props.type !== 'edit') return
402
+
403
+ diskProvisioning.value = newValue.provision_type || 'thick'
404
+ sharing.value = newValue.sharing ? 'yes' : ''
405
+ shares.value = newValue.shares || 0
406
+ limitIopsType.value = newValue.io === 'native' ? 'unlimited' : 'custom'
407
+ limitIops.value = newValue.limit_iops || 16
408
+ diskMode.value = newValue.disk_mode || 'dependent'
409
+ cache.value = newValue.cache || 'none'
410
+ bus.value = newValue.bus || 'ide'
411
+ readOnly.value = newValue.read_only || false
412
+ discard.value = newValue.discard || ''
413
+ io.value = newValue.io || ''
414
+ target.value = newValue.target || ''
415
+ },
416
+ { immediate: true }
417
+ )
418
+ watch(
419
+ isRunning,
420
+ (newValue) => {
421
+ if (newValue && props.type === 'new') {
422
+ bus.value = 'virtio'
423
+ }
424
+ },
425
+ { immediate: true }
426
+ )
427
+
428
+ const hardDiskInvalid = computed<boolean>(() => {
429
+ return !!hardDiskTypeErrorLocalText.value || limitIopsInvalid.value
430
+ })
431
+ watch(
432
+ hardDiskInvalid,
433
+ (newValue) => {
434
+ emits('invalid', newValue)
435
+ },
436
+ { immediate: true }
437
+ )
438
+ </script>
439
+
440
+ <style scoped lang="scss">
441
+ .hardware-cpu {
442
+ #hard-disk {
443
+ width: 100px;
444
+ -webkit-appearance: none;
445
+
446
+ &.has-error {
447
+ border: 1px solid #db2100;
448
+ }
449
+ }
450
+ }
451
+ </style>