Update MAC address on pre-existing interfaces #166

Open
opened 2020-09-01 12:47:59 +02:00 by nrhtr · 0 comments
nrhtr commented 2020-09-01 12:47:59 +02:00 (Migrated from github.com)

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']
**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'] ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: DGNum/netbox-agent#166
No description provided.