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