summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--deploy/reap.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/deploy/reap.py b/deploy/reap.py
index 7d996314b..eb02fe25d 100644
--- a/deploy/reap.py
+++ b/deploy/reap.py
@@ -16,6 +16,8 @@ import yaml
import glob
import shutil
import tempfile
+import re
+import netaddr
from common import (
N,
@@ -253,6 +255,40 @@ class Reap(object):
if key not in ['ipaddress', 'netmask',
'dhcp_pool_start', 'dhcp_pool_end', 'ssh_network']:
del fuel['ADMIN_NETWORK'][key]
+
+ ## FIXME(armband): Factor in support for adding public/other interfaces.
+ ## TODO: Following block expects interface name(s) to be lowercase only
+ interfaces_list = exec_cmd('ip -o -4 a | grep -e "e[nt][hopsx].*"')
+ for interface in re.split('\n', interfaces_list):
+ # Sample output line from above cmd:
+ # 3: eth1 inet 10.0.2.10/24 scope global eth1 valid_lft forever ...
+ ifcfg = re.split(r'\s+', interface)
+ ifcfg_name = ifcfg[1]
+ ifcfg_ipaddr = ifcfg[3]
+
+ # Filter out admin interface (device name is not known, match IP)
+ current_network = netaddr.IPNetwork(ifcfg_ipaddr)
+ if str(current_network.ip) == fuel['ADMIN_NETWORK']['ipaddress']:
+ continue
+
+ # Read ifcfg-* network interface config file, write IFCFG_<IFNAME>
+ ifcfg_sec = 'IFCFG_%s' % ifcfg_name.upper()
+ fuel[ifcfg_sec] = {}
+ ifcfg_data = {}
+ ifcfg_f = ('/etc/sysconfig/network-scripts/ifcfg-%s' % ifcfg_name)
+ with open(ifcfg_f) as f:
+ for line in f:
+ if line.startswith('#'):
+ continue
+ (key, val) = line.split('=')
+ ifcfg_data[key.lower()] = val.rstrip()
+
+ # Keep only needed info (e.g. filter-out type=Ethernet).
+ fuel[ifcfg_sec]['ipaddress'] = ifcfg_data['ipaddr']
+ fuel[ifcfg_sec]['device'] = ifcfg_data['device']
+ fuel[ifcfg_sec]['netmask'] = str(current_network.netmask)
+ fuel[ifcfg_sec]['gateway'] = ifcfg_data['gateway']
+
self.write_yaml(self.dea_file, {'fuel': fuel})
def reap_network_settings(self):
* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
##############################################################################
# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
from __future__ import absolute_import

import sys
import json


def write_hosts(hosts_ip):

    yardstick_flag = "# SUT hosts info for Yardstick"
    hosts_list = ('\n{} {} {}'.format(ip, host_name, yardstick_flag)
                  for host_name, ip in hosts_ip.items())

    with open("/etc/hosts", 'r') as f:
        origin_lines = [line for line in f if yardstick_flag not in line]

    with open("/etc/hosts", 'w') as f:
        f.writelines(origin_lines)
        f.write(yardstick_flag)
        f.writelines(hosts_list)


if __name__ == "__main__":
    write_hosts(json.load(sys.stdin))