summaryrefslogtreecommitdiff
path: root/nova/api/validation/extra_specs/hw.py
blob: 4aaccf639a43e65ffb2a60cfd140a273967ec640 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
# Copyright 2020 Red Hat, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

"""Validators for ``hw`` namespaced extra specs."""

from nova.api.validation.extra_specs import base


realtime_validators = [
    base.ExtraSpecValidator(
        name='hw:cpu_realtime',
        description=(
            'Determine whether realtime mode should be enabled for the '
            'instance or not. '
            'Only supported by the libvirt virt driver.'
        ),
        value={
            'type': bool,
            'description': 'Whether to enable realtime priority.',
        },
    ),
    base.ExtraSpecValidator(
        name='hw:cpu_realtime_mask',
        description=(
            'A exclusion mask of CPUs that should not be enabled for '
            'realtime. '
            'Only supported by the libvirt virt driver.'
        ),
        value={
            'type': str,
            'pattern': r'(\^)?\d+((-\d+)?(,\^?\d+(-\d+)?)?)*',
        },
    ),
]

hide_hypervisor_id_validator = [
    base.ExtraSpecValidator(
        name='hw:hide_hypervisor_id',
        description=(
            'Determine whether the hypervisor ID should be hidden from the '
            'guest. '
            'Only supported by the libvirt virt driver.'
        ),
        value={
            'type': bool,
            'description': 'Whether to hide the hypervisor ID.',
        },
    )
]

cpu_policy_validators = [
    base.ExtraSpecValidator(
        name='hw:cpu_policy',
        description=(
            'The policy to apply when determining what host CPUs the guest '
            'CPUs can run on. '
            'If ``shared`` (default), guest CPUs can be overallocated but '
            'cannot float across host cores. '
            'If ``dedicated``, guest CPUs cannot be overallocated but are '
            'individually pinned to their own host core. '
            'If ``mixed``, the policy for each instance CPU can be specified '
            'using the ``hw:cpu_dedicated_mask`` or ``hw:cpu_realtime_mask`` '
            'extra specs.'
            'Only supported by the libvirt virt driver.'
        ),
        value={
            'type': str,
            'description': 'The CPU policy.',
            'enum': [
                'dedicated',
                'shared',
                'mixed',
            ],
        },
    ),
    base.ExtraSpecValidator(
        name='hw:cpu_thread_policy',
        description=(
            'The policy to apply when determining whether the destination '
            'host can have hardware threads enabled or not. '
            'If ``prefer`` (default), hosts with hardware threads will be '
            'preferred. '
            'If ``require``, hosts with hardware threads will be required. '
            'If ``isolate``, hosts with hardware threads will be forbidden. '
            'Only supported by the libvirt virt driver.'
        ),
        value={
            'type': str,
            'description': 'The CPU thread policy.',
            'enum': [
                'prefer',
                'isolate',
                'require',
            ],
        },
    ),
    base.ExtraSpecValidator(
        name='hw:emulator_threads_policy',
        description=(
            'The policy to apply when determining whether emulator threads '
            'should be offloaded to a separate isolated core or to a pool '
            'of shared cores. '
            'If ``share``, emulator overhead threads will be offloaded to a '
            'pool of shared cores. '
            'If ``isolate``, emulator overhead threads will be offloaded to '
            'their own core. '
            'Only supported by the libvirt virt driver.'
        ),
        value={
            'type': str,
            'description': 'The emulator thread policy.',
            'enum': [
                'isolate',
                'share',
            ],
        },
    ),
    base.ExtraSpecValidator(
        name='hw:cpu_dedicated_mask',
        description=(
            'A mapping of **guest** (instance) CPUs to be pinned to **host** '
            'CPUs for an instance with a ``mixed`` CPU policy. '
            'Any **guest** CPUs which are not in this mapping will float '
            'across host cores. '
            'Only supported by the libvirt virt driver.'
        ),
        value={
            'type': str,
            'description': (
                'The **guest** CPU mapping to be pinned to **host** CPUs for '
                'an instance with a ``mixed`` CPU policy.'
            ),
            # This pattern is identical to 'hw:cpu_realtime_mask' pattern.
            'pattern': r'\^?\d+((-\d+)?(,\^?\d+(-\d+)?)?)*',
        },
    ),
]

hugepage_validators = [
    base.ExtraSpecValidator(
        name='hw:mem_page_size',
        description=(
            'The size of memory pages to allocate to the guest with. '
            'Can be one of the three alias - ``large``, ``small`` or '
            '``any``, - or an actual size. '
            'Only supported by the libvirt virt driver.'
        ),
        value={
            'type': str,
            'description': 'The size of memory page to allocate',
            'pattern': r'(large|small|any|\d+([kKMGT]i?)?(b|bit|B)?)',
        },
    ),
]

numa_validators = [
    base.ExtraSpecValidator(
        name='hw:numa_nodes',
        description=(
            'The number of virtual NUMA nodes to allocate to configure the '
            'guest with. '
            'Each virtual NUMA node will be mapped to a unique host NUMA '
            'node. '
            'Only supported by the libvirt virt driver.'
        ),
        value={
            'type': int,
            'description': 'The number of virtual NUMA nodes to allocate',
            'min': 1,
        },
    ),
    base.ExtraSpecValidator(
        name='hw:numa_cpus.{num}',
        description=(
            'A mapping of **guest** (instance) CPUs to the **guest** (not '
            'host!) NUMA node identified by ``{num}``. '
            'This can be used to provide asymmetric CPU-NUMA allocation and '
            'is necessary where the number of guest NUMA nodes is not a '
            'factor of the number of guest CPUs. '
            'Only supported by the libvirt virt driver.'
        ),
        parameters=[
            {
                'name': 'num',
                'pattern': r'\d+',  # positive integers
                'description': 'The ID of the **guest** NUMA node.',
            },
        ],
        value={
            'type': str,
            'description': (
                'The guest CPUs, in the form of a CPU map, to allocate to the '
                'guest NUMA node identified by ``{num}``.'
            ),
            'pattern': r'\^?\d+((-\d+)?(,\^?\d+(-\d+)?)?)*',
        },
    ),
    base.ExtraSpecValidator(
        name='hw:numa_mem.{num}',
        description=(
            'A mapping of **guest** memory to the **guest** (not host!) NUMA '
            'node identified by ``{num}``. '
            'This can be used to provide asymmetric memory-NUMA allocation '
            'and is necessary where the number of guest NUMA nodes is not a '
            'factor of the total guest memory. '
            'Only supported by the libvirt virt driver.'
        ),
        parameters=[
            {
                'name': 'num',
                'pattern': r'\d+',  # positive integers
                'description': 'The ID of the **guest** NUMA node.',
            },
        ],
        value={
            'type': int,
            'description': (
                'The guest memory, in MB, to allocate to the guest NUMA node '
                'identified by ``{num}``.'
            ),
            'min': 1,
        },
    ),
    base.ExtraSpecValidator(
        name='hw:pci_numa_affinity_policy',
        description=(
            'The NUMA affinity policy of any PCI passthrough devices or '
            'SR-IOV network interfaces attached to the instance. '
            'If ``required`, only PCI devices from one of the host NUMA '
            'nodes the instance VCPUs are allocated from can be used by said '
            'instance. '
            'If ``preferred``, any PCI device can be used, though preference '
            'will be given to those from the same NUMA node as the instance '
            'VCPUs. '
            'If ``legacy`` (default), behavior is as with ``required`` unless '
            'the PCI device does not support provide NUMA affinity '
            'information, in which case affinity is ignored. '
            'Only supported by the libvirt virt driver.'
        ),
        value={
            'type': str,
            'description': 'The PCI NUMA affinity policy',
            'enum': [
                'required',
                'preferred',
                'legacy',
                'socket',
            ],
        },
    ),
]

cpu_topology_validators = [
    base.ExtraSpecValidator(
        name='hw:cpu_sockets',
        description=(
            'The number of virtual CPU threads to emulate in the guest '
            'CPU topology. '
            'Defaults to the number of vCPUs requested. '
            'Only supported by the libvirt virt driver.'
        ),
        value={
            'type': int,
            'description': 'A number of virtual CPU sockets',
            'min': 1,
        },
    ),
    base.ExtraSpecValidator(
        name='hw:cpu_cores',
        description=(
            'The number of virtual CPU cores to emulate per socket in the '
            'guest CPU topology. '
            'Defaults to ``1``.'
            'Only supported by the libvirt virt driver. '
        ),
        value={
            'type': int,
            'description': 'A number of virtual CPU cores',
            'min': 1,
        },
    ),
    base.ExtraSpecValidator(
        name='hw:cpu_threads',
        description=(
            'The number of virtual CPU threads to emulate per core in the '
            'guest CPU topology.'
            'Defaults to ``1``. '
            'Only supported by the libvirt virt driver. '
        ),
        value={
            'type': int,
            'description': 'A number of virtual CPU threads',
            'min': 1,
        },
    ),
    base.ExtraSpecValidator(
        name='hw:max_cpu_sockets',
        description=(
            'The max number of virtual CPU threads to emulate in the '
            'guest CPU topology. '
            'This is used to limit the topologies that can be requested by '
            'an image and will be used to validate the ``hw_cpu_sockets`` '
            'image metadata property. '
            'Only supported by the libvirt virt driver. '
        ),
        value={
            'type': int,
            'description': 'A number of virtual CPU sockets',
            'min': 1,
        },
    ),
    base.ExtraSpecValidator(
        name='hw:max_cpu_cores',
        description=(
            'The max number of virtual CPU cores to emulate per socket in the '
            'guest CPU topology. '
            'This is used to limit the topologies that can be requested by an '
            'image and will be used to validate the ``hw_cpu_cores`` image '
            'metadata property. '
            'Only supported by the libvirt virt driver. '
        ),
        value={
            'type': int,
            'description': 'A number of virtual CPU cores',
            'min': 1,
        },
    ),
    base.ExtraSpecValidator(
        name='hw:max_cpu_threads',
        description=(
            'The max number of virtual CPU threads to emulate per core in the '
            'guest CPU topology. '
            'This is used to limit the topologies that can be requested by an '
            'image and will be used to validate the ``hw_cpu_threads`` image '
            'metadata property. '
            'Only supported by the libvirt virt driver. '
        ),
        value={
            'type': int,
            'description': 'A number of virtual CPU threads',
            'min': 1,
        },
    ),
]

feature_flag_validators = [
    # TODO(stephenfin): Consider deprecating and moving this to the 'os:'
    # namespace
    base.ExtraSpecValidator(
        name='hw:boot_menu',
        description=(
            'Whether to show a boot menu when booting the guest. '
            'Only supported by the libvirt virt driver. '
        ),
        value={
            'type': bool,
            'description': 'Whether to enable the boot menu',
        },
    ),
    base.ExtraSpecValidator(
        name='hw:vif_multiqueue_enabled',
        description=(
            'Whether to enable the virtio-net multiqueue feature. '
            'When set, the driver sets the number of queues equal to the '
            'number of guest vCPUs. This makes the network performance scale '
            'across a number of vCPUs. This requires guest support and is '
            'only supported by the libvirt driver.'
        ),
        value={
            'type': bool,
            'description': 'Whether to enable multiqueue',
        },
    ),
    base.ExtraSpecValidator(
        name='hw:mem_encryption',
        description=(
            'Whether to enable memory encryption for the guest. '
            'Only supported by the libvirt virt driver on hosts with AMD SEV '
            'support.'
        ),
        value={
            'type': bool,
            'description': 'Whether to enable memory encryption',
        },
    ),
    base.ExtraSpecValidator(
        name='hw:pmem',
        description=(
            'A comma-separated list of ``$LABEL``\\ s defined in config for '
            'vPMEM devices. '
            'Only supported by the libvirt virt driver on hosts with PMEM '
            'devices.'
        ),
        value={
            'type': str,
            'description': (
                'A comma-separated list of valid resource class names.'
            ),
            'pattern': '([a-zA-Z0-9_]+(,)?)+',
        },
    ),
    base.ExtraSpecValidator(
        name='hw:pmu',
        description=(
            'Whether to enable the Performance Monitory Unit (PMU) for the '
            'guest. '
            'If this option is not specified, the presence of the vPMU is '
            'determined by the hypervisor. '
            'The vPMU is used by tools like ``perf`` in the guest to provide '
            'more accurate information for profiling application and '
            'monitoring guest performance. '
            'For realtime workloads, the emulation of a vPMU can introduce '
            'additional latency which may be undesirable. '
            'If the telemetry it provides is not required, such workloads '
            'should disable this feature. '
            'For most workloads, the default of unset will be correct. '
            'Only supported by the libvirt virt driver.'
        ),
        value={
            'type': bool,
            'description': 'Whether to enable the PMU',
        },
    ),
    base.ExtraSpecValidator(
        name='hw:serial_port_count',
        description=(
            'The number of serial ports to allocate to the guest. '
            'Only supported by the libvirt virt driver.'
        ),
        value={
            'type': int,
            'min': 0,
            'description': 'The number of serial ports to allocate',
        },
    ),
    base.ExtraSpecValidator(
        name='hw:tpm_model',
        description=(
            'The model of the attached TPM device. '
            'Only supported by the libvirt virt driver.'
        ),
        value={
            'type': str,
            'description': 'A TPM model',
            'enum': [
                'tpm-tis',
                'tpm-crb',
            ],
        },
    ),
    base.ExtraSpecValidator(
        name='hw:tpm_version',
        description=(
            "The TPM version. "
            "Required if requesting a vTPM via the 'hw:tpm_model' extra spec "
            "or equivalent image metadata property. "
            "Only supported by the libvirt virt driver."
        ),
        value={
            'type': str,
            'description': 'A TPM version.',
            'enum': [
                '1.2',
                '2.0',
            ],
        },
    ),
    base.ExtraSpecValidator(
        name='hw:watchdog_action',
        description=(
            'The action to take when the watchdog timer is kicked. '
            'Watchdog devices keep an eye on the instance and carry out the '
            'specified action if the server hangs. '
            'The watchdog uses the ``i6300esb`` device, emulating a PCI Intel '
            '6300ESB. '
            'Only supported by the libvirt virt driver.'
        ),
        value={
            'type': str,
            'description': 'The action to take',
            'enum': [
                'none',
                'pause',
                'poweroff',
                'reset',
                'disabled',
            ],
        },
    ),
]


def register():
    return (
        realtime_validators +
        hide_hypervisor_id_validator +
        cpu_policy_validators +
        hugepage_validators +
        numa_validators +
        cpu_topology_validators +
        feature_flag_validators
    )