aboutsummaryrefslogtreecommitdiffstats
path: root/app/discover/fetchers/db/db_fetch_vedges_vpp.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/discover/fetchers/db/db_fetch_vedges_vpp.py')
-rw-r--r--app/discover/fetchers/db/db_fetch_vedges_vpp.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/app/discover/fetchers/db/db_fetch_vedges_vpp.py b/app/discover/fetchers/db/db_fetch_vedges_vpp.py
new file mode 100644
index 0000000..a1c659e
--- /dev/null
+++ b/app/discover/fetchers/db/db_fetch_vedges_vpp.py
@@ -0,0 +1,56 @@
+###############################################################################
+# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
+# 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 discover.fetchers.cli.cli_access import CliAccess
+from discover.fetchers.db.db_access import DbAccess
+from utils.inventory_mgr import InventoryMgr
+from utils.singleton import Singleton
+
+
+class DbFetchVedgesVpp(DbAccess, CliAccess, metaclass=Singleton):
+ def __init__(self):
+ super().__init__()
+ self.inv = InventoryMgr()
+
+ def get(self, id):
+ host_id = id[:id.rindex('-')]
+ vedge = {
+ 'host': host_id,
+ 'id': host_id + '-VPP',
+ 'name': 'VPP-' + host_id,
+ 'agent_type': 'VPP'
+ }
+ ver = self.run_fetch_lines('vppctl show ver', host_id)
+ if ver:
+ ver = ver[0]
+ vedge['binary'] = ver[:ver.index(' ', ver.index(' ') + 1)]
+ host = self.inv.get_by_id(self.get_env(), host_id)
+ if not host:
+ self.log.error("unable to find host in inventory: %s", host_id)
+ return []
+ host_types = host["host_type"]
+ if "Network" not in host_types and "Compute" not in host_types:
+ return []
+ interfaces = self.run_fetch_lines('vppctl show int', host_id)
+ vedge['ports'] = self.fetch_ports(interfaces)
+ return [vedge]
+
+ def fetch_ports(self, interfaces):
+ ports = {}
+ for i in interfaces:
+ if not i or i.startswith(' '):
+ continue
+ parts = i.split()
+ port = {
+ 'id': parts[1],
+ 'state': parts[2],
+ 'name': parts[0]
+ }
+ ports[port['name']] = port
+ return ports