1 From: Josep Puigdemont <josep.puigdemont@enea.com>
2 Date: Wed, 4 May 2016 17:58:56 +0200
3 Subject: [PATCH] transplant: Generate extra interfaces config file
5 The DEA override may contain a IFCGF_<interface> section in its 'fuel:'
6 section, containing the necessary keys to produce a ifcfg-<interface>
7 file, like in this example:
13 netmask: 255.255.255.0
16 FIXME: In order for Network Manager to use the newly added interfaces
17 for outgoing traffic and honor their GATEWAY setting (e.g. if we just
18 added one public interface), the default route on admin iface (most of
19 the time called eth0) should be disabled. For now, we assume the admin
20 interface is always "eth0".
22 Signed-off-by: Josep Puigdemont <josep.puigdemont@enea.com>
23 Signed-off-by: Alexandu Avadanii <alexandru.avadanii@enea.com>
25 deploy/transplant_fuel_settings.py | 37 +++++++++++++++++++++++++++++++++++++
26 1 file changed, 37 insertions(+)
28 diff --git a/deploy/transplant_fuel_settings.py b/deploy/transplant_fuel_settings.py
29 index e57a4fb..9a65cf6 100644
30 --- a/deploy/transplant_fuel_settings.py
31 +++ b/deploy/transplant_fuel_settings.py
38 from dea import DeploymentEnvironmentAdapter
46 ASTUTE_YAML = '/etc/fuel/astute.yaml'
47 @@ -35,15 +39,45 @@ def parse_arguments():
48 check_file_exists(dea_file)
51 +def write_ifcfg_file(key, fuel_conf):
52 + config = ('BOOTPROTO=none\n'
55 + 'NM_CONTROLLED=yes\n')
56 + for skey in ('ipaddress', 'device', 'netmask', 'gateway'):
57 + if not fuel_conf[key].get(skey):
58 + log('Warning: missing key %s for %s' % (skey, key))
59 + config += '%s=\n' % skey.upper()
60 + elif skey == 'ipaddress':
61 + config += 'IPADDR=%s\n' % fuel_conf[key][skey]
63 + config += '%s=%s\n' % (skey.upper(), fuel_conf[key][skey])
65 + fname = os.path.join('/etc/sysconfig/network-scripts/',
66 + key.lower().replace('_','-'))
67 + with open(fname, 'wc') as f:
70 def transplant(dea, astute):
71 fuel_conf = dea.get_fuel_config()
72 + require_network_restart = False
73 for key in fuel_conf.iterkeys():
74 if key == 'ADMIN_NETWORK':
75 for skey in fuel_conf[key].iterkeys():
76 astute[key][skey] = fuel_conf[key][skey]
77 + elif re.match('^IFCFG', key):
78 + log('Adding interface configuration for: %s' % key.lower())
79 + require_network_restart = True
80 + write_ifcfg_file(key, fuel_conf)
81 + if astute.has_key(key):
82 + astute.pop(key, None)
84 astute[key] = fuel_conf[key]
85 + if require_network_restart:
86 + admin_ifcfg = '/etc/sysconfig/network-scripts/ifcfg-eth0'
87 + exec_cmd('echo "DEFROUTE=no" >> %s' % admin_ifcfg)
88 + log('At least one interface was reconfigured, restart network manager')
89 + exec_cmd('systemctl restart network')
93 @@ -51,11 +85,14 @@ def main():
94 dea_file = parse_arguments()
95 check_file_exists(ASTUTE_YAML)
96 dea = DeploymentEnvironmentAdapter(dea_file)
97 + log('Reading astute file %s' % ASTUTE_YAML)
98 with io.open(ASTUTE_YAML) as stream:
99 astute = yaml.load(stream)
100 + log('Initiating transplant')
101 transplant(dea, astute)
102 with io.open(ASTUTE_YAML, 'w') as stream:
103 yaml.dump(astute, stream, default_flow_style=False)
104 + log('Transplant done')
107 if __name__ == '__main__':