summaryrefslogtreecommitdiff
path: root/nova/api/validation/extra_specs/quota.py
blob: f0ff3db2a677140d340194e80fca5c283fd3f8c8 (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
# 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 ``quota`` namespaced extra specs."""

from nova.api.validation.extra_specs import base


EXTRA_SPEC_VALIDATORS = []


# CPU, memory, disk IO and VIF quotas (VMWare)
for key, name, unit in (
    ('cpu', 'CPU', 'MHz'),
    ('memory', 'memory', 'MB'),
    ('disk_io', 'disk IO', 'I/O per second'),
    ('vif', 'virtual interface', 'Mbps'),
):
    EXTRA_SPEC_VALIDATORS.extend(
        [
            base.ExtraSpecValidator(
                name=f'quota:{key}_limit',
                description=(
                    f'The upper limit for {name} allocation in {unit}. '
                    f'The utilization of an instance will not exceed this '
                    f'limit, even if there are available resources. '
                    f'This is typically used to ensure a consistent '
                    f'performance of instances independent of available '
                    f'resources.'
                    f'The value ``0`` indicates that {name} usage is not '
                    f'limited.'
                    f'Only supported by the VMWare virt driver.'
                ),
                value={
                    'type': int,
                    'min': 0,
                },
            ),
            base.ExtraSpecValidator(
                name=f'quota:{key}_reservation',
                description=(
                    f'The guaranteed minimum {name} reservation in {unit}. '
                    f'This means the specified amount of {name} that will '
                    f'be guaranteed for the instance. '
                    f'Only supported by the VMWare virt driver.'
                ),
                value={
                    'type': int,
                },
            ),
            base.ExtraSpecValidator(
                name=f'quota:{key}_shares_level',
                description=(
                    f"The allocation level for {name}. If you choose "
                    f"'custom', set the number of {name} shares using "
                    f"'quota:{key}_shares_share'. "
                    f"Only supported by the VMWare virt driver."
                ),
                value={
                    'type': str,
                    'enum': ['custom', 'high', 'normal', 'low'],
                },
            ),
            base.ExtraSpecValidator(
                name=f'quota:{key}_shares_share',
                description=(
                    f"The number of shares of {name} allocated in the "
                    f"event that 'quota:{key}_shares_level=custom' is "
                    f"used. "
                    f"Ignored otherwise. "
                    f"There is no unit for this value: it is a relative "
                    f"measure based on the settings for other instances. "
                    f"Only supported by the VMWare virt driver."
                ),
                value={
                    'type': int,
                    'min': 0,
                },
            ),
        ]
    )


# CPU quotas (libvirt)
EXTRA_SPEC_VALIDATORS.extend(
    [
        base.ExtraSpecValidator(
            name='quota:cpu_shares',
            description=(
                'The proportional weighted share for the domain. '
                'If this element is omitted, the service defaults to the OS '
                'provided defaults. '
                'There is no unit for the value; it is a relative measure '
                'based on the setting of other VMs. '
                'For example, a VM configured with a value of 2048 gets '
                'twice as much CPU time as a VM configured with value 1024. '
                'Only supported by the libvirt virt driver.'
            ),
            value={
                'type': int,
                'min': 0,
            },
        ),
        base.ExtraSpecValidator(
            name='quota:cpu_period',
            description=(
                'Specifies the enforcement interval in microseconds. '
                'Within a period, each VCPU of the instance is not allowed '
                'to consume more than the quota worth of runtime. '
                'The value should be in range 1,000 - 1,000,000. '
                'A period with a value of 0 means no value. '
                'Only supported by the libvirt virt driver.'
            ),
            value={
                'type': int,
                'min': 0,
            },
        ),
        base.ExtraSpecValidator(
            name='quota:cpu_quota',
            description=(
                "The maximum allowed bandwidth in microseconds. "
                "Can be combined with 'quota:cpu_period' to limit an instance "
                "to a percentage of capacity of a physical CPU. "
                "The value should be in range 1,000 - 2^64 or negative. "
                "A negative value indicates that the instance has infinite "
                "bandwidth. "
                "Only supported by the libvirt virt driver."
            ),
            value={
                'type': int,
            },
        ),
    ]
)


# Disk quotas (libvirt, HyperV)
for stat in ('read', 'write', 'total'):
    for metric in ('bytes', 'iops'):
        EXTRA_SPEC_VALIDATORS.append(
            base.ExtraSpecValidator(
                name=f'quota:disk_{stat}_{metric}_sec',
                # NOTE(stephenfin): HyperV supports disk_total_{metric}_sec
                # too; update
                description=(
                    f'The quota {stat} {metric} for disk. '
                    f'Only supported by the libvirt virt driver.'
                ),
                value={
                    'type': int,
                    'min': 0,
                },
            )
        )


# VIF quotas (libvirt)
# TODO(stephenfin): Determine whether this should be deprecated now that
# nova-network is dead
for stat in ('inbound', 'outbound'):
    for metric in ('average', 'peak', 'burst'):
        EXTRA_SPEC_VALIDATORS.append(
            base.ExtraSpecValidator(
                name=f'quota:vif_{stat}_{metric}',
                description=(
                    f'The quota {stat} {metric} for VIF. Only supported '
                    f'by the libvirt virt driver.'
                ),
                value={
                    'type': int,
                    'min': 0,
                },
            )
        )


def register():
    return EXTRA_SPEC_VALIDATORS