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

Update MAC address on pre-existing interfaces #166

Open
nrhtr opened this issue Sep 1, 2020 · 5 comments · May be fixed by #363
Open

Update MAC address on pre-existing interfaces #166

nrhtr opened this issue Sep 1, 2020 · 5 comments · May be fixed by #363
Labels
need testing type: enhancement New feature or request

Comments

@nrhtr
Copy link

nrhtr commented Sep 1, 2020

Describe the bug
If a device already has interfaces with no MAC set (e.g. device type template interfaces) netbox-agent bails out. It seems it can't find the interface because it's searching by mac&name. I think it should be searching by device&name since this is enough to uniquely identify interfaces.

Expected behavior
MAC address should be updated for existing interfaces.

Configuration file
N/A

Environment:
N/A

Additional context
This is the patch I applied to get it to work for me. This probably breaks other stuff but at least shows what I mean.

# diff /usr/local/lib/python3.6/site-packages/netbox_agent/network.old.py /usr/local/lib/python3.6/site-packages/netbox_agent/network.py
145,155c145,149
<         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,
<             )
---
> 	# Should/can this query by device&name?
>         interface = self.nb_net.interfaces.get(
>             name=nic['name'],
>             **self.custom_arg_id,
>         )
409a404,409
>                 nic_update += 1
>
>             if nic['mac'] != getattr(interface, 'mac_address', ''):
>                 logging.info('Updating interface {interface} mac to: {mac}'.format(
>                     interface=interface, mac=nic['mac']))
>                 interface.mac_address = nic['mac']
@Solvik Solvik added need testing type: enhancement New feature or request labels Nov 28, 2020
@TiagoTT
Copy link
Contributor

TiagoTT commented Jan 9, 2025

The MAC of bond interfaces can change at every boot or network restart, because the bond takes the MAC of the first slave interface (which is prone to race conditions during interface startup). Also the MAC of the subsequent slave interfaces gets changed to be the MAC of the bond. So it would be great if the netbox-agent could update MAC addresses of interfaces.
For this, I could prepare a PR based on the patch submitted in this issue.

Additionally, I think it would be preferable to store the permanent MAC address of physical interfaces for inventory purposes.
But it seems that the output of lshw provides the current MAC address as serial number and not the permanent MAC address.
One option would be to pick the permanent MAC address from the output of ethtool -P and use it as serial, instead of the serial provided by lshw.
Another option would be to add the permanent MAC address to the description of the inventory item, so that at least the user could find the inventory item when searching by the permanent MAC address.
Also linking the inventory item representing the NIC to the logical NIC object would be useful.

What do you think?

@TiagoTT
Copy link
Contributor

TiagoTT commented Jan 10, 2025

Here is the suggested change from @nrhtr with minor format changes in a PR: #355

@ribetm
Copy link
Collaborator

ribetm commented Jan 20, 2025

Hello, this would be a breaking change and even one that may not be wanted by some.

Maybe this could be configurable, with either name or MAC or both being used as the lookup term and the remaining one being updated on changes. I'm currently adding a few improvements related to NICs, so I should be able to add this. Would that work for you ? You would simply have to set something like network.interface_identifiers=name in the configuration.

@TiagoTT
Copy link
Contributor

TiagoTT commented Jan 20, 2025

Hi @ribetm , yes, having an option to make the interfaces be identified by name would work for us.

Meanwhile, I have been working on storing the permanent MAC address as serial number on the inventory items of the network interface cards and also on linking the inventory item to the network interface in #361.

@TiagoTT
Copy link
Contributor

TiagoTT commented Jan 21, 2025

Hi @ribetm ,
Your PR looks good, so I dropped by first PR #355.
I just left a comment about the order of the interface update operations because reset_vlan_on_interface creates a new interface object and drops the changes made to the previous one. I suggested changing the order of the operations, but maybe you can find a better fix.
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need testing type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants