Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions netbox_agent/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,12 @@ def update_interface_macs(self, nic, macs):
nb_macs = list(self.nb_net.mac_addresses.filter(interface_id=nic.id))
# Clean
for nb_mac in nb_macs:
if nb_mac.mac_address not in macs:
if nb_mac.mac_address.lower() not in macs:
logging.debug("Deleting extra MAC {mac} from {nic}".format(mac=nb_mac, nic=nic))
nb_mac.delete()
# Add missing
for mac in macs:
if mac not in {nb_mac.mac_address for nb_mac in nb_macs}:
if mac not in {nb_mac.mac_address.lower() for nb_mac in nb_macs}:
logging.debug("Adding MAC {mac} to {nic}".format(mac=mac, nic=nic))
self.nb_net.mac_addresses.create(
{
Expand Down Expand Up @@ -542,7 +542,7 @@ def batched(it, n):
if nic["mac"]:
self.update_interface_macs(interface, [nic["mac"]])

if nic["mac"] and nic["mac"] != interface.mac_address:
if nic["mac"] and nic["mac"] != interface.mac_address.lower():
logging.info(
"Updating interface {interface} mac to: {mac}".format(
interface=interface, mac=nic["mac"]
Expand All @@ -551,7 +551,12 @@ def batched(it, n):
if version.parse(nb.version) < version.parse("4.2"):
interface.mac_address = nic["mac"]
else:
interface.primary_mac_address = {"mac_address": nic["mac"]}
interface.primary_mac_address = {
"mac_address": nic["mac"],
"interface": {
"id": interface.id,
},
}
nic_update += 1

if hasattr(interface, "mtu"):
Expand Down