Corrected links associated with release docs. To be updated along with the previous...
[genesis.git] / fuel / deploy / dea.py
1 import yaml
2 import io
3 import netaddr
4
5 class DeploymentEnvironmentAdapter(object):
6     def __init__(self, yaml_path):
7         self.dea_struct = None
8         self.parse_yaml(yaml_path)
9         self.network_names = []
10         self.collect_network_names()
11
12     def modify_ip(self, ip_addr, index, val):
13         ip_str = str(netaddr.IPAddress(ip_addr))
14         decimal_list = map(int, ip_str.split('.'))
15         decimal_list[index] = val
16         return '.'.join(map(str, decimal_list))
17
18     def parse_yaml(self, yaml_path):
19         with io.open(yaml_path) as yaml_file:
20             self.dea_struct = yaml.load(yaml_file)
21
22     def get_fuel_config(self):
23         return self.dea_struct['fuel']
24
25     def get_fuel_ip(self):
26         fuel_conf = self.get_fuel_config()
27         return fuel_conf['ADMIN_NETWORK']['ipaddress']
28
29     def get_fuel_netmask(self):
30         fuel_conf = self.get_fuel_config()
31         return fuel_conf['ADMIN_NETWORK']['netmask']
32
33     def get_fuel_gateway(self):
34         ip = self.get_fuel_ip()
35         return self.modify_ip(ip, 3, 1)
36
37     def get_fuel_hostname(self):
38         fuel_conf = self.get_fuel_config()
39         return fuel_conf['HOSTNAME']
40
41     def get_fuel_dns(self):
42         fuel_conf = self.get_fuel_config()
43         return fuel_conf['DNS_UPSTREAM']
44
45     def get_node_property(self, node_id, property_name):
46         for node in self.dea_struct['nodes']:
47             if node['id'] == node_id and property_name in node:
48                 return node[property_name]
49
50     def get_node_role(self, node_id):
51         return self.get_node_property(node_id, 'role')
52
53     def get_node_ids(self):
54         node_ids = []
55         for node in self.dea_struct['nodes']:
56             node_ids.append(node['id'])
57         return node_ids
58
59     def get_property(self, property_name):
60         return self.dea_struct[property_name]
61
62     def collect_network_names(self):
63         self.network_names = []
64         for network in self.dea_struct['network']['networks']:
65             self.network_names.append(network['name'])
66
67     def get_network_names(self):
68         return self.network_names
69
70     def get_interfaces(self, type):
71         return self.dea_struct['interfaces'][type]
72
73     def get_transformations(self, type):
74         return self.dea_struct['transformations'][type]
75
76     def get_opnfv(self, role):
77         return {'opnfv': self.dea_struct['opnfv'][role]}
78
79     def get_wanted_release(self):
80         return self.dea_struct['wanted_release']