blob: 3a124a92ea5982395f82e38a37e3e3a28b95f271 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
###############################################################################
# Copyright (c) 2015 Ericsson AB and others.
# szilard.cserey@ericsson.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
###############################################################################
import yaml
import io
import netaddr
class DeploymentEnvironmentAdapter(object):
def __init__(self, yaml_path):
self.dea_struct = None
self.parse_yaml(yaml_path)
self.network_names = []
self.collect_network_names()
def modify_ip(self, ip_addr, index, val):
ip_str = str(netaddr.IPAddress(ip_addr))
decimal_list = map(int, ip_str.split('.'))
decimal_list[index] = val
return '.'.join(map(str, decimal_list))
def parse_yaml(self, yaml_path):
with io.open(yaml_path) as yaml_file:
self.dea_struct = yaml.load(yaml_file)
def get_env_name(self):
return self.get_property('environment')['name']
def get_env_net_segment_type(self):
return self.get_property('environment')['net_segment_type']
def get_fuel_config(self):
return self.dea_struct['fuel']
def get_fuel_ip(self):
fuel_conf = self.get_fuel_config()
return fuel_conf['ADMIN_NETWORK']['ipaddress']
def get_fuel_netmask(self):
fuel_conf = self.get_fuel_config()
return fuel_conf['ADMIN_NETWORK']['netmask']
def get_fuel_gateway(self):
ip = self.get_fuel_ip()
return self.modify_ip(ip, 3, 1)
def get_fuel_hostname(self):
fuel_conf = self.get_fuel_config()
return fuel_conf['HOSTNAME']
def get_fuel_dns(self):
fuel_conf = self.get_fuel_config()
return fuel_conf['DNS_UPSTREAM
|