Merge pull request #264 from Farfaday/feat/manage_mtu

feat: Retrieve and manage MTU for the interfaces
This commit is contained in:
Cyril Levis 2023-02-15 11:55:02 +01:00 committed by GitHub
commit ab96965767
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View file

@ -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']) \

View file

@ -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 \