From 41f0b04d007188539d581bb98db9a9c0c8c32851 Mon Sep 17 00:00:00 2001 From: Cyrinux Date: Tue, 9 Jun 2020 09:05:35 +0200 Subject: [PATCH 1/5] Add missing N/A fallback on DIMM memory (#129) --- netbox_agent/lshw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox_agent/lshw.py b/netbox_agent/lshw.py index 6e11fb7..c7841a1 100644 --- a/netbox_agent/lshw.py +++ b/netbox_agent/lshw.py @@ -129,7 +129,7 @@ class LSHW(): d["id"] = dimm.get("id") d["serial"] = dimm.get("serial", 'N/A') d["vendor"] = dimm.get("vendor", 'N/A') - d["product"] = dimm.get("product") + d["product"] = dimm.get("product", 'N/A') d["size"] = dimm.get("size", 0) / 2 ** 20 / 1024 self.memories.append(d) -- 2.47.0 From 683e6cacb188f901ef1aa06e840457a31d802cbf Mon Sep 17 00:00:00 2001 From: Cyrinux Date: Wed, 10 Jun 2020 15:24:43 +0200 Subject: [PATCH 2/5] Fix HP raid controller parsing (#131) * Some messages about the cache for example, with indentation level 0 break the parsing. I ignore line indentation if indentation level and line dont match REGEXP_CONTROLLER_HP. ```bash DC1|server-01:~# hpacucli ctrl all show detail Smart Array P244br in Slot 0 (Embedded) A cache backup failure has occurred. Please execute the "reenablecache" command to enable the cache. Your controller may require a reboot after the operation to complete the cache recovery process. Bus Interface: PCI Slot: 0 Serial Number: PDZVU0WLM241FP Cache Serial Number: PDZVU0WLM241FP RAID 6 (ADG) Status: Enabled Controller Status: OK Hardware Revision: B Firmware Version: 7.00-0 ... ``` * Remove whitespace --- netbox_agent/raid/hp.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/netbox_agent/raid/hp.py b/netbox_agent/raid/hp.py index 40a9a27..144e73b 100644 --- a/netbox_agent/raid/hp.py +++ b/netbox_agent/raid/hp.py @@ -54,6 +54,13 @@ def _get_dict(lines, start_index, indentation): continue current_line_indentation = _get_indentation(current_line) + # This check ignore some useless information that make + # crash the parsing + product_name = REGEXP_CONTROLLER_HP.search(current_line) + if current_line_indentation == 0 and not product_name: + i = i + 1 + continue + if current_line_indentation == indentation: current_item = current_line.lstrip(' ') -- 2.47.0 From e7ffacecaab2f69235a7f43439891f7f6437dfab Mon Sep 17 00:00:00 2001 From: Cyril Levis Date: Thu, 11 Jun 2020 20:48:46 +0200 Subject: [PATCH 3/5] Add Tun and Tap support, change type to Virtual and remove mac address --- netbox_agent/network.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/netbox_agent/network.py b/netbox_agent/network.py index 8659ee2..e6bb2b4 100644 --- a/netbox_agent/network.py +++ b/netbox_agent/network.py @@ -90,6 +90,12 @@ class Network(object): bonding_slaves = open( '/sys/class/net/{}/bonding/slaves'.format(interface) ).read().split() + + # Tun and TAP support + virtual = os.path.isfile( + '/sys/class/net/{}/tun_flags'.format(interface) + ) + nic = { 'name': interface, 'mac': mac if mac != '00:00:00:00:00:00' else None, @@ -100,6 +106,7 @@ class Network(object): ) for x in ip_addr ] if ip_addr else None, # FIXME: handle IPv6 addresses 'ethtool': Ethtool(interface).parse(), + 'virtual': virtual, 'vlan': vlan, 'bonding': bonding, 'bonding_slaves': bonding_slaves, @@ -159,6 +166,10 @@ class Network(object): if nic.get('bonding'): return self.dcim_choices['interface:type']['Link Aggregation Group (LAG)'] + + if nic.get('virtual') or nic.get('mac') is None: + return self.dcim_choices['interface:type']['Virtual'] + if nic.get('ethtool') is None: return self.dcim_choices['interface:type']['Other'] @@ -237,13 +248,20 @@ class Network(object): name=nic['name'], mac=nic['mac'], device=self.device.name)) nb_vlan = None - interface = self.nb_net.interfaces.create( - name=nic['name'], - mac_address=nic['mac'], - type=type, - mgmt_only=mgmt, + + params = { + 'name': nic['name'], + 'mac_address': nic['mac'], + 'type': type, + 'mgmt_only': mgmt, **self.custom_arg, - ) + } + + # Remove mac for virtual + if nic.get('virtual', False): + del params['mac_address'] + + interface = self.nb_net.interfaces.create(**params) if nic['vlan']: nb_vlan = self.get_or_create_vlan(nic['vlan']) -- 2.47.0 From 6d3564389d1163f5d13ec39bfd1376403456ddf1 Mon Sep 17 00:00:00 2001 From: Cyril Levis Date: Fri, 12 Jun 2020 09:58:27 +0200 Subject: [PATCH 4/5] Simplify --- netbox_agent/network.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/netbox_agent/network.py b/netbox_agent/network.py index e6bb2b4..1597a32 100644 --- a/netbox_agent/network.py +++ b/netbox_agent/network.py @@ -80,6 +80,10 @@ class Network(object): ip_addr.pop(i) mac = open('/sys/class/net/{}/address'.format(interface), 'r').read().strip() + # Loopback lo + if mac == '00:00:00:00:00:00': + mac = None + vlan = None if len(interface.split('.')) > 1: vlan = int(interface.split('.')[1]) @@ -98,7 +102,7 @@ class Network(object): nic = { 'name': interface, - 'mac': mac if mac != '00:00:00:00:00:00' else None, + 'mac': mac, 'ip': [ '{}/{}'.format( x['addr'], @@ -167,7 +171,7 @@ class Network(object): if nic.get('bonding'): return self.dcim_choices['interface:type']['Link Aggregation Group (LAG)'] - if nic.get('virtual') or nic.get('mac') is None: + if nic.get('virtual'): return self.dcim_choices['interface:type']['Virtual'] if nic.get('ethtool') is None: @@ -257,7 +261,7 @@ class Network(object): **self.custom_arg, } - # Remove mac for virtual + # Remove mac for virtual interface if nic.get('virtual', False): del params['mac_address'] -- 2.47.0 From 6a3522138f08147ee94db0798f65ca5c795c89fa Mon Sep 17 00:00:00 2001 From: Cyril Levis Date: Fri, 12 Jun 2020 10:24:35 +0200 Subject: [PATCH 5/5] Resimplify --- netbox_agent/network.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/netbox_agent/network.py b/netbox_agent/network.py index 1597a32..cb163a3 100644 --- a/netbox_agent/network.py +++ b/netbox_agent/network.py @@ -80,10 +80,6 @@ class Network(object): ip_addr.pop(i) mac = open('/sys/class/net/{}/address'.format(interface), 'r').read().strip() - # Loopback lo - if mac == '00:00:00:00:00:00': - mac = None - vlan = None if len(interface.split('.')) > 1: vlan = int(interface.split('.')[1]) @@ -102,7 +98,7 @@ class Network(object): nic = { 'name': interface, - 'mac': mac, + 'mac': mac if mac != '00:00:00:00:00:00' else None, 'ip': [ '{}/{}'.format( x['addr'], @@ -255,15 +251,13 @@ class Network(object): params = { 'name': nic['name'], - 'mac_address': nic['mac'], 'type': type, 'mgmt_only': mgmt, **self.custom_arg, } - # Remove mac for virtual interface - if nic.get('virtual', False): - del params['mac_address'] + if not nic.get('virtual', False): + params['mac_address'] = nic['mac'] interface = self.nb_net.interfaces.create(**params) -- 2.47.0