1 # Copyright (c) 2016 Cable Television Laboratories, Inc. ("CableLabs")
2 # and others. All rights reserved.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 class FlavorConfig(object):
19 Configuration settings for OpenStack flavor creation
22 def __init__(self, **kwargs):
25 :param name: the flavor's name (required)
26 :param flavor_id: the string ID (default 'auto')
27 :param ram: the required RAM in MB (required)
28 :param disk: the size of the root disk in GB (required)
29 :param vcpus: the number of virtual CPUs (required)
30 :param ephemeral: the size of the ephemeral disk in GB (default 0)
31 :param swap: the size of the dedicated swap disk in GB (default 0)
32 :param rxtx_factor: the receive/transmit factor to be set on ports if
33 backend supports QoS extension (default 1.0)
34 :param is_public: denotes whether or not the flavor is public
36 :param metadata: freeform dict() for special metadata
38 self.name = kwargs.get('name')
40 if kwargs.get('flavor_id'):
41 self.flavor_id = kwargs['flavor_id']
43 self.flavor_id = 'auto'
45 self.ram = kwargs.get('ram')
46 self.disk = kwargs.get('disk')
47 self.vcpus = kwargs.get('vcpus')
49 if kwargs.get('ephemeral'):
50 self.ephemeral = kwargs['ephemeral']
54 if kwargs.get('swap'):
55 self.swap = kwargs['swap']
59 if kwargs.get('rxtx_factor'):
60 self.rxtx_factor = kwargs['rxtx_factor']
62 self.rxtx_factor = 1.0
64 if kwargs.get('is_public') is not None:
65 self.is_public = kwargs['is_public']
69 if kwargs.get('metadata'):
70 self.metadata = kwargs['metadata']
74 if not self.name or not self.ram or not self.disk or not self.vcpus:
75 raise FlavorConfigError(
76 'The attributes name, ram, disk, and vcpus are required for'
79 if not isinstance(self.ram, int):
80 raise FlavorConfigError('The ram attribute must be a integer')
82 if not isinstance(self.disk, int):
83 raise FlavorConfigError('The ram attribute must be a integer')
85 if not isinstance(self.vcpus, int):
86 raise FlavorConfigError('The vcpus attribute must be a integer')
88 if self.ephemeral and not isinstance(self.ephemeral, int):
89 raise FlavorConfigError(
90 'The ephemeral attribute must be an integer')
92 if self.swap and not isinstance(self.swap, int):
93 raise FlavorConfigError('The swap attribute must be an integer')
95 if self.rxtx_factor and not isinstance(self.rxtx_factor, (int, float)):
96 raise FlavorConfigError(
97 'The is_public attribute must be an integer or float')
99 if self.is_public and not isinstance(self.is_public, bool):
100 raise FlavorConfigError(
101 'The is_public attribute must be a boolean')
104 class FlavorConfigError(Exception):
106 Exception to be thrown when a flavor configuration is incorrect