bfg-common 1.3.430 → 1.3.432

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