bfg-common 1.1.50 → 1.1.52

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,372 +1,374 @@
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
- class="input-text-color"
28
- v-model.number="selectedCpu"
29
- :items="cpuOptions"
30
- :disabled="isCpuDisabled"
31
- @click.stop
32
- />
33
- </template>
34
- <template #content>{{ vcpusLocalAndApiErrorsTexts }}</template>
35
- </atoms-tooltip-error>
36
- </div>
37
-
38
- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-tooltip
39
- :vm-cpu-help-text-second="props.vmCpuHelpTextSecond"
40
- />
41
- </div>
42
- </template>
43
- <template #stackChildren>
44
- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-cores-per-socket
45
- v-model:selected-core-per-socket="selectedCorePerSocket"
46
- :selected-cpu="selectedCpu"
47
- :cpu-options="cpuOptions"
48
- :is-edit="props.isEdit"
49
- :disabled="isDisabled"
50
- :error-validation-fields="props.errorValidationFields"
51
- @remove-error-by-title="emits('remove-error-by-title', $event)"
52
- />
53
- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-hot-plug
54
- v-model:enable-cpu-hot-add="enableCpuHotAdd"
55
- :disabled="enableCpuHotAddDisabled"
56
- />
57
- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-max-cpu
58
- v-show="enableCpuHotAdd"
59
- v-model:selected-max-cpu.number="selectedMaxCpu"
60
- :cpu-options="maxCpuOptions"
61
- :error-validation-fields="props.errorValidationFields"
62
- :disabled="isDisabled"
63
- @invalid="maxCpuInvalid = $event"
64
- @remove-error-by-title="emits('remove-error-by-title', $event)"
65
- />
66
- <common-vm-actions-add-customize-hardware-virtual-hardware-reservation
67
- v-model:reservation="reservation"
68
- v-model:reservation-type="reservationType"
69
- :error-validation-fields="props.errorValidationFields"
70
- :disabled="isDisabled"
71
- type="mhz"
72
- component-type="cpu"
73
- @invalid="reservationInvalid = $event"
74
- @remove-error-by-title="emits('remove-error-by-title', $event)"
75
- />
76
- <common-vm-actions-add-customize-hardware-virtual-hardware-limit
77
- v-model:limit="limit"
78
- v-model:limit-type="limitType"
79
- :error-validation-fields="props.errorValidationFields"
80
- :disabled="isDisabled"
81
- type="mhz"
82
- component-type="cpu"
83
- @invalid="limitInvalid = $event"
84
- @remove-error-by-title="emits('remove-error-by-title', $event)"
85
- />
86
- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-shares
87
- v-model:shares="shares"
88
- v-model:shares-type="sharesType"
89
- :error-validation-fields="props.errorValidationFields"
90
- :disabled="isDisabled"
91
- @remove-error-by-title="emits('remove-error-by-title', $event)"
92
- @invalid="sharesInvalid = $event"
93
- />
94
- <!-- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-hv-->
95
- <!-- v-model:hardwareVirtualization="hardwareVirtualization"-->
96
- <!-- />-->
97
- <!-- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-pc-->
98
- <!-- v-model:performanceCounters="performanceCounters"-->
99
- <!-- />-->
100
- <!-- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-sa-->
101
- <!-- v-model:schedulingAffinity="schedulingAffinity"-->
102
- <!-- />-->
103
- <!-- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-iommu-->
104
- <!-- v-model:iommu="iommu"-->
105
- <!-- />-->
106
- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-model
107
- v-model:cpu-model="cpuModel"
108
- v-model:passthrough-host-cpu="passthroughHostCpu"
109
- v-model:host-model-cpu="hostModelCpu"
110
- :cpu-models="props.cpuModels"
111
- :is-edit="props.isEdit"
112
- :error-validation-fields="props.errorValidationFields"
113
- :disabled="isDisabled"
114
- @remove-error-by-title="emits('remove-error-by-title', $event)"
115
- />
116
- </template>
117
- </atoms-stack-block>
118
- </div>
119
- </template>
120
-
121
- <script setup lang="ts">
122
- import { UI_I_SendDataCpu } from '~/components/common/vm/actions/add/customizeHardware/virtualHardware/models/interfaces'
123
- import { UI_I_Localization } from '~/models/interfaces'
124
- import { UI_I_ErrorValidationField } from '~/models/store/interfaces'
125
- import { UI_I_OptionItem } from '~/components/atoms/models/interfaces'
126
- import { API_UI_I_VmEditCpu } from '~/models/store/vm/interfaces'
127
- import { cpuOptionsFunc } from '~/components/common/vm/actions/add/customizeHardware/virtualHardware/cpu/config/cpuOptions'
128
-
129
- const props = defineProps<{
130
- maxCpus: number
131
- cpuModels: UI_I_OptionItem[]
132
- isEdit: boolean
133
- errorValidationFields: UI_I_ErrorValidationField<string>[]
134
- vmCpuHelpTextSecond?: string
135
- state?: string
136
- cpu?: API_UI_I_VmEditCpu
137
- }>()
138
- const emits = defineEmits<{
139
- (event: 'send-data', value: UI_I_SendDataCpu): void
140
- (event: 'invalid', value: boolean): void
141
- (event: 'remove-error-by-title', value: string): void
142
- }>()
143
-
144
- const localization = computed<UI_I_Localization>(() => useLocal())
145
-
146
- const isDisabled = computed<boolean>(() => {
147
- return props.state === '1'
148
- })
149
-
150
- const cpuOptions = computed<UI_I_OptionItem[]>(() =>
151
- cpuOptionsFunc(localization.value, 1, props.maxCpus)
152
- )
153
-
154
- const enableCpuHotAdd = ref<boolean>(false)
155
- const enableCpuHotAddDisabled = computed<boolean>(
156
- () => selectedCpu.value >= props.maxCpus || isDisabled.value
157
- )
158
- watch(enableCpuHotAdd, (newValue) => {
159
- if (newValue) return
160
-
161
- maxCpuInvalid.value = false
162
- selectedMaxCpu.value = cpuOptions.value.at(-1)?.value
163
- })
164
-
165
- const selectedCpu = ref<number>(
166
- isDisabled.value && enableCpuHotAdd.value ? props.maxCpus : 2
167
- )
168
- const isCpuDisabled = computed<boolean>(
169
- () => isDisabled.value && !enableCpuHotAdd.value
170
- )
171
- watch(selectedCpu, (newValue) => {
172
- selectedCpu.value = Math.floor(+newValue)
173
- if (!(selectedCpu.value % selectedCorePerSocket.value)) return
174
- selectedCorePerSocket.value = 1
175
- })
176
- const maxCpuOptions = computed<UI_I_OptionItem[]>(() =>
177
- cpuOptionsFunc(localization.value, selectedCpu.value + 1, props.maxCpus)
178
- )
179
- watch(selectedCpu, (newValue) => {
180
- if (newValue >= props.maxCpus) {
181
- enableCpuHotAdd.value = false
182
- }
183
- selectedMaxCpu.value =
184
- selectedMaxCpu.value <= newValue ? newValue + 1 : selectedMaxCpu.value
185
- if (selectedMaxCpu.value > props.maxCpus) selectedMaxCpu.value = props.maxCpus
186
- })
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(
247
- cpuInvalid,
248
- (newValue: boolean) => {
249
- emits('invalid', newValue)
250
- },
251
- { immediate: true }
252
- )
253
-
254
- const reservation = ref<string>('1')
255
- const reservationType = ref<string>('mhz')
256
-
257
- const limit = ref<string>('Unlimited')
258
- const limitType = ref<string>('mhz')
259
-
260
- const shares = ref<string>('2000')
261
- const sharesType = ref<string>('2000')
262
-
263
- // const hardwareVirtualization = ref<boolean>(false)
264
- //
265
- // const performanceCounters = ref<boolean>(false)
266
- //
267
- // const schedulingAffinity = ref<string>('')
268
- //
269
- // const iommu = ref<boolean>(false)
270
-
271
- const cpuModel = ref<string>(props.cpuModels[0]?.value || '')
272
- watch(
273
- () => props.cpuModels,
274
- (newValue) => {
275
- cpuModel.value = newValue[0].value
276
- }
277
- )
278
- const passthroughHostCpu = ref<boolean>(false)
279
- const hostModelCpu = ref<boolean>(false)
280
-
281
- // const isShowCpuHelp = ref<boolean>(false)
282
-
283
- const { $binary } = useNuxtApp()
284
- watch(
285
- [
286
- reservation,
287
- reservationType,
288
- limit,
289
- shares,
290
- selectedCpu,
291
- selectedMaxCpu,
292
- selectedCorePerSocket,
293
- enableCpuHotAdd,
294
- cpuModel,
295
- passthroughHostCpu,
296
- hostModelCpu,
297
- ],
298
- () => {
299
- const reservationInMhz =
300
- reservationType.value === 'ghz'
301
- ? $binary.ghzToMhz(+reservation.value)
302
- : +reservation.value
303
- const limitInMhz =
304
- limit.value === 'Unlimited'
305
- ? limit.value
306
- : limitType.value === 'ghz'
307
- ? $binary.ghzToMhz(+limit.value)
308
- : +limit.value
309
- const model = passthroughHostCpu.value
310
- ? 'host-passthrough'
311
- : hostModelCpu.value
312
- ? 'host-model'
313
- : cpuModel.value
314
-
315
- emits('send-data', {
316
- model,
317
- vcpus: selectedCpu.value,
318
- max_vcpus: enableCpuHotAdd.value ? selectedMaxCpu.value : 0,
319
- core_per_socket: selectedCorePerSocket.value,
320
- reservation_mhz: reservationInMhz,
321
- limit_mhz: limitInMhz,
322
- shares: +shares.value,
323
- hotplug: enableCpuHotAdd.value,
324
- })
325
- },
326
- {
327
- immediate: true,
328
- }
329
- )
330
-
331
- // Добавляем данные для редактирования
332
- watch(
333
- () => props.cpu,
334
- (newValue) => {
335
- if (!newValue) return
336
-
337
- enableCpuHotAdd.value = newValue.hotplug
338
- selectedCpu.value = newValue.vcpus
339
- selectedMaxCpu.value = newValue.max_vcpus
340
- selectedCorePerSocket.value = newValue.core_per_socket
341
- reservation.value = '' + newValue.reservation_mhz
342
- limit.value = '' + newValue.limit_mhz
343
- shares.value = '' + newValue.shares
344
- cpuModel.value =
345
- props.cpuModels.find((model) => model.text === props.cpu?.model)?.value ||
346
- cpuModel.value
347
- },
348
- { immediate: true }
349
- )
350
-
351
- const onRemoveValidationError = (): void => {
352
- emits('remove-error-by-title', 'cpu.vcpus')
353
- }
354
- </script>
355
-
356
- <style scoped lang="scss">
357
- h3.cpu-help-title {
358
- margin-top: 7px;
359
- font-size: 22px;
360
- color: #565656;
361
- }
362
- p.cpu-help-text {
363
- width: 310px;
364
- margin-top: 24px;
365
- font-size: 14px;
366
- color: #565656;
367
- }
368
- a.cpu-more-info {
369
- color: #00648f;
370
- font-size: 14px;
371
- }
372
- </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
+ class="input-text-color"
28
+ v-model.number="selectedCpu"
29
+ :items="cpuOptions"
30
+ :disabled="isCpuDisabled"
31
+ @click.stop
32
+ />
33
+ </template>
34
+ <template #content>{{ vcpusLocalAndApiErrorsTexts }}</template>
35
+ </atoms-tooltip-error>
36
+ </div>
37
+
38
+ <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-tooltip
39
+ :vm-cpu-help-text-second="props.vmCpuHelpTextSecond"
40
+ />
41
+ </div>
42
+ </template>
43
+ <template #stackChildren>
44
+ <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-cores-per-socket
45
+ v-model:selected-core-per-socket="selectedCorePerSocket"
46
+ :selected-cpu="selectedCpu"
47
+ :cpu-options="cpuOptions"
48
+ :is-edit="props.isEdit"
49
+ :disabled="isDisabled"
50
+ :error-validation-fields="props.errorValidationFields"
51
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
52
+ />
53
+ <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-hot-plug
54
+ v-model:enable-cpu-hot-add="enableCpuHotAdd"
55
+ :disabled="enableCpuHotAddDisabled"
56
+ />
57
+ <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-max-cpu
58
+ v-show="enableCpuHotAdd"
59
+ v-model:selected-max-cpu.number="selectedMaxCpu"
60
+ :cpu-options="maxCpuOptions"
61
+ :error-validation-fields="props.errorValidationFields"
62
+ :disabled="isDisabled"
63
+ @invalid="maxCpuInvalid = $event"
64
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
65
+ />
66
+ <common-vm-actions-add-customize-hardware-virtual-hardware-reservation
67
+ v-model:reservation="reservation"
68
+ v-model:reservation-type="reservationType"
69
+ :error-validation-fields="props.errorValidationFields"
70
+ :disabled="isDisabled"
71
+ type="mhz"
72
+ component-type="cpu"
73
+ @invalid="reservationInvalid = $event"
74
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
75
+ />
76
+ <common-vm-actions-add-customize-hardware-virtual-hardware-limit
77
+ v-model:limit="limit"
78
+ v-model:limit-type="limitType"
79
+ :error-validation-fields="props.errorValidationFields"
80
+ :disabled="isDisabled"
81
+ type="mhz"
82
+ component-type="cpu"
83
+ @invalid="limitInvalid = $event"
84
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
85
+ />
86
+ <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-shares
87
+ v-model:shares="shares"
88
+ v-model:shares-type="sharesType"
89
+ :error-validation-fields="props.errorValidationFields"
90
+ :disabled="isDisabled"
91
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
92
+ @invalid="sharesInvalid = $event"
93
+ />
94
+ <!-- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-hv-->
95
+ <!-- v-model:hardwareVirtualization="hardwareVirtualization"-->
96
+ <!-- />-->
97
+ <!-- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-pc-->
98
+ <!-- v-model:performanceCounters="performanceCounters"-->
99
+ <!-- />-->
100
+ <!-- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-sa-->
101
+ <!-- v-model:schedulingAffinity="schedulingAffinity"-->
102
+ <!-- />-->
103
+ <!-- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-iommu-->
104
+ <!-- v-model:iommu="iommu"-->
105
+ <!-- />-->
106
+ <common-vm-actions-add-customize-hardware-virtual-hardware-cpu-model
107
+ v-model:cpu-model="cpuModel"
108
+ v-model:passthrough-host-cpu="passthroughHostCpu"
109
+ v-model:host-model-cpu="hostModelCpu"
110
+ :cpu-models="props.cpuModels"
111
+ :is-edit="props.isEdit"
112
+ :error-validation-fields="props.errorValidationFields"
113
+ :disabled="isDisabled"
114
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
115
+ />
116
+ </template>
117
+ </atoms-stack-block>
118
+ </div>
119
+ </template>
120
+
121
+ <script setup lang="ts">
122
+ import { UI_I_SendDataCpu } from '~/components/common/vm/actions/add/customizeHardware/virtualHardware/models/interfaces'
123
+ import { UI_I_Localization } from '~/models/interfaces'
124
+ import { UI_I_ErrorValidationField } from '~/models/store/interfaces'
125
+ import { UI_I_OptionItem } from '~/components/atoms/models/interfaces'
126
+ import { API_UI_I_VmEditCpu } from '~/models/store/vm/interfaces'
127
+ import { cpuOptionsFunc } from '~/components/common/vm/actions/add/customizeHardware/virtualHardware/cpu/config/cpuOptions'
128
+
129
+ const props = defineProps<{
130
+ maxCpus: number
131
+ cpuModels: UI_I_OptionItem[]
132
+ isEdit: boolean
133
+ errorValidationFields: UI_I_ErrorValidationField<string>[]
134
+ vmCpuHelpTextSecond?: string
135
+ state?: string
136
+ cpu?: API_UI_I_VmEditCpu
137
+ }>()
138
+ const emits = defineEmits<{
139
+ (event: 'send-data', value: UI_I_SendDataCpu): void
140
+ (event: 'invalid', value: boolean): void
141
+ (event: 'remove-error-by-title', value: string): void
142
+ }>()
143
+
144
+ const localization = computed<UI_I_Localization>(() => useLocal())
145
+
146
+ const isDisabled = computed<boolean>(() => {
147
+ return props.state === '1'
148
+ })
149
+
150
+ const cpuOptions = computed<UI_I_OptionItem[]>(() =>
151
+ cpuOptionsFunc(localization.value, 1, props.maxCpus)
152
+ )
153
+
154
+ const enableCpuHotAdd = ref<boolean>(false)
155
+ const enableCpuHotAddDisabled = computed<boolean>(
156
+ () => selectedCpu.value >= props.maxCpus || isDisabled.value
157
+ )
158
+ watch(enableCpuHotAdd, (newValue) => {
159
+ if (newValue) return
160
+
161
+ maxCpuInvalid.value = false
162
+ selectedMaxCpu.value = cpuOptions.value.at(-1)?.value
163
+ })
164
+
165
+ const selectedCpu = ref<number>(
166
+ isDisabled.value && enableCpuHotAdd.value ? props.maxCpus : 2
167
+ )
168
+ const isCpuDisabled = computed<boolean>(
169
+ () => isDisabled.value && !enableCpuHotAdd.value
170
+ )
171
+ watch(selectedCpu, (newValue) => {
172
+ selectedCpu.value = Math.floor(+newValue)
173
+ if (!(selectedCpu.value % selectedCorePerSocket.value)) return
174
+ selectedCorePerSocket.value = 1
175
+ })
176
+ const maxCpuOptions = computed<UI_I_OptionItem[]>(() =>
177
+ cpuOptionsFunc(localization.value, selectedCpu.value + 1, props.maxCpus)
178
+ )
179
+ watch(selectedCpu, (newValue) => {
180
+ if (newValue >= props.maxCpus) {
181
+ enableCpuHotAdd.value = false
182
+ }
183
+ selectedMaxCpu.value =
184
+ selectedMaxCpu.value <= newValue ? newValue + 1 : selectedMaxCpu.value
185
+ if (selectedMaxCpu.value > props.maxCpus) selectedMaxCpu.value = props.maxCpus
186
+ })
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
+ (enableCpuHotAdd.value &&
245
+ selectedCpu.value < props.maxCpus &&
246
+ maxCpuInvalid.value)
247
+ )
248
+ watch(
249
+ cpuInvalid,
250
+ (newValue: boolean) => {
251
+ emits('invalid', newValue)
252
+ },
253
+ { immediate: true }
254
+ )
255
+
256
+ const reservation = ref<string>('1')
257
+ const reservationType = ref<string>('mhz')
258
+
259
+ const limit = ref<string>('Unlimited')
260
+ const limitType = ref<string>('mhz')
261
+
262
+ const shares = ref<string>('2000')
263
+ const sharesType = ref<string>('2000')
264
+
265
+ // const hardwareVirtualization = ref<boolean>(false)
266
+ //
267
+ // const performanceCounters = ref<boolean>(false)
268
+ //
269
+ // const schedulingAffinity = ref<string>('')
270
+ //
271
+ // const iommu = ref<boolean>(false)
272
+
273
+ const cpuModel = ref<string>(props.cpuModels[0]?.value || '')
274
+ watch(
275
+ () => props.cpuModels,
276
+ (newValue) => {
277
+ cpuModel.value = newValue[0].value
278
+ }
279
+ )
280
+ const passthroughHostCpu = ref<boolean>(false)
281
+ const hostModelCpu = ref<boolean>(false)
282
+
283
+ // const isShowCpuHelp = ref<boolean>(false)
284
+
285
+ const { $binary } = useNuxtApp()
286
+ watch(
287
+ [
288
+ reservation,
289
+ reservationType,
290
+ limit,
291
+ shares,
292
+ selectedCpu,
293
+ selectedMaxCpu,
294
+ selectedCorePerSocket,
295
+ enableCpuHotAdd,
296
+ cpuModel,
297
+ passthroughHostCpu,
298
+ hostModelCpu,
299
+ ],
300
+ () => {
301
+ const reservationInMhz =
302
+ reservationType.value === 'ghz'
303
+ ? $binary.ghzToMhz(+reservation.value)
304
+ : +reservation.value
305
+ const limitInMhz =
306
+ limit.value === 'Unlimited'
307
+ ? limit.value
308
+ : limitType.value === 'ghz'
309
+ ? $binary.ghzToMhz(+limit.value)
310
+ : +limit.value
311
+ const model = passthroughHostCpu.value
312
+ ? 'host-passthrough'
313
+ : hostModelCpu.value
314
+ ? 'host-model'
315
+ : cpuModel.value
316
+
317
+ emits('send-data', {
318
+ model,
319
+ vcpus: selectedCpu.value,
320
+ max_vcpus: enableCpuHotAdd.value ? selectedMaxCpu.value : 0,
321
+ core_per_socket: selectedCorePerSocket.value,
322
+ reservation_mhz: reservationInMhz,
323
+ limit_mhz: limitInMhz,
324
+ shares: +shares.value,
325
+ hotplug: enableCpuHotAdd.value,
326
+ })
327
+ },
328
+ {
329
+ immediate: true,
330
+ }
331
+ )
332
+
333
+ // Добавляем данные для редактирования
334
+ watch(
335
+ () => props.cpu,
336
+ (newValue) => {
337
+ if (!newValue) return
338
+
339
+ enableCpuHotAdd.value = newValue.hotplug
340
+ selectedCpu.value = newValue.vcpus
341
+ selectedMaxCpu.value = newValue.max_vcpus
342
+ selectedCorePerSocket.value = newValue.core_per_socket
343
+ reservation.value = '' + newValue.reservation_mhz
344
+ limit.value = '' + newValue.limit_mhz
345
+ shares.value = '' + newValue.shares
346
+ cpuModel.value =
347
+ props.cpuModels.find((model) => model.text === props.cpu?.model)?.value ||
348
+ cpuModel.value
349
+ },
350
+ { immediate: true }
351
+ )
352
+
353
+ const onRemoveValidationError = (): void => {
354
+ emits('remove-error-by-title', 'cpu.vcpus')
355
+ }
356
+ </script>
357
+
358
+ <style scoped lang="scss">
359
+ h3.cpu-help-title {
360
+ margin-top: 7px;
361
+ font-size: 22px;
362
+ color: #565656;
363
+ }
364
+ p.cpu-help-text {
365
+ width: 310px;
366
+ margin-top: 24px;
367
+ font-size: 14px;
368
+ color: #565656;
369
+ }
370
+ a.cpu-more-info {
371
+ color: #00648f;
372
+ font-size: 14px;
373
+ }
374
+ </style>