bfg-common 1.0.14 → 1.0.16

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 (38) hide show
  1. package/components/common/vm/actions/add/Add.vue +1 -1
  2. package/components/common/vm/actions/add/FolderTreeView.vue +1 -1
  3. package/components/common/vm/actions/add/customizeHardware/CustomizeHardware.vue +1 -1
  4. package/components/common/vm/actions/add/customizeHardware/virtualHardware/cpu/CoresPerSocket.vue +1 -1
  5. package/components/common/vm/actions/add/customizeHardware/virtualHardware/cpu/Cpu.vue +371 -368
  6. package/components/common/vm/actions/add/customizeHardware/virtualHardware/cpu/CpuModel.vue +2 -2
  7. package/components/common/vm/actions/add/customizeHardware/virtualHardware/cpu/MaxCpu.vue +105 -99
  8. package/components/common/vm/actions/add/customizeHardware/virtualHardware/cpu/shares/Shares.vue +155 -151
  9. package/components/common/vm/actions/add/customizeHardware/virtualHardware/limit/Limit.vue +214 -210
  10. package/components/common/vm/actions/add/customizeHardware/virtualHardware/memory/Memory.vue +282 -278
  11. package/components/common/vm/actions/add/customizeHardware/virtualHardware/newHardDisk/Location.vue +10 -10
  12. package/components/common/vm/actions/add/customizeHardware/virtualHardware/newHardDisk/NewHardDisk.vue +10 -6
  13. package/components/common/vm/actions/add/customizeHardware/virtualHardware/newHardDisk/cache/Cache.vue +1 -1
  14. package/components/common/vm/actions/add/customizeHardware/virtualHardware/newHardDisk/limitIops/LimitIops.vue +7 -3
  15. package/components/common/vm/actions/add/customizeHardware/virtualHardware/newHardDisk/provisioning/Provisioning.vue +2 -2
  16. package/components/common/vm/actions/add/customizeHardware/virtualHardware/newNetwork/Location.vue +1 -1
  17. package/components/common/vm/actions/add/customizeHardware/virtualHardware/newNetwork/NewNetwork.vue +256 -252
  18. package/components/common/vm/actions/add/customizeHardware/virtualHardware/newNetwork/adapterType/AdapterType.vue +1 -1
  19. package/components/common/vm/actions/add/customizeHardware/virtualHardware/newNetwork/macAddress/MacAddress.vue +6 -6
  20. package/components/common/vm/actions/add/customizeHardware/virtualHardware/newUsbController/NewUsbController.vue +3 -3
  21. package/components/common/vm/actions/add/customizeHardware/virtualHardware/reservation/Reservation.vue +231 -228
  22. package/components/common/vm/actions/add/customizeHardware/virtualHardware/videoCard/TotalVideoMemory.vue +1 -1
  23. package/components/common/vm/actions/add/customizeHardware/virtualHardware/videoCard/VideoCard.vue +173 -169
  24. package/components/common/vm/actions/add/customizeHardware/virtualHardware/videoCard/numberDisplays/NumberDisplays.vue +1 -1
  25. package/components/common/vm/actions/add/customizeHardware/vmoptions/Vmoptions.vue +145 -141
  26. package/components/common/vm/actions/add/customizeHardware/vmoptions/bootOptions/BootOptions.vue +1 -1
  27. package/components/common/vm/actions/add/customizeHardware/vmoptions/bootOptions/firmware/Firmware.vue +1 -1
  28. package/components/common/vm/actions/add/customizeHardware/vmoptions/remoteConsoleOptions/RemoteConsoleOptions.vue +230 -226
  29. package/components/common/vm/actions/add/customizeHardware/vmoptions/remoteConsoleOptions/imgCompression/ImgCompression.vue +1 -1
  30. package/components/common/vm/actions/add/customizeHardware/vmoptions/remoteConsoleOptions/jpegCompression/JpegCompression.vue +1 -1
  31. package/components/common/vm/actions/add/customizeHardware/vmoptions/remoteConsoleOptions/keymap/Keymap.vue +1 -1
  32. package/components/common/vm/actions/add/customizeHardware/vmoptions/remoteConsoleOptions/mouseMode/MouseMode.vue +1 -1
  33. package/components/common/vm/actions/add/customizeHardware/vmoptions/remoteConsoleOptions/streamingMode/StreamingMode.vue +1 -1
  34. package/components/common/vm/actions/add/customizeHardware/vmoptions/remoteConsoleOptions/type/Type.vue +1 -1
  35. package/components/common/vm/actions/add/customizeHardware/vmoptions/remoteConsoleOptions/zlibCompression/ZlibCompression.vue +1 -1
  36. package/components/common/vm/actions/add/select/compatibility/Compatibility.vue +6 -6
  37. package/components/common/vm/actions/add/select/os/os.vue +7 -7
  38. package/package.json +1 -1
@@ -1,368 +1,371 @@
1
- <template>
2
- <div class="hardware-cpu">
3
- <atoms-stack-block :has-children="true">
4
- <template #stackBlockKey>
5
- <div id="vm-wizard-toggle-block-cpu" class="flex-align-center">
6
- <span>{{ localization.cpu }}</span>
7
- <atoms-the-icon
8
- v-show="cpuInvalid"
9
- width="24px"
10
- height="24px"
11
- class="is-error tooltip-trigger"
12
- name="info"
13
- />
14
- </div>
15
- </template>
16
- <template #stackBlockContent>
17
- <div class="flex-align-center flex-space-between">
18
- <div class="flex-align-center">
19
- <atoms-tooltip-error
20
- :has-error="!!vcpusLocalAndApiErrorsTexts"
21
- selector="#vm-wizard-vcpus-field input"
22
- @remove="onRemoveValidationError"
23
- >
24
- <template #elem>
25
- <atoms-combobox
26
- id="vm-wizard-vcpus-field"
27
- v-model.number="selectedCpu"
28
- :items="cpuOptions"
29
- :disabled="isCpuDisabled"
30
- @click.stop
31
- />
32
- </template>
33
- <template #content>{{ vcpusLocalAndApiErrorsTexts }}</template>
34
- </atoms-tooltip-error>
35
- </div>
36
-
37
- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-tooltip
38
- :vm-cpu-help-text-second="props.vmCpuHelpTextSecond"
39
- />
40
- </div>
41
- </template>
42
- <template #stackChildren>
43
- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-cores-per-socket
44
- v-model:selected-core-per-socket="selectedCorePerSocket"
45
- :selected-cpu="selectedCpu"
46
- :cpu-options="cpuOptions"
47
- :is-edit="props.isEdit"
48
- :disabled="isDisabled"
49
- :error-validation-fields="props.errorValidationFields"
50
- @remove-error-by-title="emits('remove-error-by-title', $event)"
51
- />
52
- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-hot-plug
53
- v-model:enable-cpu-hot-add="enableCpuHotAdd"
54
- :disabled="enableCpuHotAddDisabled"
55
- />
56
- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-max-cpu
57
- v-show="enableCpuHotAdd"
58
- v-model:selected-max-cpu.number="selectedMaxCpu"
59
- :cpu-options="maxCpuOptions"
60
- :error-validation-fields="props.errorValidationFields"
61
- :disabled="isDisabled"
62
- @invalid="maxCpuInvalid = $event"
63
- @remove-error-by-title="emits('remove-error-by-title', $event)"
64
- />
65
- <common-vm-actions-add-customize-hardware-virtual-hardware-reservation
66
- v-model:reservation="reservation"
67
- v-model:reservation-type="reservationType"
68
- :error-validation-fields="props.errorValidationFields"
69
- :disabled="isDisabled"
70
- type="mhz"
71
- component-type="cpu"
72
- @invalid="reservationInvalid = $event"
73
- @remove-error-by-title="emits('remove-error-by-title', $event)"
74
- />
75
- <common-vm-actions-add-customize-hardware-virtual-hardware-limit
76
- v-model:limit="limit"
77
- v-model:limit-type="limitType"
78
- :error-validation-fields="props.errorValidationFields"
79
- :disabled="isDisabled"
80
- type="mhz"
81
- component-type="cpu"
82
- @invalid="limitInvalid = $event"
83
- @remove-error-by-title="emits('remove-error-by-title', $event)"
84
- />
85
- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-shares
86
- v-model:shares="shares"
87
- v-model:shares-type="sharesType"
88
- :error-validation-fields="props.errorValidationFields"
89
- :disabled="isDisabled"
90
- @remove-error-by-title="emits('remove-error-by-title', $event)"
91
- @invalid="sharesInvalid = $event"
92
- />
93
- <!-- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-hv-->
94
- <!-- v-model:hardwareVirtualization="hardwareVirtualization"-->
95
- <!-- />-->
96
- <!-- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-pc-->
97
- <!-- v-model:performanceCounters="performanceCounters"-->
98
- <!-- />-->
99
- <!-- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-sa-->
100
- <!-- v-model:schedulingAffinity="schedulingAffinity"-->
101
- <!-- />-->
102
- <!-- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-iommu-->
103
- <!-- v-model:iommu="iommu"-->
104
- <!-- />-->
105
- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-model
106
- v-model:cpu-model="cpuModel"
107
- v-model:passthrough-host-cpu="passthroughHostCpu"
108
- v-model:host-model-cpu="hostModelCpu"
109
- :cpu-models="props.cpuModels"
110
- :is-edit="props.isEdit"
111
- :error-validation-fields="props.errorValidationFields"
112
- :disabled="isDisabled"
113
- @remove-error-by-title="emits('remove-error-by-title', $event)"
114
- />
115
- </template>
116
- </atoms-stack-block>
117
- </div>
118
- </template>
119
-
120
- <script setup lang="ts">
121
- import { UI_I_SendDataCpu } from '~/components/common/vm/actions/add/customizeHardware/virtualHardware/models/interfaces'
122
- import { UI_I_Localization } from '~/models/interfaces'
123
- import { UI_I_ErrorValidationField } from '~/models/store/interfaces'
124
- import { UI_I_OptionItem } from '~/components/atoms/models/interfaces'
125
- import { API_UI_I_VmEditCpu } from '~/models/store/vm/interfaces'
126
- import { cpuOptionsFunc } from '~/components/common/vm/actions/add/customizeHardware/virtualHardware/cpu/config/cpuOptions'
127
-
128
- const props = defineProps<{
129
- maxCpus: number
130
- cpuModels: UI_I_OptionItem[]
131
- isEdit: boolean
132
- errorValidationFields: UI_I_ErrorValidationField<string>[]
133
- vmCpuHelpTextSecond?: string
134
- state?: string
135
- cpu?: API_UI_I_VmEditCpu
136
- }>()
137
- const emits = defineEmits<{
138
- (event: 'send-data', value: UI_I_SendDataCpu): void
139
- (event: 'invalid', value: boolean): void
140
- (event: 'remove-error-by-title', value: string): void
141
- }>()
142
-
143
- const localization = computed<UI_I_Localization>(() => useLocal())
144
-
145
- const isDisabled = computed<boolean>(() => {
146
- return props.state === '1'
147
- })
148
-
149
- const cpuOptions = computed<UI_I_OptionItem[]>(() =>
150
- cpuOptionsFunc(localization.value, 1, props.maxCpus)
151
- )
152
-
153
- const enableCpuHotAdd = ref<boolean>(false)
154
- const enableCpuHotAddDisabled = computed<boolean>(
155
- () => selectedCpu.value >= props.maxCpus || isDisabled.value
156
- )
157
- watch(enableCpuHotAdd, (newValue) => {
158
- if (newValue) return
159
-
160
- maxCpuInvalid.value = false
161
- selectedMaxCpu.value = cpuOptions.value.at(-1)?.value
162
- })
163
-
164
- const selectedCpu = ref<number>(
165
- isDisabled.value && enableCpuHotAdd.value ? props.maxCpus : 2
166
- )
167
- const isCpuDisabled = computed<boolean>(
168
- () => isDisabled.value && !enableCpuHotAdd.value
169
- )
170
- watch(selectedCpu, (newValue) => {
171
- selectedCpu.value = Math.floor(+newValue)
172
- if (!(selectedCpu.value % selectedCorePerSocket.value)) return
173
- selectedCorePerSocket.value = 1
174
- })
175
- const maxCpuOptions = computed<UI_I_OptionItem[]>(() =>
176
- cpuOptionsFunc(localization.value, selectedCpu.value + 1, props.maxCpus)
177
- )
178
- watch(selectedCpu, (newValue) => {
179
- if (newValue >= props.maxCpus) {
180
- enableCpuHotAdd.value = false
181
- }
182
- selectedMaxCpu.value =
183
- selectedMaxCpu.value <= newValue ? newValue + 1 : selectedMaxCpu.value
184
- if (selectedMaxCpu.value > props.maxCpus) selectedMaxCpu.value = props.maxCpus
185
- })
186
- // @ts-ignore
187
- const selectedMaxCpu = ref<number>(cpuOptions.value.at(-1).value)
188
- watch(
189
- () => props.maxCpus,
190
- (newValue) => {
191
- selectedMaxCpu.value = newValue
192
- }
193
- )
194
-
195
- const selectedCorePerSocket = ref<number>(1)
196
-
197
- const cpuErrorLocalText = computed<string>(() => {
198
- const validValue = /^\d+(\.\d+)?$/.test(selectedCpu.value + '')
199
- if (!validValue) {
200
- return localization.value.inputContainsInvalidCharacters
201
- }
202
-
203
- const min = cpuOptions.value[0].value
204
- const max = cpuOptions.value[1].value
205
- if (selectedCpu.value < min || selectedCpu.value > max) {
206
- return localization.value.memoryMustBe
207
- .replace('{0}', min)
208
- .replace('{1}', max)
209
- }
210
-
211
- return ''
212
- })
213
-
214
- const apiVcpusError = computed<string>(() => {
215
- return (
216
- props.errorValidationFields?.find(
217
- (message) => message.field === 'cpu.vcpus'
218
- )?.error_message || ''
219
- )
220
- })
221
-
222
- const vcpusLocalAndApiErrorsTexts = computed<string>(() => {
223
- const localError = cpuErrorLocalText.value
224
- const apiError = apiVcpusError.value
225
-
226
- let result = ''
227
- if (localError && !apiError) result = localError
228
- if (!localError && apiError) result = apiError
229
- if (localError && apiError) result = localError + ', ' + apiError
230
- if (!localError && apiError) result = apiError
231
-
232
- return result
233
- })
234
- const reservationInvalid = ref<boolean>(false)
235
- const limitInvalid = ref<boolean>(false)
236
- const sharesInvalid = ref<boolean>(false)
237
- const maxCpuInvalid = ref<boolean>(false)
238
- const cpuInvalid = computed<boolean>(
239
- () =>
240
- !!cpuErrorLocalText.value ||
241
- reservationInvalid.value ||
242
- limitInvalid.value ||
243
- sharesInvalid.value ||
244
- (selectedCpu.value < props.maxCpus && maxCpuInvalid.value)
245
- )
246
- watch(cpuInvalid, (val: boolean) => {
247
- emits('invalid', val)
248
- })
249
-
250
- const reservation = ref<string>('1')
251
- const reservationType = ref<string>('mhz')
252
-
253
- const limit = ref<string>('Unlimited')
254
- const limitType = ref<string>('mhz')
255
-
256
- const shares = ref<string>('2000')
257
- const sharesType = ref<string>('2000')
258
-
259
- // const hardwareVirtualization = ref<boolean>(false)
260
- //
261
- // const performanceCounters = ref<boolean>(false)
262
- //
263
- // const schedulingAffinity = ref<string>('')
264
- //
265
- // const iommu = ref<boolean>(false)
266
-
267
- const cpuModel = ref<string>(props.cpuModels[0]?.value || '')
268
- watch(
269
- () => props.cpuModels,
270
- (newValue) => {
271
- cpuModel.value = newValue[0].value
272
- }
273
- )
274
- const passthroughHostCpu = ref<boolean>(false)
275
- const hostModelCpu = ref<boolean>(false)
276
-
277
- // const isShowCpuHelp = ref<boolean>(false)
278
-
279
- const { $binary } = useNuxtApp()
280
- watch(
281
- [
282
- reservation,
283
- reservationType,
284
- limit,
285
- shares,
286
- selectedCpu,
287
- selectedMaxCpu,
288
- selectedCorePerSocket,
289
- enableCpuHotAdd,
290
- cpuModel,
291
- passthroughHostCpu,
292
- hostModelCpu,
293
- ],
294
- () => {
295
- const reservationInMhz =
296
- reservationType.value === 'ghz'
297
- ? $binary.ghzToMhz(+reservation.value)
298
- : +reservation.value
299
- const limitInMhz =
300
- limit.value === 'Unlimited'
301
- ? limit.value
302
- : limitType.value === 'ghz'
303
- ? $binary.ghzToMhz(+limit.value)
304
- : +limit.value
305
- const model = passthroughHostCpu.value
306
- ? 'host-passthrough'
307
- : hostModelCpu.value
308
- ? 'host-model'
309
- : cpuModel.value
310
-
311
- emits('send-data', {
312
- model,
313
- vcpus: selectedCpu.value,
314
- max_vcpus: enableCpuHotAdd.value ? selectedMaxCpu.value : 0,
315
- core_per_socket: selectedCorePerSocket.value,
316
- reservation_mhz: reservationInMhz,
317
- limit_mhz: limitInMhz,
318
- shares: +shares.value,
319
- hotplug: enableCpuHotAdd.value,
320
- })
321
- },
322
- {
323
- immediate: true,
324
- }
325
- )
326
-
327
- // Добавляем данные для редактирования
328
- watch(
329
- () => props.cpu,
330
- (newValue) => {
331
- if (!newValue) return
332
-
333
- enableCpuHotAdd.value = newValue.hotplug
334
- selectedCpu.value = newValue.vcpus
335
- selectedMaxCpu.value = newValue.max_vcpus
336
- selectedCorePerSocket.value = newValue.core_per_socket
337
- reservation.value = '' + newValue.reservation_mhz
338
- limit.value = '' + newValue.limit_mhz
339
- shares.value = '' + newValue.shares
340
- cpuModel.value =
341
- props.cpuModels.find((model) => model.text === props.cpu?.model)?.value ||
342
- cpuModel.value
343
- },
344
- { immediate: true }
345
- )
346
-
347
- const onRemoveValidationError = (): void => {
348
- emits('remove-error-by-title', 'cpu.vcpus')
349
- }
350
- </script>
351
-
352
- <style scoped lang="scss">
353
- h3.cpu-help-title {
354
- margin-top: 7px;
355
- font-size: 22px;
356
- color: #565656;
357
- }
358
- p.cpu-help-text {
359
- width: 310px;
360
- margin-top: 24px;
361
- font-size: 14px;
362
- color: #565656;
363
- }
364
- a.cpu-more-info {
365
- color: #00648f;
366
- font-size: 14px;
367
- }
368
- </style>
1
+ <template>
2
+ <div class="hardware-cpu">
3
+ <atoms-stack-block :has-children="true">
4
+ <template #stackBlockKey>
5
+ <div id="vm-wizard-toggle-block-cpu" class="flex-align-center">
6
+ <span>{{ localization.cpu }}</span>
7
+ <atoms-the-icon
8
+ v-show="cpuInvalid"
9
+ width="24px"
10
+ height="24px"
11
+ class="is-error tooltip-trigger"
12
+ name="info"
13
+ />
14
+ </div>
15
+ </template>
16
+ <template #stackBlockContent>
17
+ <div class="flex-align-center flex-space-between">
18
+ <div class="flex-align-center">
19
+ <atoms-tooltip-error
20
+ :has-error="!!vcpusLocalAndApiErrorsTexts"
21
+ selector="#vm-wizard-vcpus-field input"
22
+ @remove="onRemoveValidationError"
23
+ >
24
+ <template #elem>
25
+ <atoms-combobox
26
+ id="vm-wizard-vcpus-field"
27
+ v-model.number="selectedCpu"
28
+ :items="cpuOptions"
29
+ :disabled="isCpuDisabled"
30
+ @click.stop
31
+ />
32
+ </template>
33
+ <template #content>{{ vcpusLocalAndApiErrorsTexts }}</template>
34
+ </atoms-tooltip-error>
35
+ </div>
36
+
37
+ <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-tooltip
38
+ :vm-cpu-help-text-second="props.vmCpuHelpTextSecond"
39
+ />
40
+ </div>
41
+ </template>
42
+ <template #stackChildren>
43
+ <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-cores-per-socket
44
+ v-model:selected-core-per-socket="selectedCorePerSocket"
45
+ :selected-cpu="selectedCpu"
46
+ :cpu-options="cpuOptions"
47
+ :is-edit="props.isEdit"
48
+ :disabled="isDisabled"
49
+ :error-validation-fields="props.errorValidationFields"
50
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
51
+ />
52
+ <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-hot-plug
53
+ v-model:enable-cpu-hot-add="enableCpuHotAdd"
54
+ :disabled="enableCpuHotAddDisabled"
55
+ />
56
+ <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-max-cpu
57
+ v-show="enableCpuHotAdd"
58
+ v-model:selected-max-cpu.number="selectedMaxCpu"
59
+ :cpu-options="maxCpuOptions"
60
+ :error-validation-fields="props.errorValidationFields"
61
+ :disabled="isDisabled"
62
+ @invalid="maxCpuInvalid = $event"
63
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
64
+ />
65
+ <common-vm-actions-add-customize-hardware-virtual-hardware-reservation
66
+ v-model:reservation="reservation"
67
+ v-model:reservation-type="reservationType"
68
+ :error-validation-fields="props.errorValidationFields"
69
+ :disabled="isDisabled"
70
+ type="mhz"
71
+ component-type="cpu"
72
+ @invalid="reservationInvalid = $event"
73
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
74
+ />
75
+ <common-vm-actions-add-customize-hardware-virtual-hardware-limit
76
+ v-model:limit="limit"
77
+ v-model:limit-type="limitType"
78
+ :error-validation-fields="props.errorValidationFields"
79
+ :disabled="isDisabled"
80
+ type="mhz"
81
+ component-type="cpu"
82
+ @invalid="limitInvalid = $event"
83
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
84
+ />
85
+ <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-shares
86
+ v-model:shares="shares"
87
+ v-model:shares-type="sharesType"
88
+ :error-validation-fields="props.errorValidationFields"
89
+ :disabled="isDisabled"
90
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
91
+ @invalid="sharesInvalid = $event"
92
+ />
93
+ <!-- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-hv-->
94
+ <!-- v-model:hardwareVirtualization="hardwareVirtualization"-->
95
+ <!-- />-->
96
+ <!-- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-pc-->
97
+ <!-- v-model:performanceCounters="performanceCounters"-->
98
+ <!-- />-->
99
+ <!-- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-sa-->
100
+ <!-- v-model:schedulingAffinity="schedulingAffinity"-->
101
+ <!-- />-->
102
+ <!-- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-iommu-->
103
+ <!-- v-model:iommu="iommu"-->
104
+ <!-- />-->
105
+ <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-model
106
+ v-model:cpu-model="cpuModel"
107
+ v-model:passthrough-host-cpu="passthroughHostCpu"
108
+ v-model:host-model-cpu="hostModelCpu"
109
+ :cpu-models="props.cpuModels"
110
+ :is-edit="props.isEdit"
111
+ :error-validation-fields="props.errorValidationFields"
112
+ :disabled="isDisabled"
113
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
114
+ />
115
+ </template>
116
+ </atoms-stack-block>
117
+ </div>
118
+ </template>
119
+
120
+ <script setup lang="ts">
121
+ import { UI_I_SendDataCpu } from '~/components/common/vm/actions/add/customizeHardware/virtualHardware/models/interfaces'
122
+ import { UI_I_Localization } from '~/models/interfaces'
123
+ import { UI_I_ErrorValidationField } from '~/models/store/interfaces'
124
+ import { UI_I_OptionItem } from '~/components/atoms/models/interfaces'
125
+ import { API_UI_I_VmEditCpu } from '~/models/store/vm/interfaces'
126
+ import { cpuOptionsFunc } from '~/components/common/vm/actions/add/customizeHardware/virtualHardware/cpu/config/cpuOptions'
127
+
128
+ const props = defineProps<{
129
+ maxCpus: number
130
+ cpuModels: UI_I_OptionItem[]
131
+ isEdit: boolean
132
+ errorValidationFields: UI_I_ErrorValidationField<string>[]
133
+ vmCpuHelpTextSecond?: string
134
+ state?: string
135
+ cpu?: API_UI_I_VmEditCpu
136
+ }>()
137
+ const emits = defineEmits<{
138
+ (event: 'send-data', value: UI_I_SendDataCpu): void
139
+ (event: 'invalid', value: boolean): void
140
+ (event: 'remove-error-by-title', value: string): void
141
+ }>()
142
+
143
+ const localization = computed<UI_I_Localization>(() => useLocal())
144
+
145
+ const isDisabled = computed<boolean>(() => {
146
+ return props.state === '1'
147
+ })
148
+
149
+ const cpuOptions = computed<UI_I_OptionItem[]>(() =>
150
+ cpuOptionsFunc(localization.value, 1, props.maxCpus)
151
+ )
152
+
153
+ const enableCpuHotAdd = ref<boolean>(false)
154
+ const enableCpuHotAddDisabled = computed<boolean>(
155
+ () => selectedCpu.value >= props.maxCpus || isDisabled.value
156
+ )
157
+ watch(enableCpuHotAdd, (newValue) => {
158
+ if (newValue) return
159
+
160
+ maxCpuInvalid.value = false
161
+ selectedMaxCpu.value = cpuOptions.value.at(-1)?.value
162
+ })
163
+
164
+ const selectedCpu = ref<number>(
165
+ isDisabled.value && enableCpuHotAdd.value ? props.maxCpus : 2
166
+ )
167
+ const isCpuDisabled = computed<boolean>(
168
+ () => isDisabled.value && !enableCpuHotAdd.value
169
+ )
170
+ watch(selectedCpu, (newValue) => {
171
+ selectedCpu.value = Math.floor(+newValue)
172
+ if (!(selectedCpu.value % selectedCorePerSocket.value)) return
173
+ selectedCorePerSocket.value = 1
174
+ })
175
+ const maxCpuOptions = computed<UI_I_OptionItem[]>(() =>
176
+ cpuOptionsFunc(localization.value, selectedCpu.value + 1, props.maxCpus)
177
+ )
178
+ watch(selectedCpu, (newValue) => {
179
+ if (newValue >= props.maxCpus) {
180
+ enableCpuHotAdd.value = false
181
+ }
182
+ selectedMaxCpu.value =
183
+ selectedMaxCpu.value <= newValue ? newValue + 1 : selectedMaxCpu.value
184
+ if (selectedMaxCpu.value > props.maxCpus) selectedMaxCpu.value = props.maxCpus
185
+ })
186
+ const selectedMaxCpu = ref<number>(cpuOptions.value.at(-1)?.value)
187
+ watch(
188
+ () => props.maxCpus,
189
+ (newValue) => {
190
+ selectedMaxCpu.value = newValue
191
+ }
192
+ )
193
+
194
+ const selectedCorePerSocket = ref<number>(1)
195
+
196
+ const cpuErrorLocalText = computed<string>(() => {
197
+ const validValue = /^\d+(\.\d+)?$/.test(selectedCpu.value + '')
198
+ if (!validValue) {
199
+ return localization.value.inputContainsInvalidCharacters
200
+ }
201
+
202
+ const min = cpuOptions.value[0].value
203
+ const max = cpuOptions.value[1].value
204
+ if (selectedCpu.value < min || selectedCpu.value > max) {
205
+ return localization.value.memoryMustBe
206
+ .replace('{0}', min)
207
+ .replace('{1}', max)
208
+ }
209
+
210
+ return ''
211
+ })
212
+
213
+ const apiVcpusError = computed<string>(() => {
214
+ return (
215
+ props.errorValidationFields?.find(
216
+ (message) => message.field === 'cpu.vcpus'
217
+ )?.error_message || ''
218
+ )
219
+ })
220
+
221
+ const vcpusLocalAndApiErrorsTexts = computed<string>(() => {
222
+ const localError = cpuErrorLocalText.value
223
+ const apiError = apiVcpusError.value
224
+
225
+ let result = ''
226
+ if (localError && !apiError) result = localError
227
+ if (!localError && apiError) result = apiError
228
+ if (localError && apiError) result = localError + ', ' + apiError
229
+ if (!localError && apiError) result = apiError
230
+
231
+ return result
232
+ })
233
+ const reservationInvalid = ref<boolean>(false)
234
+ const limitInvalid = ref<boolean>(false)
235
+ const sharesInvalid = ref<boolean>(false)
236
+ const maxCpuInvalid = ref<boolean>(false)
237
+ const cpuInvalid = computed<boolean>(
238
+ () =>
239
+ !!cpuErrorLocalText.value ||
240
+ reservationInvalid.value ||
241
+ limitInvalid.value ||
242
+ sharesInvalid.value ||
243
+ (selectedCpu.value < props.maxCpus && maxCpuInvalid.value)
244
+ )
245
+ watch(
246
+ cpuInvalid,
247
+ (newValue: boolean) => {
248
+ emits('invalid', newValue)
249
+ },
250
+ { immediate: true }
251
+ )
252
+
253
+ const reservation = ref<string>('1')
254
+ const reservationType = ref<string>('mhz')
255
+
256
+ const limit = ref<string>('Unlimited')
257
+ const limitType = ref<string>('mhz')
258
+
259
+ const shares = ref<string>('2000')
260
+ const sharesType = ref<string>('2000')
261
+
262
+ // const hardwareVirtualization = ref<boolean>(false)
263
+ //
264
+ // const performanceCounters = ref<boolean>(false)
265
+ //
266
+ // const schedulingAffinity = ref<string>('')
267
+ //
268
+ // const iommu = ref<boolean>(false)
269
+
270
+ const cpuModel = ref<string>(props.cpuModels[0]?.value || '')
271
+ watch(
272
+ () => props.cpuModels,
273
+ (newValue) => {
274
+ cpuModel.value = newValue[0].value
275
+ }
276
+ )
277
+ const passthroughHostCpu = ref<boolean>(false)
278
+ const hostModelCpu = ref<boolean>(false)
279
+
280
+ // const isShowCpuHelp = ref<boolean>(false)
281
+
282
+ const { $binary } = useNuxtApp()
283
+ watch(
284
+ [
285
+ reservation,
286
+ reservationType,
287
+ limit,
288
+ shares,
289
+ selectedCpu,
290
+ selectedMaxCpu,
291
+ selectedCorePerSocket,
292
+ enableCpuHotAdd,
293
+ cpuModel,
294
+ passthroughHostCpu,
295
+ hostModelCpu,
296
+ ],
297
+ () => {
298
+ const reservationInMhz =
299
+ reservationType.value === 'ghz'
300
+ ? $binary.ghzToMhz(+reservation.value)
301
+ : +reservation.value
302
+ const limitInMhz =
303
+ limit.value === 'Unlimited'
304
+ ? limit.value
305
+ : limitType.value === 'ghz'
306
+ ? $binary.ghzToMhz(+limit.value)
307
+ : +limit.value
308
+ const model = passthroughHostCpu.value
309
+ ? 'host-passthrough'
310
+ : hostModelCpu.value
311
+ ? 'host-model'
312
+ : cpuModel.value
313
+
314
+ emits('send-data', {
315
+ model,
316
+ vcpus: selectedCpu.value,
317
+ max_vcpus: enableCpuHotAdd.value ? selectedMaxCpu.value : 0,
318
+ core_per_socket: selectedCorePerSocket.value,
319
+ reservation_mhz: reservationInMhz,
320
+ limit_mhz: limitInMhz,
321
+ shares: +shares.value,
322
+ hotplug: enableCpuHotAdd.value,
323
+ })
324
+ },
325
+ {
326
+ immediate: true,
327
+ }
328
+ )
329
+
330
+ // Добавляем данные для редактирования
331
+ watch(
332
+ () => props.cpu,
333
+ (newValue) => {
334
+ if (!newValue) return
335
+
336
+ enableCpuHotAdd.value = newValue.hotplug
337
+ selectedCpu.value = newValue.vcpus
338
+ selectedMaxCpu.value = newValue.max_vcpus
339
+ selectedCorePerSocket.value = newValue.core_per_socket
340
+ reservation.value = '' + newValue.reservation_mhz
341
+ limit.value = '' + newValue.limit_mhz
342
+ shares.value = '' + newValue.shares
343
+ cpuModel.value =
344
+ props.cpuModels.find((model) => model.text === props.cpu?.model)?.value ||
345
+ cpuModel.value
346
+ },
347
+ { immediate: true }
348
+ )
349
+
350
+ const onRemoveValidationError = (): void => {
351
+ emits('remove-error-by-title', 'cpu.vcpus')
352
+ }
353
+ </script>
354
+
355
+ <style scoped lang="scss">
356
+ h3.cpu-help-title {
357
+ margin-top: 7px;
358
+ font-size: 22px;
359
+ color: #565656;
360
+ }
361
+ p.cpu-help-text {
362
+ width: 310px;
363
+ margin-top: 24px;
364
+ font-size: 14px;
365
+ color: #565656;
366
+ }
367
+ a.cpu-more-info {
368
+ color: #00648f;
369
+ font-size: 14px;
370
+ }
371
+ </style>