5 class DeploymentEnvironmentAdapter(object):
6 def __init__(self, yaml_path):
8 self.parse_yaml(yaml_path)
9 self.network_names = []
10 self.collect_network_names()
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))
18 def parse_yaml(self, yaml_path):
19 with io.open(yaml_path) as yaml_file:
20 self.dea_struct = yaml.load(yaml_file)
22 def get_fuel_config(self):
23 return self.dea_struct['fuel']
25 def get_fuel_ip(self):
26 fuel_conf = self.get_fuel_config()
27 return fuel_conf['ADMIN_NETWORK']['ipaddress']
29 def get_fuel_netmask(self):
30 fuel_conf = self.get_fuel_config()
31 return fuel_conf['ADMIN_NETWORK']['netmask']
33 def get_fuel_gateway(self):
34 ip = self.get_fuel_ip()
35 return self.modify_ip(ip, 3, 1)
37 def get_fuel_hostname(self):
38 fuel_conf = self.get_fuel_config()
39 return fuel_conf['HOSTNAME']
41 def get_fuel_dns(self):
42 fuel_conf = self.get_fuel_config()
43 return fuel_conf['DNS_UPSTREAM']
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]
50 def get_node_role(self, node_id):
51 return self.get_node_property(node_id, 'role')
53 def get_node_ids(self):
55 for node in self.dea_struct['nodes']:
56 node_ids.append(node['id'])
59 def get_property(self, property_name):
60 return self.dea_struct[property_name]
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'])
67 def get_network_names(self):
68 return self.network_names
70 def get_interfaces(self, type):
71 return self.dea_struct['interfaces'][type]
73 def get_transformations(self, type):
74 return self.dea_struct['transformations'][type]
76 def get_opnfv(self, role):
77 return {'opnfv': self.dea_struct['opnfv'][role]}
79 def get_wanted_release(self):
80 return self.dea_struct['wanted_release']