Coverage for nova/api/validation/extra_specs/quota.py: 100%
13 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 ``quota`` namespaced extra specs."""
17from nova.api.validation.extra_specs import base
20EXTRA_SPEC_VALIDATORS = []
23# CPU, memory, disk IO and VIF quotas (VMWare)
24for key, name, unit in (
25 ('cpu', 'CPU', 'MHz'),
26 ('memory', 'memory', 'MB'),
27 ('disk_io', 'disk IO', 'I/O per second'),
28 ('vif', 'virtual interface', 'Mbps'),
29):
30 EXTRA_SPEC_VALIDATORS.extend(
31 [
32 base.ExtraSpecValidator(
33 name=f'quota:{key}_limit',
34 description=(
35 f'The upper limit for {name} allocation in {unit}. '
36 f'The utilization of an instance will not exceed this '
37 f'limit, even if there are available resources. '
38 f'This is typically used to ensure a consistent '
39 f'performance of instances independent of available '
40 f'resources. '
41 f'The value ``0`` indicates that {name} usage is not '
42 f'limited. '
43 f'Only supported by the VMWare virt driver.'
44 ),
45 value={
46 'type': int,
47 'min': 0,
48 },
49 ),
50 base.ExtraSpecValidator(
51 name=f'quota:{key}_reservation',
52 description=(
53 f'The guaranteed minimum {name} reservation in {unit}. '
54 f'This means the specified amount of {name} that will '
55 f'be guaranteed for the instance. '
56 f'Only supported by the VMWare virt driver.'
57 ),
58 value={
59 'type': int,
60 },
61 ),
62 base.ExtraSpecValidator(
63 name=f'quota:{key}_shares_level',
64 description=(
65 f"The allocation level for {name}. If you choose "
66 f"'custom', set the number of {name} shares using "
67 f"'quota:{key}_shares_share'. "
68 f"Only supported by the VMWare virt driver."
69 ),
70 value={
71 'type': str,
72 'enum': ['custom', 'high', 'normal', 'low'],
73 },
74 ),
75 base.ExtraSpecValidator(
76 name=f'quota:{key}_shares_share',
77 description=(
78 f"The number of shares of {name} allocated in the "
79 f"event that 'quota:{key}_shares_level=custom' is "
80 f"used. "
81 f"Ignored otherwise. "
82 f"There is no unit for this value: it is a relative "
83 f"measure based on the settings for other instances. "
84 f"Only supported by the VMWare virt driver."
85 ),
86 value={
87 'type': int,
88 'min': 0,
89 },
90 ),
91 ]
92 )
95# CPU quotas (libvirt)
96EXTRA_SPEC_VALIDATORS.extend(
97 [
98 base.ExtraSpecValidator(
99 name='quota:cpu_shares',
100 description=(
101 'The proportional weighted share for the domain. '
102 'If this element is omitted, the service defaults to the OS '
103 'provided defaults. '
104 'There is no unit for the value; it is a relative measure '
105 'based on the setting of other VMs. '
106 'For example, a VM configured with a value of 2048 gets '
107 'twice as much CPU time as a VM configured with value 1024. '
108 'Only supported by the libvirt virt driver.'
109 ),
110 value={
111 'type': int,
112 'min': 0,
113 },
114 ),
115 base.ExtraSpecValidator(
116 name='quota:cpu_period',
117 description=(
118 'Specifies the enforcement interval in microseconds. '
119 'Within a period, each VCPU of the instance is not allowed '
120 'to consume more than the quota worth of runtime. '
121 'The value should be in range 1,000 - 1,000,000. '
122 'A period with a value of 0 means no value. '
123 'Only supported by the libvirt virt driver.'
124 ),
125 value={
126 'type': int,
127 'min': 0,
128 },
129 ),
130 base.ExtraSpecValidator(
131 name='quota:cpu_quota',
132 description=(
133 "The maximum allowed bandwidth in microseconds. "
134 "Can be combined with 'quota:cpu_period' to limit an instance "
135 "to a percentage of capacity of a physical CPU. "
136 "The value should be in range 1,000 - 2^64 or negative. "
137 "A negative value indicates that the instance has infinite "
138 "bandwidth. "
139 "Only supported by the libvirt virt driver."
140 ),
141 value={
142 'type': int,
143 },
144 ),
145 ]
146)
149# Disk quotas (libvirt)
150for stat in ('read', 'write', 'total'):
151 for metric in ('bytes', 'iops'):
152 EXTRA_SPEC_VALIDATORS.append(
153 base.ExtraSpecValidator(
154 name=f'quota:disk_{stat}_{metric}_sec',
155 description=(
156 f'The quota {stat} {metric} for disk. '
157 f'Only supported by the libvirt virt driver.'
158 ),
159 value={
160 'type': int,
161 'min': 0,
162 },
163 )
164 )
167# VIF quotas (libvirt)
168# TODO(stephenfin): Determine whether this should be deprecated now that
169# nova-network is dead
170for stat in ('inbound', 'outbound'):
171 for metric in ('average', 'peak', 'burst'):
172 EXTRA_SPEC_VALIDATORS.append(
173 base.ExtraSpecValidator(
174 name=f'quota:vif_{stat}_{metric}',
175 description=(
176 f'The quota {stat} {metric} for VIF. Only supported '
177 f'by the libvirt virt driver.'
178 ),
179 value={
180 'type': int,
181 'min': 0,
182 },
183 )
184 )
187def register():
188 return EXTRA_SPEC_VALIDATORS