Migrates Apex to Python
[apex.git] / apex / settings / deploy_settings.py
similarity index 92%
rename from lib/python/apex/deploy_settings.py
rename to apex/settings/deploy_settings.py
index 0618594..c8e347b 100644 (file)
@@ -9,9 +9,9 @@
 
 
 import yaml
-import logging
 
-from .common import utils
+from apex.common import utils
+from apex.common import constants
 
 REQ_DEPLOY_SETTINGS = ['sdn_controller',
                        'odl_version',
@@ -37,6 +37,7 @@ OPT_DEPLOY_SETTINGS = ['performance',
 VALID_ROLES = ['Controller', 'Compute', 'ObjectStorage']
 VALID_PERF_OPTS = ['kernel', 'nova', 'vpp', 'ovs']
 VALID_DATAPLANES = ['ovs', 'ovs_dpdk', 'fdio']
+VALID_ODL_VERSIONS = ['carbon', 'nitrogen', 'master']
 
 
 class DeploySettings(dict):
@@ -48,7 +49,6 @@ class DeploySettings(dict):
     deployment script move to python.
     """
     def __init__(self, filename):
-        init_dict = {}
         if isinstance(filename, str):
             with open(filename, 'r') as deploy_settings_file:
                 init_dict = yaml.safe_load(deploy_settings_file)
@@ -103,8 +103,16 @@ class DeploySettings(dict):
                     self['deploy_options'][req_set] = 'ovs'
                 elif req_set == 'ceph':
                     self['deploy_options'][req_set] = True
+                elif req_set == 'odl_version':
+                    self['deploy_options'][req_set] = \
+                        constants.DEFAULT_ODL_VERSION
                 else:
                     self['deploy_options'][req_set] = False
+            elif req_set == 'odl_version' and self['deploy_options'][
+                    'odl_version'] not in VALID_ODL_VERSIONS:
+                raise DeploySettingsException(
+                    "Invalid ODL version: {}".format(self[deploy_options][
+                        'odl_version']))
 
         if 'performance' in deploy_options:
             if not isinstance(deploy_options['performance'], dict):
@@ -171,21 +179,6 @@ class DeploySettings(dict):
                                                                    value)
         return bash_str
 
-    def dump_bash(self, path=None):
-        """
-        Prints settings for bash consumption.
-
-        If optional path is provided, bash string will be written to the file
-        instead of stdout.
-        """
-        bash_str = ''
-        for key, value in self['global_params'].items():
-            bash_str += "{}={}\n".format(key, value)
-        if 'performance' in self['deploy_options']:
-            bash_str += self._dump_performance()
-        bash_str += self._dump_deploy_options_array()
-        utils.write_str(bash_str, path)
-
 
 class DeploySettingsException(Exception):
     def __init__(self, value):