Skip to content

Commit 123753a

Browse files
author
Anatole Denis
committed
Normalize MAC addresses from netbox to lowercase
Both tools used to gather MAC addresses from devices (ethtool and /sys/class/net) return mac addresses as lowercase, but netbox normalizes them as uppercase, causing spurious MAC delete/re-creates when updating servers as the macs don't compare equal
1 parent fe0ea00 commit 123753a

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

netbox_agent/network.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,12 @@ def update_interface_macs(self, nic, macs):
294294
nb_macs = list(self.nb_net.mac_addresses.filter(interface_id=nic.id))
295295
# Clean
296296
for nb_mac in nb_macs:
297-
if nb_mac.mac_address not in macs:
297+
if nb_mac.mac_address.lower() not in macs:
298298
logging.debug("Deleting extra MAC {mac} from {nic}".format(mac=nb_mac, nic=nic))
299299
nb_mac.delete()
300300
# Add missing
301301
for mac in macs:
302-
if mac not in {nb_mac.mac_address for nb_mac in nb_macs}:
302+
if mac not in {nb_mac.mac_address.lower() for nb_mac in nb_macs}:
303303
logging.debug("Adding MAC {mac} to {nic}".format(mac=mac, nic=nic))
304304
self.nb_net.mac_addresses.create(
305305
{
@@ -542,7 +542,7 @@ def batched(it, n):
542542
if nic["mac"]:
543543
self.update_interface_macs(interface, [nic["mac"]])
544544

545-
if nic["mac"] and nic["mac"] != interface.mac_address:
545+
if nic["mac"] and nic["mac"] != interface.mac_address.lower():
546546
logging.info(
547547
"Updating interface {interface} mac to: {mac}".format(
548548
interface=interface, mac=nic["mac"]

0 commit comments

Comments
 (0)