From 221ac16e87c6ff4c733c3e95bab78e84183c4b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Blondel?= Date: Tue, 14 Feb 2023 23:32:26 +0100 Subject: [PATCH] feat: Retrieve and manage MTU for the interfaces --- netbox_agent/ipmi.py | 1 + netbox_agent/network.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/netbox_agent/ipmi.py b/netbox_agent/ipmi.py index 10ccb8c..ff2b42b 100644 --- a/netbox_agent/ipmi.py +++ b/netbox_agent/ipmi.py @@ -55,6 +55,7 @@ class IPMI(): ret = {} ret['name'] = 'IPMI' + ret["mtu"] = 1500 ret['bonding'] = False ret['mac'] = _ipmi['MAC Address'] ret['vlan'] = int(_ipmi['802.1q VLAN ID']) \ diff --git a/netbox_agent/network.py b/netbox_agent/network.py index 500dc95..922e2aa 100644 --- a/netbox_agent/network.py +++ b/netbox_agent/network.py @@ -85,6 +85,7 @@ class Network(object): ip_addr.append(addr) mac = open('/sys/class/net/{}/address'.format(interface), 'r').read().strip() + mtu = int(open('/sys/class/net/{}/mtu'.format(interface), 'r').read().strip()) vlan = None if len(interface.split('.')) > 1: vlan = int(interface.split('.')[1]) @@ -114,6 +115,7 @@ class Network(object): 'ethtool': Ethtool(interface).parse(), 'virtual': virtual, 'vlan': vlan, + 'mtu': mtu, 'bonding': bonding, 'bonding_slaves': bonding_slaves, } @@ -276,6 +278,9 @@ class Network(object): if nic['mac']: params['mac_address'] = nic['mac'] + if nic['mtu']: + params['mtu'] = nic['mtu'] + interface = self.nb_net.interfaces.create(**params) if nic['vlan']: @@ -443,6 +448,13 @@ class Network(object): ret, interface = self.reset_vlan_on_interface(nic, interface) nic_update += ret + if hasattr(interface, 'mtu'): + if nic['mtu'] != interface.mtu: + logging.info('Interface mtu is wrong, updating to: {mtu}'.format( + mtu=nic['mtu'])) + interface.mtu = nic['mtu'] + nic_update += 1 + if hasattr(interface, 'type'): _type = self.get_netbox_type_for_nic(nic) if not interface.type or \