Merge "Fix ssl cert upload path"
[fuel.git] / deploy / cloud / configure_nodes.py
index 20ecc17..a50973a 100644 (file)
@@ -8,7 +8,6 @@
 ###############################################################################
 
 import copy
-import glob
 import io
 
 import six
@@ -33,36 +32,31 @@ class ConfigureNodes(object):
     def config_nodes(self):
         log('Configure nodes')
 
-        # Super dirty fix since Fuel 7 requires user defined roles to be
-        # assigned before anything else (BUG fixed in Fuel 8)!
+        # Assign nodes to environment with given roles
         for node_id, roles_blade in self.node_id_roles_dict.iteritems():
-            if "opendaylight" in roles_blade[0] or "onos" in roles_blade[0] or "contrail" in roles_blade[0]:
-                exec_cmd('fuel node set --node-id %s --role %s --env %s'
-                         % (node_id, roles_blade[0], self.env_id))
+            exec_cmd('fuel node set --node-id %s --role %s --env %s'
+                     % (node_id, roles_blade[0], self.env_id))
 
         for node_id, roles_blade in self.node_id_roles_dict.iteritems():
-            if "opendaylight" not in roles_blade[0] and "onos" not in roles_blade[0] and "contrail" not in roles_blade[0]:
-                exec_cmd('fuel node set --node-id %s --role %s --env %s'
-                         % (node_id, roles_blade[0], self.env_id))
-
-        # Download the unmodified default deployment configuration, because we
-        # need it for the network config.
-        self.download_deployment_config()
-        for node_id, roles_blade in self.node_id_roles_dict.iteritems():
-            # Modify node attributes
-            self.download_attributes(node_id)
-            self.modify_node_attributes(node_id, roles_blade)
-            self.upload_attributes(node_id)
             # Modify interfaces configuration
             self.download_interface_config(node_id)
             self.modify_node_interface(node_id, roles_blade)
-            self.modify_node_network_schemes(node_id, roles_blade)
             self.upload_interface_config(node_id)
+            # Modify node attributes
+            self.download_attributes(node_id)
+            self.modify_node_attributes(node_id, roles_blade)
+            self.upload_attributes(node_id)
 
+        # Currently not used, we use default deployment facts
+        # which are generated by fuel based on type segmentation
+        # and network to nic assignment
+        #
         # Download our modified deployment configuration, which includes our
         # changes to network topology etc.
-        self.download_deployment_config()
-        self.upload_deployment_config()
+        #self.download_deployment_config()
+        #for node_id, roles_blade in self.node_id_roles_dict.iteritems():
+        #    self.modify_node_network_schemes(node_id, roles_blade)
+        #self.upload_deployment_config()
 
     def modify_node_network_schemes(self, node_id, roles_blade):
         log('Modify network transformations for node %s' % node_id)
@@ -71,14 +65,14 @@ class ConfigureNodes(object):
         deployment_dir = '%s/deployment_%s' % (
             self.yaml_config_dir, self.env_id)
         backup(deployment_dir)
-        for node_file in glob.glob(deployment_dir + '/*_%s.yaml' % node_id):
-            with io.open(node_file) as stream:
-                node = yaml.load(stream)
+        node_file = ('%s/%s.yaml' % (deployment_dir, node_id))
+        with io.open(node_file) as stream:
+            node = yaml.load(stream)
 
-            node['network_scheme'].update(transformations)
+        node['network_scheme'].update(transformations)
 
-            with io.open(node_file, 'w') as stream:
-                yaml.dump(node, stream, default_flow_style=False)
+        with io.open(node_file, 'w') as stream:
+            yaml.dump(node, stream, default_flow_style=False)
 
     def download_deployment_config(self):
         log('Download deployment config for environment %s' % self.env_id)
@@ -129,6 +123,23 @@ class ConfigureNodes(object):
         with open(attributes_yaml, 'w') as stream:
             yaml.dump(result_attributes, stream, default_flow_style=False)
 
+    # interface configuration can
+    # looks like this:
+    #
+    # interfaces_dpdk:
+    #   ens3:
+    #   - fuelweb_admin
+    #   ens4:
+    #   - storage
+    #   - management
+    #   ens5:
+    #   - interface_properties:
+    #       dpdk:
+    #         enabled:
+    #           value: true
+    #   - private
+    #   ens6:
+    #   - public
     def modify_node_interface(self, node_id, roles_blade):
         log('Modify interface config for node %s' % node_id)
         interface_yaml = ('%s/node_%s/interfaces.yaml'
@@ -150,11 +161,21 @@ class ConfigureNodes(object):
         for interface in interfaces:
             interface['assigned_networks'] = []
             if interface['name'] in interface_config:
-                for net_name in interface_config[interface['name']]:
+                for prop in interface_config[interface['name']]:
                     net = {}
-                    net['id'] = net_name_id[net_name]
-                    net['name'] = net_name
-                    interface['assigned_networks'].append(net)
+                    # net name
+                    if isinstance(prop, six.string_types):
+                        net['id'] = net_name_id[prop]
+                        net['name'] = prop
+                        interface['assigned_networks'].append(net)
+                    # network properties
+                    elif isinstance(prop, dict):
+                        if 'interface_properties' not in prop:
+                            log('Interface configuration contains unknown dict: %s' % prop)
+                            continue
+                        interface['attributes'] = self._merge_dicts(
+                            interface.get('attributes', {}),
+                            prop.get('interface_properties', {}))
 
         with io.open(interface_yaml, 'w') as stream:
             yaml.dump(interfaces, stream, default_flow_style=False)
@@ -171,4 +192,3 @@ class ConfigureNodes(object):
                 continue
             result[k] = copy.deepcopy(v)
         return result
-