diff --git a/netbox_agent/lldp.py b/netbox_agent/lldp.py index 7b991d5..51083f5 100644 --- a/netbox_agent/lldp.py +++ b/netbox_agent/lldp.py @@ -53,7 +53,7 @@ class LLDP(): # lldp.eth0.chassis.mgmt-ip=100.66.7.222 if self.data['lldp'].get(interface) is None: return None - return self.data['lldp'][interface]['chassis'].get('mgmt-ip') + return self.data['lldp'][interface]['chassis']['mgmt-ip'] def get_switch_port(self, interface): # lldp.eth0.port.descr=GigabitEthernet1/0/1 diff --git a/netbox_agent/misc.py b/netbox_agent/misc.py index 8672cad..6e7e92d 100644 --- a/netbox_agent/misc.py +++ b/netbox_agent/misc.py @@ -32,17 +32,12 @@ def get_device_type(type): def get_device_platform(device_platform): if device_platform is None: try: - # Python 3.8+ moved linux_distribution() to distro - try: - import distro - linux_distribution = " ".join(distro.linux_distribution()) - except ImportError: - import platform - linux_distribution = " ".join(platform.linux_distribution()) + import platform + linux_distribution = " ".join(platform.linux_distribution()) if not linux_distribution: return None - except (ModuleNotFoundError, NameError, AttributeError): + except (ModuleNotFoundError, NameError): return None else: linux_distribution = device_platform diff --git a/netbox_agent/network.py b/netbox_agent/network.py index fb97409..500dc95 100644 --- a/netbox_agent/network.py +++ b/netbox_agent/network.py @@ -214,7 +214,7 @@ class Network(object): lldp_vlan = self.lldp.get_switch_vlan(nic['name']) if config.network.lldp else None # For strange reason, we need to get the object from scratch # The object returned by pynetbox's save isn't always working (since pynetbox 6) - interface = nb.dcim.interfaces.get(id=interface.id) + interface = self.nb_net.interfaces.get(id=interface.id) # Handle the case were the local interface isn't an interface vlan as reported by Netbox # and that LLDP doesn't report a vlan-id diff --git a/netbox_agent/raid/hp.py b/netbox_agent/raid/hp.py index c8e0df8..82d3c06 100644 --- a/netbox_agent/raid/hp.py +++ b/netbox_agent/raid/hp.py @@ -10,6 +10,7 @@ REGEXP_CONTROLLER_HP = re.compile(r'Smart Array ([a-zA-Z0-9- ]+) in Slot ([0-9]+ class HPRaidControllerError(Exception): pass + def ssacli(sub_command): command = ["ssacli"] command.extend(sub_command.split()) @@ -20,19 +21,16 @@ def ssacli(sub_command): ) p.wait() stdout = p.stdout.read().decode("utf-8") - if p.returncode != 0 and 'does not have any physical' not in stdout: + if p.returncode != 0: mesg = "Failed to execute command '{}':\n{}".format( " ".join(command), stdout ) raise HPRaidControllerError(mesg) - else: - if 'does not have any physical' in stdout: - return list() - else: - lines = stdout.split('\n') - lines = list(filter(None, lines)) + lines = stdout.split('\n') + lines = list(filter(None, lines)) return lines + def _parse_ctrl_output(lines): controllers = {} current_ctrl = None diff --git a/netbox_agent/server.py b/netbox_agent/server.py index bdc1407..f7008bf 100644 --- a/netbox_agent/server.py +++ b/netbox_agent/server.py @@ -274,7 +274,7 @@ class ServerBase(): serial=serial, device_role=device_role.id, device_type=device_type.id, - platform=self.device_platform.id, + platform=self.device_platform, site=datacenter.id if datacenter else None, tenant=tenant.id if tenant else None, rack=rack.id if rack else None,