9ed79cc430f4da56e74e4c1c5abdc71984debc59
[armband.git] / patches / opnfv-fuel / 0008-deploy-reap.py-Dump-extra-interfaces-information.patch
1 From e8232eca62d67c2bac1d34f5b2adfeba1a580634 Mon Sep 17 00:00:00 2001
2 From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
3 Date: Wed, 4 May 2016 18:31:09 +0200
4 Subject: [PATCH] deploy/reap.py: Dump extra interfaces information.
5
6 Since on AArch64, Ubuntu local mirror lacks arm64 packages (see [1]),
7 Fuel master requires internet connectivity during deploy, and hence
8 a way to setup such a public (extra) interface automatically.
9
10 Previous commit "transplant: Generate extra interfaces config file"
11 introduced support for passing this information via DEA (override),
12 which may define a IFCGF_<interface> section in its 'fuel:'
13 section, containing the necessary keys to produce a ifcfg-<interface>
14 file, like in this example:
15
16 fuel:
17    IFCFG_ETH1:
18      device: eth1
19      ipaddress: 10.0.1.10
20      netmask: 255.255.255.0
21      gateway: 10.0.1.254
22
23 In order for Network Manager to use the newly added interfaces
24 for outgoing traffic and honor their GATEWAY setting (e.g. if we just
25 added one public interface), the default route on admin iface (most of
26 the time called eth0) is disabled when extra interfaces are present.
27
28 FIXME: Only supports lowercase interface names, but so does Fuel,
29 see related bug report [2].
30
31 [1] https://jira.opnfv.org/browse/ARMBAND-35
32 [2] https://jira.opnfv.org/browse/FUEL-136
33
34 Change-Id: I6f0a759c65a435ec8bd883a04c8d1adca109cc13
35 Signed-off-by: Alexandu Avadanii <alexandru.avadanii@enea.com>
36 Signed-off-by: Josep Puigdemont <josep.puigdemont@enea.com>
37 ---
38  deploy/reap.py | 34 ++++++++++++++++++++++++++++++++++
39  1 file changed, 34 insertions(+)
40
41 diff --git a/deploy/reap.py b/deploy/reap.py
42 index ed5bc99..9f14e35 100644
43 --- a/deploy/reap.py
44 +++ b/deploy/reap.py
45 @@ -15,6 +15,8 @@ import yaml
46  import glob
47  import shutil
48  import tempfile
49 +import re
50 +import netaddr
51  
52  from common import (
53      N,
54 @@ -248,6 +250,40 @@ class Reap(object):
55              if key not in ['ipaddress', 'netmask',
56                             'dhcp_pool_start', 'dhcp_pool_end', 'ssh_network']:
57                  del fuel['ADMIN_NETWORK'][key]
58 +
59 +        ## FIXME(armband): Factor in support for adding public/other interfaces.
60 +        ## TODO: Following block expects interface name(s) to be lowercase only
61 +        interfaces_list = exec_cmd('ip -o -4 a | grep -e "e[nt][hopsx].*"')
62 +        for interface in re.split('\n', interfaces_list):
63 +            # Sample output line from above cmd:
64 +            # 3: eth1 inet 10.0.2.10/24 scope global eth1 valid_lft forever ...
65 +            ifcfg = re.split(r'\s+', interface)
66 +            ifcfg_name = ifcfg[1]
67 +            ifcfg_ipaddr = ifcfg[3]
68 +
69 +            # Filter out admin interface (device name is not known, match IP)
70 +            current_network = netaddr.IPNetwork(ifcfg_ipaddr)
71 +            if str(current_network.ip) == fuel['ADMIN_NETWORK']['ipaddress']:
72 +                continue
73 +
74 +            # Read ifcfg-* network interface config file, write IFCFG_<IFNAME>
75 +            ifcfg_sec = 'IFCFG_%s' % ifcfg_name.upper()
76 +            fuel[ifcfg_sec] = {}
77 +            ifcfg_data = {}
78 +            ifcfg_f = ('/etc/sysconfig/network-scripts/ifcfg-%s' % ifcfg_name)
79 +            with open(ifcfg_f) as f:
80 +                for line in f:
81 +                    if line.startswith('#'):
82 +                        continue
83 +                    (key, val) = line.split('=')
84 +                    ifcfg_data[key.lower()] = val.rstrip()
85 +
86 +            # Keep only needed info (e.g. filter-out type=Ethernet).
87 +            fuel[ifcfg_sec]['ipaddress'] = ifcfg_data['ipaddr']
88 +            fuel[ifcfg_sec]['device'] = ifcfg_data['device']
89 +            fuel[ifcfg_sec]['netmask'] = str(current_network.netmask)
90 +            fuel[ifcfg_sec]['gateway'] = ifcfg_data['gateway']
91 +
92          self.write_yaml(self.dea_file, {'fuel': fuel})
93  
94      def reap_network_settings(self):
95 -- 
96 2.5.5
97