1 ###############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 # szilard.cserey@ericsson.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ###############################################################################
16 class DeploymentEnvironmentAdapter(object):
18 def __init__(self, yaml_path):
19 self.dea_struct = None
20 self.parse_yaml(yaml_path)
21 self.network_names = []
22 self.collect_network_names()
24 def modify_ip(self, ip_addr, index, val):
25 ip_str = str(netaddr.IPAddress(ip_addr))
26 decimal_list = map(int, ip_str.split('.'))
27 decimal_list[index] = val
28 return '.'.join(map(str, decimal_list))
30 def parse_yaml(self, yaml_path):
31 with io.open(yaml_path) as yaml_file:
32 self.dea_struct = yaml.load(yaml_file)
34 def get_env_name(self):
35 return self.get_property('environment')['name']
37 def get_env_net_segment_type(self):
38 return self.get_property('environment')['net_segment_type']
40 def get_fuel_config(self):
41 return self.dea_struct['fuel']
43 def get_fuel_ip(self):
44 fuel_conf = self.get_fuel_config()
45 return fuel_conf['ADMIN_NETWORK']['ipaddress']
47 def get_fuel_netmask(self):
48 fuel_conf = self.get_fuel_config()
49 return fuel_conf['ADMIN_NETWORK']['netmask']
51 def get_fuel_gateway(self):
52 ip = self.get_fuel_ip()
53 return self.modify_ip(ip, 3, 1)
55 def get_fuel_hostname(self):
56 fuel_conf = self.get_fuel_config()
57 return fuel_conf['HOSTNAME']
59 def get_fuel_dns(self):
60 fuel_conf = self.get_fuel_config()
61 return fuel_conf['DNS_UPSTREAM']
63 def get_node_property(self, node_id, property_name):
64 for node in self.dea_struct['nodes']:
65 if node['id'] == node_id and property_name in node:
66 return node[property_name]
68 def get_node_roles(self, node_id):
69 return self.get_node_property(node_id, 'role')
71 def get_node_main_role(self, node_id, fuel_node_id):
72 if node_id == fuel_node_id:
74 roles = self.get_node_roles(node_id)
75 return 'controller' if 'controller' in roles else 'compute'
77 def get_node_ids(self):
79 for node in self.dea_struct['nodes']:
80 node_ids.append(node['id'])
83 def get_property(self, property_name):
84 return self.dea_struct[property_name]
86 def collect_network_names(self):
87 self.network_names = []
88 for network in self.dea_struct['network']['networks']:
89 self.network_names.append(network['name'])
91 def get_network_names(self):
92 return self.network_names
94 def get_dns_list(self):
95 settings = self.get_property('settings')
96 dns_list = settings['editable']['external_dns']['dns_list']['value']
97 return [d.strip() for d in dns_list.split(',')]
99 def get_ntp_list(self):
100 settings = self.get_property('settings')
101 ntp_list = settings['editable']['external_ntp']['ntp_list']['value']
102 return [n.strip() for n in ntp_list.split(',')]
104 def get_blade_node_map(self):
105 return self.dea_struct['blade_node_map']