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 Change-Id: I0457dc9a0d49e46b8ca85cfe7a4435c2b15f5238
23 Signed-off-by: Josep Puigdemont <josep.puigdemont@enea.com>
24 Signed-off-by: Alexandu Avadanii <alexandru.avadanii@enea.com>
26 deploy/transplant_fuel_settings.py | 37 +++++++++++++++++++++++++++++++++++++
27 1 file changed, 37 insertions(+)
29 diff --git a/deploy/transplant_fuel_settings.py b/deploy/transplant_fuel_settings.py
30 index e57a4fb..9a65cf6 100644
31 --- a/deploy/transplant_fuel_settings.py
32 +++ b/deploy/transplant_fuel_settings.py
39 from dea import DeploymentEnvironmentAdapter
47 ASTUTE_YAML = '/etc/fuel/astute.yaml'
48 @@ -35,15 +39,45 @@ def parse_arguments():
49 check_file_exists(dea_file)
52 +def write_ifcfg_file(key, fuel_conf):
53 + config = ('BOOTPROTO=none\n'
56 + 'NM_CONTROLLED=yes\n')
57 + for skey in ('ipaddress', 'device', 'netmask', 'gateway'):
58 + if not fuel_conf[key].get(skey):
59 + log('Warning: missing key %s for %s' % (skey, key))
60 + config += '%s=\n' % skey.upper()
61 + elif skey == 'ipaddress':
62 + config += 'IPADDR=%s\n' % fuel_conf[key][skey]
64 + config += '%s=%s\n' % (skey.upper(), fuel_conf[key][skey])
66 + fname = os.path.join('/etc/sysconfig/network-scripts/',
67 + key.lower().replace('_','-'))
68 + with open(fname, 'wc') as f:
71 def transplant(dea, astute):
72 fuel_conf = dea.get_fuel_config()
73 + require_network_restart = False
74 for key in fuel_conf.iterkeys():
75 if key == 'ADMIN_NETWORK':
76 for skey in fuel_conf[key].iterkeys():
77 astute[key][skey] = fuel_conf[key][skey]
78 + elif re.match('^IFCFG', key):
79 + log('Adding interface configuration for: %s' % key.lower())
80 + require_network_restart = True
81 + write_ifcfg_file(key, fuel_conf)
82 + if astute.has_key(key):
83 + astute.pop(key, None)
85 astute[key] = fuel_conf[key]
86 + if require_network_restart:
87 + admin_ifcfg = '/etc/sysconfig/network-scripts/ifcfg-eth0'
88 + exec_cmd('echo "DEFROUTE=no" >> %s' % admin_ifcfg)
89 + log('At least one interface was reconfigured, restart network manager')
90 + exec_cmd('systemctl restart network')
94 @@ -51,11 +85,14 @@ def main():
95 dea_file = parse_arguments()
96 check_file_exists(ASTUTE_YAML)
97 dea = DeploymentEnvironmentAdapter(dea_file)
98 + log('Reading astute file %s' % ASTUTE_YAML)
99 with io.open(ASTUTE_YAML) as stream:
100 astute = yaml.load(stream)
101 + log('Initiating transplant')
102 transplant(dea, astute)
103 with io.open(ASTUTE_YAML, 'w') as stream:
104 yaml.dump(astute, stream, default_flow_style=False)
105 + log('Transplant done')
108 if __name__ == '__main__':