1 ##############################################################################
2 # Copyright (c) 2016 Michael Chapman (michapma@redhat.com) and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
13 from apex.common import utils
14 from apex.common import constants
16 REQ_DEPLOY_SETTINGS = ['sdn_controller',
28 OPT_DEPLOY_SETTINGS = ['performance',
33 'odl_vpp_routing_node',
38 VALID_ROLES = ['Controller', 'Compute', 'ObjectStorage']
39 VALID_PERF_OPTS = ['kernel', 'nova', 'vpp', 'ovs']
40 VALID_DATAPLANES = ['ovs', 'ovs_dpdk', 'fdio']
41 VALID_ODL_VERSIONS = ['carbon', 'nitrogen', 'oxygen', 'master']
44 class DeploySettings(dict):
46 This class parses a APEX deploy settings yaml file into an object
48 def __init__(self, filename):
49 if isinstance(filename, str):
50 with open(filename, 'r') as deploy_settings_file:
51 init_dict = yaml.safe_load(deploy_settings_file)
53 # assume input is a dict to build from
56 super().__init__(init_dict)
57 self._validate_settings()
59 def _validate_settings(self):
61 Validates the deploy settings file provided
63 DeploySettingsException will be raised if validation fails.
66 if 'deploy_options' not in self:
67 raise DeploySettingsException("No deploy options provided in"
68 " deploy settings file")
69 if 'global_params' not in self:
70 raise DeploySettingsException("No global options provided in"
71 " deploy settings file")
73 deploy_options = self['deploy_options']
74 if not isinstance(deploy_options, dict):
75 raise DeploySettingsException("deploy_options should be a list")
77 if ('gluon' in self['deploy_options'] and
78 'vpn' in self['deploy_options']):
79 if (self['deploy_options']['gluon'] is True and
80 self['deploy_options']['vpn'] is False):
81 raise DeploySettingsException(
82 "Invalid deployment configuration: "
83 "If gluon is enabled, "
84 "vpn also needs to be enabled")
86 for setting, value in deploy_options.items():
87 if setting not in REQ_DEPLOY_SETTINGS + OPT_DEPLOY_SETTINGS:
88 raise DeploySettingsException("Invalid deploy_option {} "
89 "specified".format(setting))
90 if setting == 'dataplane':
91 if value not in VALID_DATAPLANES:
92 planes = ' '.join(VALID_DATAPLANES)
93 raise DeploySettingsException(
94 "Invalid dataplane {} specified. Valid dataplanes:"
95 " {}".format(value, planes))
97 for req_set in REQ_DEPLOY_SETTINGS:
98 if req_set not in deploy_options:
99 if req_set == 'dataplane':
100 self['deploy_options'][req_set] = 'ovs'
101 elif req_set == 'ceph':
102 self['deploy_options'][req_set] = True
103 elif req_set == 'odl_version':
104 self['deploy_options'][req_set] = \
105 constants.DEFAULT_ODL_VERSION
107 self['deploy_options'][req_set] = False
108 elif req_set == 'odl_version' and self['deploy_options'][
109 'odl_version'] not in VALID_ODL_VERSIONS:
110 raise DeploySettingsException(
111 "Invalid ODL version: {}".format(self[deploy_options][
114 if self['deploy_options']['odl_version'] == 'oxygen':
115 self['deploy_options']['odl_version'] = 'master'
117 if 'performance' in deploy_options:
118 if not isinstance(deploy_options['performance'], dict):
119 raise DeploySettingsException("Performance deploy_option"
120 "must be a dictionary.")
121 for role, role_perf_sets in deploy_options['performance'].items():
122 if role not in VALID_ROLES:
123 raise DeploySettingsException("Performance role {}"
124 "is not valid, choose"
127 " ".join(VALID_ROLES)
130 for key in role_perf_sets:
131 if key not in VALID_PERF_OPTS:
132 raise DeploySettingsException("Performance option {} "
133 "is not valid, choose"
140 def _dump_performance(self):
142 Creates performance settings string for bash consumption.
144 Output will be in the form of a list that can be iterated over in
145 bash, with each string being the direct input to the performance
146 setting script in the form <role> <category> <key> <value> to
147 facilitate modification of the correct image.
149 bash_str = 'performance_options=(\n'
150 deploy_options = self['deploy_options']
151 for role, settings in deploy_options['performance'].items():
152 for category, options in settings.items():
153 for key, value in options.items():
154 bash_str += "\"{} {} {} {}\"\n".format(role,
160 bash_str += 'performance_roles=(\n'
161 for role in self['deploy_options']['performance']:
162 bash_str += role + '\n'
168 def _dump_deploy_options_array(self):
170 Creates deploy settings array in bash syntax.
173 for key, value in self['deploy_options'].items():
174 if not isinstance(value, bool):
175 bash_str += "deploy_options_array[{}]=\"{}\"\n".format(key,
178 bash_str += "deploy_options_array[{}]={}\n".format(key,
183 class DeploySettingsException(Exception):
184 def __init__(self, value):