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('Configure nodes')
27 for node_id, roles_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_blade[0]), self.env_id))
31 self.download_deployment_config()
32 for node_id, roles_blade in self.node_id_roles_dict.iteritems():
33 self.download_interface_config(node_id)
34 self.modify_node_interface(node_id, roles_blade)
35 self.modify_node_network_schemes(node_id, roles_blade)
36 self.upload_interface_config(node_id)
37 self.upload_deployment_config()
39 def modify_node_network_schemes(self, node_id, roles_blade):
40 log('Modify node network transformations in environment %s'
42 type = self.dea.get_node_property(roles_blade[1], 'transformations')
43 transformations = self.dea.get_transformations(type)
45 for node_file in glob.glob('%s/deployment_%s/*_%s.yaml'
46 % (self.yaml_config_dir, self.env_id,
48 with io.open(node_file) as stream:
49 node = yaml.load(stream)
51 node['network_scheme']['transformations'] = transformations
53 with io.open(node_file, 'w') as stream:
54 yaml.dump(node, stream, default_flow_style=False)
57 def download_deployment_config(self):
58 log('Download deployment config for environment %s' % self.env_id)
59 exec_cmd('fuel deployment --env %s --default --dir %s'
60 % (self.env_id, self.yaml_config_dir))
62 def upload_deployment_config(self):
63 log('Upload deployment config for environment %s' % self.env_id)
64 exec_cmd('fuel deployment --env %s --upload --dir %s'
65 % (self.env_id, self.yaml_config_dir))
67 def download_interface_config(self, node_id):
68 log('Download interface config for node %s' % node_id)
69 exec_cmd('fuel node --env %s --node %s --network --download '
70 '--dir %s' % (self.env_id, node_id, self.yaml_config_dir))
72 def upload_interface_config(self, node_id):
73 log('Upload interface config for node %s' % node_id)
74 exec_cmd('fuel node --env %s --node %s --network --upload '
75 '--dir %s' % (self.env_id, node_id, self.yaml_config_dir))
77 def modify_node_interface(self, node_id, roles_blade):
78 log('Modify interface config for node %s' % node_id)
79 interface_yaml = ('%s/node_%s/interfaces.yaml'
80 % (self.yaml_config_dir, node_id))
81 check_file_exists(interface_yaml)
83 with io.open(interface_yaml) as stream:
84 interfaces = yaml.load(stream)
87 for interface in interfaces:
88 for network in interface['assigned_networks']:
89 net_name_id[network['name']] = network['id']
91 type = self.dea.get_node_property(roles_blade[1], 'interfaces')
92 interface_config = self.dea.get_interfaces(type)
94 for interface in interfaces:
95 interface['assigned_networks'] = []
96 if interface['name'] in interface_config:
97 for net_name in interface_config[interface['name']]:
99 net['id'] = net_name_id[net_name]
100 net['name'] = net_name
101 interface['assigned_networks'].append(net)
103 with io.open(interface_yaml, 'w') as stream:
104 yaml.dump(interfaces, stream, default_flow_style=False)