10 exec_cmd = common.exec_cmd
13 check_file_exists = common.check_file_exists
17 class ConfigureNodes(object):
19 def __init__(self, yaml_config_dir, env_id, node_id_roles_dict, dea):
20 self.yaml_config_dir = yaml_config_dir
22 self.node_id_roles_dict = node_id_roles_dict
25 def config_nodes(self):
26 LOG.debug('Configure nodes\n')
27 for node_id, roles_shelf_blade in self.node_id_roles_dict.iteritems():
28 exec_cmd('fuel node set --node-id %s --role %s --env %s'
29 % (node_id, ','.join(roles_shelf_blade[0]), self.env_id))
31 self.download_deployment_config()
32 self.modify_node_network_schemes()
33 self.upload_deployment_config()
35 for node_id, roles_shelf_blade in self.node_id_roles_dict.iteritems():
36 self.download_interface_config(node_id)
37 self.modify_node_interface(node_id)
38 self.upload_interface_config(node_id)
40 def modify_node_network_schemes(self):
41 LOG.debug('Modify node network schemes in environment %s\n' % self.env_id)
42 for node_file in glob.glob('%s/deployment_%s/*.yaml'
43 % (self.yaml_config_dir, self.env_id)):
44 check_file_exists(node_file)
46 if 'compute' in node_file:
49 node_type = 'controller'
51 network_scheme = self.dea.get_network_scheme(node_type)
53 with io.open(node_file) as stream:
54 node = yaml.load(stream)
56 node['network_scheme']['transformations'] = network_scheme
58 with io.open(node_file, 'w') as stream:
59 yaml.dump(node, stream, default_flow_style=False)
62 def download_deployment_config(self):
63 LOG.debug('Download deployment config for environment %s\n' % self.env_id)
64 r, c = exec_cmd('fuel deployment --env %s --default --dir %s'
65 % (self.env_id, self.yaml_config_dir))
67 def upload_deployment_config(self):
68 LOG.debug('Upload deployment config for environment %s\n' % self.env_id)
69 r, c = exec_cmd('fuel deployment --env %s --upload --dir %s'
70 % (self.env_id, self.yaml_config_dir))
72 def download_interface_config(self, node_id):
73 LOG.debug('Download interface config for node %s\n' % node_id)
74 r, c = exec_cmd('fuel node --env %s --node %s --network --download '
75 '--dir %s' % (self.env_id, node_id,
76 self.yaml_config_dir))
78 def upload_interface_config(self, node_id):
79 LOG.debug('Upload interface config for node %s\n' % node_id)
80 r, c = exec_cmd('fuel node --env %s --node %s --network --upload '
81 '--dir %s' % (self.env_id, node_id,
82 self.yaml_config_dir))
84 def modify_node_interface(self, node_id):
85 LOG.debug('Modify interface config for node %s\n' % node_id)
86 interface_yaml = (self.yaml_config_dir + '/node_%s/interfaces.yaml'
89 with io.open(interface_yaml) as stream:
90 interfaces = yaml.load(stream)
93 for interface in interfaces:
94 for network in interface['assigned_networks']:
95 net_name_id[network['name']] = network['id']
97 interface_config = self.dea.get_interfaces()
99 for interface in interfaces:
100 interface['assigned_networks'] = []
101 for net_name in interface_config[interface['name']]:
103 net['id'] = net_name_id[net_name]
104 net['name'] = net_name
105 interface['assigned_networks'].append(net)
107 with io.open(interface_yaml, 'w') as stream:
108 yaml.dump(interfaces, stream, default_flow_style=False)