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 ##############################################################################
14 REQ_DEPLOY_SETTINGS = ['sdn_controller',
24 OPT_DEPLOY_SETTINGS = ['performance']
26 VALID_ROLES = ['Controller', 'Compute', 'ObjectStorage']
27 VALID_PERF_OPTS = ['kernel','nova']
28 VALID_DATAPLANES = ['ovs','ovs_dpdk','fdio']
32 This class parses a APEX deploy settings yaml file into an object
34 Currently the parsed object is dumped into a bash global definition file
35 for deploy.sh consumption. This object will later be used directly as
36 deployment script move to python.
38 def __init__(self, filename):
39 with open(filename, 'r') as settings_file:
40 self.deploy_settings = yaml.load(settings_file)
41 self._validate_settings()
43 def _validate_settings(self):
45 Validates the deploy settings file provided
47 DeploySettingsException will be raised if validation fails.
50 if 'deploy_options' not in self.deploy_settings:
51 raise DeploySettingsException("No deploy options provided in"
52 " deploy settings file")
53 if 'global_params' not in self.deploy_settings:
54 raise DeploySettingsException("No global options provided in"
55 " deploy settings file")
57 deploy_options = self.deploy_settings['deploy_options']
58 if not isinstance(deploy_options, dict):
59 raise DeploySettingsException("deploy_options should be a list")
61 for setting, value in deploy_options.items():
62 if setting not in REQ_DEPLOY_SETTINGS + OPT_DEPLOY_SETTINGS:
63 raise DeploySettingsException("Invalid deploy_option {} "
64 "specified".format(setting))
65 if setting == 'dataplane':
66 if value not in VALID_DATAPLANES:
67 planes = ' '.join(VALID_DATAPLANES)
68 raise DeploySettingsException("Invalid dataplane {} "
69 "specified. Valid dataplanes:"
70 " {}".format(value,planes))
72 for req_set in REQ_DEPLOY_SETTINGS:
73 if req_set not in deploy_options:
74 if req_set == 'dataplane':
75 self.deploy_settings['deploy_options'][req_set] = 'ovs'
77 self.deploy_settings['deploy_options'][req_set] = False
79 if 'performance' in deploy_options:
80 if not isinstance(deploy_options['performance'], dict):
81 raise DeploySettingsException("Performance deploy_option"
82 "must be a dictionary.")
83 for role,role_perf_sets in deploy_options['performance'].items():
84 if role not in VALID_ROLES:
85 raise DeploySettingsException("Performance role {}"
86 "is not valid, choose"
88 role," ".join(VALID_ROLES)
91 for key in role_perf_sets:
92 if key not in VALID_PERF_OPTS:
93 raise DeploySettingsException("Performance option {}"
94 "is not valid, choose"
100 def _dump_performance(self):
102 Creates performance settings string for bash consumption.
104 Output will be in the form of a list that can be iterated over in bash,
105 with each string being the direct input to the performance setting script
106 in the form <role> <category> <key> <value> to facilitate modification of the
109 bash_str = 'performance_options=(\n'
110 for role,settings in self.deploy_settings['deploy_options']['performance'].items():
111 for category,options in settings.items():
112 for key,value in options.items():
113 bash_str += "\"{} {} {} {}\"\n".format(role, category, key, value)
116 bash_str += 'performance_roles=(\n'
117 for role in self.deploy_settings['deploy_options']['performance']:
118 bash_str += role + '\n'
124 def _dump_deploy_options_array(self):
126 Creates deploy settings array in bash syntax.
129 for key,value in self.deploy_settings['deploy_options'].items():
130 if not isinstance(value, bool):
131 bash_str += "deploy_options_array[{}]=\"{}\"\n".format(key, value)
133 bash_str += "deploy_options_array[{}]={}\n".format(key, value)
136 def dump_bash(self, path=None):
138 Prints settings for bash consumption.
140 If optional path is provided, bash string will be written to the file
144 for key, value in self.deploy_settings['global_params'].items():
145 bash_str += "{}={}\n".format(key, value)
146 if 'performance' in self.deploy_settings['deploy_options']:
147 bash_str += self._dump_performance()
148 bash_str += self._dump_deploy_options_array()
151 with open(path, 'w') as file:
157 class DeploySettingsException(Exception):
158 def __init__(self, value):