Coverage for nova/api/validation/extra_specs/capabilities.py: 100%
9 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-17 15:08 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-17 15:08 +0000
1# Copyright 2020 Red Hat, Inc. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
15"""Validators for (preferably) ``capabilities`` namespaced extra specs.
17These are used by the ``ComputeCapabilitiesFilter`` scheduler filter. Note that
18we explicitly do not allow the unnamespaced variant of extra specs since this
19has been deprecated since Grizzly (commit 8ce8e4b6c0d). Users that insist on
20using these can disable extra spec validation.
22For all extra specs, the value can be one of the following:
24* ``=`` (equal to or greater than as a number; same as vcpus case)
25* ``==`` (equal to as a number)
26* ``!=`` (not equal to as a number)
27* ``>=`` (greater than or equal to as a number)
28* ``<=`` (less than or equal to as a number)
29* ``s==`` (equal to as a string)
30* ``s!=`` (not equal to as a string)
31* ``s>=`` (greater than or equal to as a string)
32* ``s>`` (greater than as a string)
33* ``s<=`` (less than or equal to as a string)
34* ``s<`` (less than as a string)
35* ``<in>`` (substring)
36* ``<all-in>`` (all elements contained in collection)
37* ``<or>`` (find one of these)
38* A specific value, e.g. ``true``, ``123``, ``testing``
40Examples are: ``>= 5``, ``s== 2.1.0``, ``<in> gcc``, ``<all-in> aes mmx``, and
41``<or> fpu <or> gpu``
42"""
44from nova.api.validation.extra_specs import base
47DESCRIPTION = """\
48Specify that the '{capability}' capability provided by the host compute service
49satisfy the provided filter value. Requires the ``ComputeCapabilitiesFilter``
50scheduler filter.
51"""
53EXTRA_SPEC_VALIDATORS = []
55# non-nested capabilities (from 'nova.objects.compute_node.ComputeNode' and
56# nova.scheduler.host_manager.HostState')
58for capability in (
59 'id', 'uuid', 'service_id', 'host', 'vcpus', 'memory_mb', 'local_gb',
60 'vcpus_used', 'memory_mb_used', 'local_gb_used',
61 'hypervisor_type', 'hypervisor_version', 'hypervisor_hostname',
62 'free_ram_mb', 'free_disk_gb', 'current_workload', 'running_vms',
63 'disk_available_least', 'host_ip', 'mapped',
64 'cpu_allocation_ratio', 'ram_allocation_ratio', 'disk_allocation_ratio',
65) + (
66 'total_usable_ram_mb', 'total_usable_disk_gb', 'disk_mb_used',
67 'free_disk_mb', 'vcpus_total', 'vcpus_used', 'num_instances',
68 'num_io_ops', 'failed_builds', 'aggregates', 'cell_uuid', 'updated',
69):
70 EXTRA_SPEC_VALIDATORS.append(
71 base.ExtraSpecValidator(
72 name=f'capabilities:{capability}',
73 description=DESCRIPTION.format(capability=capability),
74 value={
75 # this is totally arbitrary, since we need to support specific
76 # values
77 'type': str,
78 },
79 ),
80 )
83# nested capabilities (from 'nova.objects.compute_node.ComputeNode' and
84# nova.scheduler.host_manager.HostState')
86for capability in (
87 'cpu_info', 'metrics', 'stats', 'numa_topology', 'supported_hv_specs',
88 'pci_device_pools',
89) + (
90 'nodename', 'pci_stats', 'supported_instances', 'limits', 'instances',
91):
92 EXTRA_SPEC_VALIDATORS.extend([
93 base.ExtraSpecValidator(
94 name=f'capabilities:{capability}{ filter} ',
95 description=DESCRIPTION.format(capability=capability),
96 parameters=[
97 {
98 'name': 'filter',
99 # this is optional, but if it's present it must be preceded
100 # by ':'
101 'pattern': r'(:\w+)*',
102 }
103 ],
104 value={
105 'type': str,
106 },
107 ),
108 ])
111def register():
112 return EXTRA_SPEC_VALIDATORS