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',
37 VALID_ROLES = ['Controller', 'Compute', 'ObjectStorage']
38 VALID_PERF_OPTS = ['kernel', 'nova', 'vpp', 'ovs']
39 VALID_DATAPLANES = ['ovs', 'ovs_dpdk', 'fdio']
40 VALID_ODL_VERSIONS = ['carbon', 'nitrogen', 'master']
43 class DeploySettings(dict):
45 This class parses a APEX deploy settings yaml file into an object
47 def __init__(self, filename):
48 if isinstance(filename, str):
49 with open(filename, 'r') as deploy_settings_file:
50 init_dict = yaml.safe_load(deploy_settings_file)
52 # assume input is a dict to build from
55 super().__init__(init_dict)
56 self._validate_settings()
58 def _validate_settings(self):
60 Validates the deploy settings file provided
62 DeploySettingsException will be raised if validation fails.
65 if 'deploy_options' not in self:
66 raise DeploySettingsException("No deploy options provided in"
67 " deploy settings file")
68 if 'global_params' not in self:
69 raise DeploySettingsException("No global options provided in"
70 " deploy settings file")
72 deploy_options = self['deploy_options']
73 if not isinstance(deploy_options, dict):
74 raise DeploySettingsException("deploy_options should be a list")
76 if ('gluon' in self['deploy_options'] and
77 'vpn' in self['deploy_options']):
78 if (self['deploy_options']['gluon'] is True and
79 self['deploy_options']['vpn'] is False):
80 raise DeploySettingsException(
81 "Invalid deployment configuration: "
82 "If gluon is enabled, "
83 "vpn also needs to be enabled")
85 for setting, value in deploy_options.items():
86 if setting not in REQ_DEPLOY_SETTINGS + OPT_DEPLOY_SETTINGS:
87 raise DeploySettingsException("Invalid deploy_option {} "
88 "specified".format(setting))
89 if setting == 'dataplane':
90 if value not in VALID_DATAPLANES:
91 planes = ' '.join(VALID_DATAPLANES)
92 raise DeploySettingsException(
93 "Invalid dataplane {} specified. Valid dataplanes:"
94 " {}".format(value, planes))
96 for req_set in REQ_DEPLOY_SETTINGS:
97 if req_set not in deploy_options:
98 if req_set == 'dataplane':
99 self['deploy_options'][req_set] = 'ovs'
100 elif req_set == 'ceph':
101 self['deploy_options'][req_set] = True
102 elif req_set == 'odl_version':
103 self['deploy_options'][req_set] = \
104 constants.DEFAULT_ODL_VERSION
106 self['deploy_options'][req_set] = False
107 elif req_set == 'odl_version' and self['deploy_options'][
108 'odl_version'] not in VALID_ODL_VERSIONS:
109 raise DeploySettingsException(
110 "Invalid ODL version: {}".format(self[deploy_options][
113 if 'performance' in deploy_options:
114 if not isinstance(deploy_options['performance'], dict):
115 raise DeploySettingsException("Performance deploy_option"
116 "must be a dictionary.")
117 for role, role_perf_sets in deploy_options['performance'].items():
118 if role not in VALID_ROLES:
119 raise DeploySettingsException("Performance role {}"
120 "is not valid, choose"
123 " ".join(VALID_ROLES)
126 for key in role_perf_sets:
127 if key not in VALID_PERF_OPTS:
128 raise DeploySettingsException("Performance option {} "
129 "is not valid, choose"
136 def _dump_performance(self):
138 Creates performance settings string for bash consumption.
140 Output will be in the form of a list that can be iterated over in
141 bash, with each string being the direct input to the performance
142 setting script in the form <role> <category> <key> <value> to
143 facilitate modification of the correct image.
145 bash_str = 'performance_options=(\n'
146 deploy_options = self['deploy_options']
147 for role, settings in deploy_options['performance'].items():
148 for category, options in settings.items():
149 for key, value in options.items():
150 bash_str += "\"{} {} {} {}\"\n".format(role,
156 bash_str += 'performance_roles=(\n'
157 for role in self['deploy_options']['performance']:
158 bash_str += role + '\n'
164 def _dump_deploy_options_array(self):
166 Creates deploy settings array in bash syntax.
169 for key, value in self['deploy_options'].items():
170 if not isinstance(value, bool):
171 bash_str += "deploy_options_array[{}]=\"{}\"\n".format(key,
174 bash_str += "deploy_options_array[{}]={}\n".format(key,
179 class DeploySettingsException(Exception):
180 def __init__(self, value):