fix setting of MAC address for host pNIC in VPP 45/41345/1
authoryayogev <yaronyogev@gmail.com>
Thu, 7 Sep 2017 20:29:16 +0000 (23:29 +0300)
committeryayogev <yaronyogev@gmail.com>
Thu, 7 Sep 2017 20:29:16 +0000 (23:29 +0300)
Change-Id: I671460410fc1a6a0fd5fd929a6ef3e9da23ecbdb
Signed-off-by: yayogev <yaronyogev@gmail.com>
app/discover/fetchers/cli/cli_fetch_host_pnics_vpp.py

index d783998..13914bb 100644 (file)
@@ -9,12 +9,13 @@
 ###############################################################################
 import re
 
-from discover.fetcher import Fetcher
+from discover.fetchers.cli.cli_access import CliAccess
 from utils.inventory_mgr import InventoryMgr
 
 NAME_RE = '^[a-zA-Z]*GigabitEthernet'
+MAC_FIELD_RE = '^.*\sEthernet address\s(\S+)(\s.*)?$'
 
-class CliFetchHostPnicsVpp(Fetcher):
+class CliFetchHostPnicsVpp(CliAccess):
     def __init__(self):
         super().__init__()
         self.inv = InventoryMgr()
@@ -39,6 +40,17 @@ class CliFetchHostPnicsVpp(Fetcher):
                 pnic['id'] = host_id + "-pnic-" + pnic_name
                 pnic['type'] = 'host_pnic'
                 pnic['object_name'] = pnic_name
+                self.get_pnic_mac_address(pnic)
                 pnic['Link detected'] = 'yes' if pnic['state'] == 'up' else 'no'
                 ret.append(pnic)
         return ret
+
+    def get_pnic_mac_address(self, pnic):
+        cmd = 'vppctl show hardware-interfaces {}'.format(pnic['object_name'])
+        output_lines = self.run_fetch_lines(cmd, ssh_to_host=pnic['host'])
+        if output_lines:
+            regexps = [{'name': 'mac_address', 're': MAC_FIELD_RE}]
+            for line in output_lines:
+                self.find_matching_regexps(pnic, line, regexps)
+                if 'mac_address' in pnic:
+                    break