Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MAC address update of network interfaces #355

Closed
Closed
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
22 changes: 8 additions & 14 deletions netbox_agent/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,7 @@ def get_network_cards(self):
return self.nics

def get_netbox_network_card(self, nic):
if nic["mac"] is None:
interface = self.nb_net.interfaces.get(name=nic["name"], **self.custom_arg_id)
else:
interface = self.nb_net.interfaces.get(
mac_address=nic["mac"], name=nic["name"], **self.custom_arg_id
)
return interface
return self.nb_net.interfaces.get(name=nic["name"], **self.custom_arg_id)

def get_netbox_network_cards(self):
return self.nb_net.interfaces.filter(**self.custom_arg_id)
Expand Down Expand Up @@ -463,18 +457,18 @@ def batched(it, n):
interface = self.create_netbox_nic(nic)

nic_update = 0
if nic["name"] != interface.name:
ret, interface = self.reset_vlan_on_interface(nic, interface)
nic_update += ret

if nic["mac"].lower() != getattr(interface, "mac_address", "").lower():
logging.info(
"Updating interface {interface} name to: {name}".format(
interface=interface, name=nic["name"]
"Updating interface {interface} mac to: {mac}".format(
interface=interface, mac=nic["mac"]
)
)
interface.name = nic["name"]
interface.mac_address = nic["mac"]
nic_update += 1

ret, interface = self.reset_vlan_on_interface(nic, interface)
nic_update += ret

if hasattr(interface, "mtu"):
if nic["mtu"] != interface.mtu:
logging.info(
Expand Down
Loading