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, 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 network transformations for node %s' % node_id)
41 type = self.dea.get_node_property(roles_blade[1], 'transformations')
42 transformations = self.dea.get_transformations(type)
44 for node_file in glob.glob('%s/deployment_%s/*_%s.yaml'
45 % (self.yaml_config_dir, self.env_id,
47 with io.open(node_file) as stream:
48 node = yaml.load(stream)
50 node['network_scheme']['transformations'] = transformations
52 with io.open(node_file, 'w') as stream:
53 yaml.dump(node, stream, default_flow_style=False)
55 def download_deployment_config(self):
56 log('Download deployment config for environment %s' % self.env_id)
57 exec_cmd('fuel deployment --env %s --default --dir %s'
58 % (self.env_id, self.yaml_config_dir))
60 def upload_deployment_config(self):
61 log('Upload deployment config for environment %s' % self.env_id)
62 exec_cmd('fuel deployment --env %s --upload --dir %s'
63 % (self.env_id, self.yaml_config_dir))
65 def download_interface_config(self, node_id):
66 log('Download interface config for node %s' % node_id)
67 exec_cmd('fuel node --env %s --node %s --network --download '
68 '--dir %s' % (self.env_id, node_id, self.yaml_config_dir))
70 def upload_interface_config(self, node_id):
71 log('Upload interface config for node %s' % node_id)
72 exec_cmd('fuel node --env %s --node %s --network --upload '
73 '--dir %s' % (self.env_id, node_id, self.yaml_config_dir))
75 def modify_node_interface(self, node_id, roles_blade):
76 log('Modify interface config for node %s' % node_id)
77 interface_yaml = ('%s/node_%s/interfaces.yaml'
78 % (self.yaml_config_dir, node_id))
79 check_file_exists(interface_yaml)
81 with io.open(interface_yaml) as stream:
82 interfaces = yaml.load(stream)
85 for interface in interfaces:
86 for network in interface['assigned_networks']:
87 net_name_id[network['name']] = network['id']
89 type = self.dea.get_node_property(roles_blade[1], 'interfaces')
90 interface_config = self.dea.get_interfaces(type)
92 for interface in interfaces:
93 interface['assigned_networks'] = []
94 if interface['name'] in interface_config:
95 for net_name in interface_config[interface['name']]:
97 net['id'] = net_name_id[net_name]
98 net['name'] = net_name
99 interface['assigned_networks'].append(net)
101 with io.open(interface_yaml, 'w') as stream:
102 yaml.dump(interfaces, stream, default_flow_style=False)