aboutsummaryrefslogtreecommitdiffstats
path: root/app/discover/fetchers/cli
diff options
context:
space:
mode:
Diffstat (limited to 'app/discover/fetchers/cli')
-rw-r--r--app/discover/fetchers/cli/cli_access.py15
-rw-r--r--app/discover/fetchers/cli/cli_fetch_host_pnics.py7
-rw-r--r--app/discover/fetchers/cli/cli_fetch_vconnectors_ovs.py54
-rw-r--r--app/discover/fetchers/cli/cli_fetch_vservice_vnics.py10
4 files changed, 48 insertions, 38 deletions
diff --git a/app/discover/fetchers/cli/cli_access.py b/app/discover/fetchers/cli/cli_access.py
index c77b22a..68b81c8 100644
--- a/app/discover/fetchers/cli/cli_access.py
+++ b/app/discover/fetchers/cli/cli_access.py
@@ -17,7 +17,7 @@ from utils.logging.console_logger import ConsoleLogger
from utils.ssh_conn import SshConn
-class CliAccess(BinaryConverter, Fetcher):
+class CliAccess(Fetcher, BinaryConverter):
connections = {}
ssh_cmd = "ssh -q -o StrictHostKeyChecking=no "
call_count_per_con = {}
@@ -71,8 +71,9 @@ class CliAccess(BinaryConverter, Fetcher):
self.cached_commands[cmd_path] = {"timestamp": curr_time, "result": ret}
return ret
- def run_fetch_lines(self, cmd, ssh_to_host="", enable_cache=True):
- out = self.run(cmd, ssh_to_host, enable_cache)
+ def run_fetch_lines(self, cmd, ssh_to_host="", enable_cache=True,
+ use_sudo=True):
+ out = self.run(cmd, ssh_to_host, enable_cache, use_sudo=use_sudo)
if not out:
return []
# first try to split lines by whitespace
@@ -236,7 +237,7 @@ class CliAccess(BinaryConverter, Fetcher):
self.find_matching_regexps(o, line, regexps)
for regexp_tuple in regexps:
name = regexp_tuple['name']
- if 'name' not in o and 'default' in regexp_tuple:
+ if name not in o and 'default' in regexp_tuple:
o[name] = regexp_tuple['default']
@staticmethod
@@ -247,4 +248,8 @@ class CliAccess(BinaryConverter, Fetcher):
regex = re.compile(regex)
matches = regex.search(line)
if matches and name not in o:
- o[name] = matches.group(1)
+ try:
+ o[name] = matches.group(1)
+ except IndexError as e:
+ self.log.error('failed to find group 1 in match, {}'
+ .format(str(regexp_tuple)))
diff --git a/app/discover/fetchers/cli/cli_fetch_host_pnics.py b/app/discover/fetchers/cli/cli_fetch_host_pnics.py
index 26cd603..81d164d 100644
--- a/app/discover/fetchers/cli/cli_fetch_host_pnics.py
+++ b/app/discover/fetchers/cli/cli_fetch_host_pnics.py
@@ -27,8 +27,8 @@ class CliFetchHostPnics(CliAccess):
'description': 'IPv6 Address'}
]
- def get(self, id):
- host_id = id[:id.rindex("-")]
+ def get(self, parent_id):
+ host_id = parent_id[:parent_id.rindex("-")]
cmd = 'ls -l /sys/class/net | grep ^l | grep -v "/virtual/"'
host = self.inv.get_by_id(self.get_env(), host_id)
if not host:
@@ -39,7 +39,8 @@ class CliFetchHostPnics(CliAccess):
", host: " + str(host))
return []
host_types = host["host_type"]
- if "Network" not in host_types and "Compute" not in host_types:
+ accepted_host_types = ['Network', 'Compute', 'Kube-node']
+ if not [t for t in accepted_host_types if t in host_types]:
return []
interface_lines = self.run_fetch_lines(cmd, host_id)
interfaces = []
diff --git a/app/discover/fetchers/cli/cli_fetch_vconnectors_ovs.py b/app/discover/fetchers/cli/cli_fetch_vconnectors_ovs.py
index ff37569..ac04568 100644
--- a/app/discover/fetchers/cli/cli_fetch_vconnectors_ovs.py
+++ b/app/discover/fetchers/cli/cli_fetch_vconnectors_ovs.py
@@ -18,8 +18,8 @@ class CliFetchVconnectorsOvs(CliFetchVconnectors):
def get_vconnectors(self, host):
host_id = host['id']
- lines = self.run_fetch_lines("brctl show", host_id)
- headers = ["bridge_name", "bridge_id", "stp_enabled", "interfaces"]
+ lines = self.run_fetch_lines('brctl show', host_id)
+ headers = ['bridge_name', 'bridge_id', 'stp_enabled', 'interfaces']
headers_count = len(headers)
# since we hard-coded the headers list, remove the headers line
del lines[:1]
@@ -31,26 +31,32 @@ class CliFetchVconnectorsOvs(CliFetchVconnectors):
results = self.parse_cmd_result_with_whitespace(fixed_lines, headers, False)
ret = []
for doc in results:
- doc["name"] = doc.pop("bridge_name")
- doc["id"] = doc["name"] + "-" + doc.pop("bridge_id")
- doc["host"] = host_id
- doc["connector_type"] = "bridge"
- if "interfaces" in doc:
- interfaces = {}
- interface_names = doc["interfaces"].split(",")
- for interface_name in interface_names:
- # find MAC address for this interface from ports list
- port_id_prefix = interface_name[3:]
- port = self.inv.find_items({
- "environment": self.get_env(),
- "type": "port",
- "binding:host_id": host_id,
- "id": {"$regex": r"^" + re.escape(port_id_prefix)}
- }, get_single=True)
- mac_address = '' if not port else port['mac_address']
- interface = {'name': interface_name, 'mac_address': mac_address}
- interfaces[interface_name] = interface
- doc["interfaces"] = interfaces
- doc['interfaces_names'] = list(interfaces.keys())
- ret.append(doc)
+ doc['name'] = '{}-{}'.format(host_id, doc['bridge_name'])
+ doc['id'] = '{}-{}'.format(doc['name'], doc.pop('bridge_id'))
+ doc['host'] = host_id
+ doc['connector_type'] = 'bridge'
+ self.get_vconnector_interfaces(doc, host_id)
+ ret.append(doc)
return ret
+
+ def get_vconnector_interfaces(self, doc, host_id):
+ if 'interfaces' not in doc:
+ doc['interfaces'] = {}
+ doc['interfaces_names'] = []
+ return
+ interfaces = {}
+ interface_names = doc['interfaces'].split(',')
+ for interface_name in interface_names:
+ # find MAC address for this interface from ports list
+ port_id_prefix = interface_name[3:]
+ port = self.inv.find_items({
+ 'environment': self.get_env(),
+ 'type': 'port',
+ 'binding:host_id': host_id,
+ 'id': {'$regex': r'^' + re.escape(port_id_prefix)}
+ }, get_single=True)
+ mac_address = '' if not port else port['mac_address']
+ interface = {'name': interface_name, 'mac_address': mac_address}
+ interfaces[interface_name] = interface
+ doc['interfaces'] = interfaces
+ doc['interfaces_names'] = list(interfaces.keys())
diff --git a/app/discover/fetchers/cli/cli_fetch_vservice_vnics.py b/app/discover/fetchers/cli/cli_fetch_vservice_vnics.py
index 3bc3a5b..0129d3b 100644
--- a/app/discover/fetchers/cli/cli_fetch_vservice_vnics.py
+++ b/app/discover/fetchers/cli/cli_fetch_vservice_vnics.py
@@ -66,17 +66,15 @@ class CliFetchVserviceVnics(CliAccess):
master_parent_id = "{}-{}".format(host, service)
current = {
"id": host + "-" + name,
- "type": "vnic",
"vnic_type": "vservice_vnic",
"host": host,
"name": name,
- "master_parent_type": "vservice",
- "master_parent_id": master_parent_id,
- "parent_type": "vnics_folder",
- "parent_id": "{}-vnics".format(master_parent_id),
- "parent_text": "vNICs",
"lines": []
}
+ self.set_folder_parent(current, object_type="vnic",
+ master_parent_type="vservice",
+ master_parent_id=master_parent_id,
+ parent_text="vNICs")
interfaces.append(current)
self.handle_line(current, line_remainder)
else: