Merge "vswitchperf: Arch-indep build."
[armband.git] / patches / opnfv-fuel / 0005-transplant-Generate-extra-interfaces-config-file.patch
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
5
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:
9
10 fuel:
11    IFCFG_ETH1:
12      device: eth1
13      ipaddress: 10.0.1.10
14      netmask: 255.255.255.0
15      gateway: 10.0.1.254
16
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".
22
23 Change-Id: I0457dc9a0d49e46b8ca85cfe7a4435c2b15f5238
24 Signed-off-by: Josep Puigdemont <josep.puigdemont@enea.com>
25 Signed-off-by: Alexandu Avadanii <alexandru.avadanii@enea.com>
26 ---
27  deploy/transplant_fuel_settings.py | 37 +++++++++++++++++++++++++++++++++++++
28  1 file changed, 37 insertions(+)
29
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
34 @@ -11,10 +11,14 @@
35  import sys
36  import io
37  import yaml
38 +import re
39 +import os
40  from dea import DeploymentEnvironmentAdapter
41  
42  from common import (
43      check_file_exists,
44 +    exec_cmd,
45 +    log,
46  )
47  
48  ASTUTE_YAML = '/etc/fuel/astute.yaml'
49 @@ -35,15 +39,45 @@ def parse_arguments():
50      check_file_exists(dea_file)
51      return dea_file
52  
53 +def write_ifcfg_file(key, fuel_conf):
54 +    config = ('BOOTPROTO=none\n'
55 +              'ONBOOT=yes\n'
56 +              'TYPE=Ethernet\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]
64 +        else:
65 +            config += '%s=%s\n' % (skey.upper(), fuel_conf[key][skey])
66 +
67 +    fname = os.path.join('/etc/sysconfig/network-scripts/',
68 +                         key.lower().replace('_','-'))
69 +    with open(fname, 'wc') as f:
70 +        f.write(config)
71  
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)
85          else:
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')
92      return astute
93  
94  
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')
107  
108  
109  if __name__ == '__main__':
110 -- 
111 2.5.5
112