diff options
author | 2017-10-10 18:08:39 +0300 | |
---|---|---|
committer | 2017-10-10 18:08:39 +0300 | |
commit | 5c6eb170878cefa12f717a62c31f7228d440e61e (patch) | |
tree | 1ac74fe56257a68ccf5a35499ba9e458a9b436ed /app/discover/fetchers | |
parent | a947ad2815cea81e126e7813d718531be414b02c (diff) |
release 1.1 for euphrates
Change-Id: Iddc0e0148db7c72458b7fcdfcb7664e4aa609be0
Signed-off-by: Koren Lev <korenlev@gmail.com>
Diffstat (limited to 'app/discover/fetchers')
-rw-r--r-- | app/discover/fetchers/cli/cli_fetch_host_pnics.py | 26 | ||||
-rw-r--r-- | app/discover/fetchers/cli/cli_fetch_vservice_vnics.py | 41 | ||||
-rw-r--r-- | app/discover/fetchers/db/db_fetch_oteps.py | 12 |
3 files changed, 47 insertions, 32 deletions
diff --git a/app/discover/fetchers/cli/cli_fetch_host_pnics.py b/app/discover/fetchers/cli/cli_fetch_host_pnics.py index 4af3ebc..26cd603 100644 --- a/app/discover/fetchers/cli/cli_fetch_host_pnics.py +++ b/app/discover/fetchers/cli/cli_fetch_host_pnics.py @@ -19,18 +19,12 @@ class CliFetchHostPnics(CliAccess): self.inv = InventoryMgr() self.ethtool_attr = re.compile('^\s+([^:]+):\s(.*)$') self.regexps = [ - {'name': 'mac_address', 're': '^.*\sHWaddr\s(\S+)(\s.*)?$', - 'description': 'MAC address with HWaddr'}, - {'name': 'mac_address', 're': '^.*\sether\s(\S+)(\s.*)?$', - 'description': 'MAC address with ether'}, - {'name': 'IP Address', 're': '^\s*inet addr:?(\S+)\s.*$', - 'description': 'IP Address with "inet addr"'}, - {'name': 'IP Address', 're': '^\s*inet ([0-9.]+)\s.*$', - 'description': 'IP Address with "inet"'}, - {'name': 'IPv6 Address', 're': '^\s*inet6 addr:\s*(\S+)(\s.*)?$', - 'description': 'IPv6 Address with "inet6 addr"'}, - {'name': 'IPv6 Address', 're': '^\s*inet6 \s*(\S+)(\s.*)?$', - 'description': 'IPv6 Address with "inet6"'} + {'name': 'mac_address', 're': '^.*\slink/ether\s(\S+)\s', + 'description': 'MAC address'}, + {'name': 'IP Address', 're': '^\s*inet ([0-9.]+)/', + 'description': 'IP Address v4'}, + {'name': 'IPv6 Address', 're': '^\s*inet6 (\S+) .* global ', + 'description': 'IPv6 Address'} ] def get(self, id): @@ -52,7 +46,7 @@ class CliFetchHostPnics(CliAccess): for line in interface_lines: interface_name = line[line.rindex('/')+1:] interface_name = interface_name.strip() - # run ifconfig with specific interface name, + # run 'ip address show' with specific interface name, # since running it with no name yields a list without inactive pNICs interface = self.find_interface_details(host_id, interface_name) if interface: @@ -60,15 +54,15 @@ class CliFetchHostPnics(CliAccess): return interfaces def find_interface_details(self, host_id, interface_name): - lines = self.run_fetch_lines("ifconfig " + interface_name, host_id) + cmd = "ip address show {}".format(interface_name) + lines = self.run_fetch_lines(cmd, host_id) interface = None status_up = None for line in [l for l in lines if l != '']: tokens = None if interface is None: tokens = line.split() - line_remainder = line.strip('-')[len(interface_name)+2:] - line_remainder = line_remainder.strip(' :') + line_remainder = line.split(":")[2].strip() interface = { "host": host_id, "name": interface_name, diff --git a/app/discover/fetchers/cli/cli_fetch_vservice_vnics.py b/app/discover/fetchers/cli/cli_fetch_vservice_vnics.py index 239ecd7..2e074f8 100644 --- a/app/discover/fetchers/cli/cli_fetch_vservice_vnics.py +++ b/app/discover/fetchers/cli/cli_fetch_vservice_vnics.py @@ -17,18 +17,13 @@ class CliFetchVserviceVnics(CliAccess): def __init__(self): super().__init__() self.inv = InventoryMgr() - self.if_header = re.compile('^[-]?(\S+)\s+(.*)$') + self.if_header = re.compile('^\d+: ([^:]+): (.+)') self.regexps = [ - {'name': 'mac_address', 're': '^.*\sHWaddr\s(\S+)(\s.*)?$'}, - {'name': 'mac_address', 're': '^.*\sether\s(\S+)(\s.*)?$'}, - {'name': 'IP Address', 're': '^\s*inet addr:(\S+)\s.*$'}, - {'name': 'IP Address', 're': '^\s*inet ([0-9.]+)\s.*$'}, - {'name': 'netmask', 're': '^.*\sMask:\s?([0-9.]+)(\s.*)?$'}, - {'name': 'netmask', 're': '^.*\snetmask\s([0-9.]+)(\s.*)?$'}, + {'name': 'mac_address', 're': '^.*\slink/ether\s(\S+)\s'}, + {'name': 'IP Address', 're': '^\s*inet ([0-9.]+)/'}, + {'name': 'netmask', 're': '^.*\slink/ether\s[^/]+/(\S+)'}, {'name': 'IPv6 Address', - 're': '^\s*inet6 addr: ?\s*([0-9a-f:/]+)(\s.*)?$'}, - {'name': 'IPv6 Address', - 're': '^\s*inet6 \s*([0-9a-f:/]+)(\s.*)?$'} + 're': '^\s*inet6 ([^/]+)/.* global '} ] def get(self, host_id): @@ -53,7 +48,7 @@ class CliFetchVserviceVnics(CliAccess): return ret def handle_service(self, host, service, enable_cache=True): - cmd = "ip netns exec " + service + " ifconfig" + cmd = "ip netns exec " + service + " ip address show" lines = self.run_fetch_lines(cmd, host, enable_cache) interfaces = [] current = None @@ -122,6 +117,7 @@ class CliFetchVserviceVnics(CliAccess): vnic["IP Address"] = "No IP Address" return "No IP Address" ipaddr = vnic["IP Address"].split('.') + vnic['netmask'] = self.convert_netmask(vnic['netmask']) netmask = vnic["netmask"].split('.') # calculate network start @@ -138,3 +134,26 @@ class CliFetchVserviceVnics(CliAccess): for octet in netmask: binary_str += bin(int(octet))[2:].zfill(8) return str(len(binary_str.rstrip('0'))) + + @staticmethod + def convert_netmask(cidr): + netmask_conversion = { + '30': '255.255.255.252', + '29': '255.255.255.248', + '28': '255.255.255.240', + '27': '255.255.255.224', + '26': '255.255.255.192', + '25': '255.255.255.128', + '24': '255.255.255.0', + '23': '255.255.254.0', + '22': '255.255.252.0', + '21': '255.255.248.0', + '20': '255.255.240.0', + '19': '255.255.224.0', + '18': '255.255.192.0', + '17': '255.255.128.0', + '16': '255.255.0.0' + } + if cidr not in netmask_conversion: + raise ValueError('can''t convert to netmask: {}'.format(cidr)) + return netmask_conversion.get(cidr) diff --git a/app/discover/fetchers/db/db_fetch_oteps.py b/app/discover/fetchers/db/db_fetch_oteps.py index f7eb8bd..85376ed 100644 --- a/app/discover/fetchers/db/db_fetch_oteps.py +++ b/app/discover/fetchers/db/db_fetch_oteps.py @@ -63,21 +63,23 @@ class DbFetchOteps(DbAccess, CliAccess, metaclass=Singleton): return results # find matching vConnector by tunneling_ip of vEdge - # look for that IP address in ifconfig for the host + # look for that IP address in 'ip address show' output for the host def get_vconnector(self, doc, host_id, vedge): tunneling_ip = vedge["configurations"]["tunneling_ip"] - ifconfig_lines = self.run_fetch_lines("ifconfig", host_id) + output_lines = self.run_fetch_lines("ip address show", host_id) interface = None - ip_string = " " * 10 + "inet addr:" + tunneling_ip + " " + ip_string = " inet {}/".format(tunneling_ip) vconnector = None - for l in ifconfig_lines: + for l in output_lines: if l.startswith(" "): if interface and l.startswith(ip_string): vconnector = interface break else: if " " in l: - interface = l[:l.index(" ")] + # line format is like this: + # <interface number>: <interface name>: .... + interface = l.split(":")[1].strip() if vconnector: doc["vconnector"] = vconnector |