netbox-sync icon indicating copy to clipboard operation
netbox-sync copied to clipboard

Setting Primary IP does not work

Open patschi opened this issue 1 year ago • 4 comments

I have some odd behavior where the sync script is not properly setting the Primary IP on almost half of the VMs existent in netbox. The output seems to be fine:

$ /opt/netbox-vmware-sync/.venv/bin/python3 /opt/netbox-vmware-sync/netbox-sync.py --config /opt/netbox-vmware-sync/settings.ini
2024-11-16 23:40:02,800 - INFO: Starting NetBox Sync v1.7.0 (2024-10-21)
2024-11-16 23:40:02,846 - INFO: Successfully connected to NetBox '127.0.0.1'
2024-11-16 23:40:02,846 - INFO: Initializing sources
2024-11-16 23:40:02,916 - INFO: Successfully connected to vCenter SDK 'vc1'
2024-11-16 23:40:02,998 - INFO: Successfully connected to vCenter API 'vc1'
2024-11-16 23:40:03,238 - INFO: Successfully connected to vCenter SDK 'vc2'
2024-11-16 23:40:03,352 - INFO: Successfully connected to vCenter API 'vc2'
2024-11-16 23:40:03,352 - INFO: Querying necessary objects from NetBox. This might take a while.
2024-11-16 23:40:08,920 - INFO: Finished querying necessary objects from NetBox
2024-11-16 23:40:08,943 - INFO: Query data from vCenter: 'vc1'
2024-11-16 23:40:29,100 - INFO: Parsing objects which were marked to be reevaluated
2024-11-16 23:40:29,100 - INFO: Query data from vCenter: 'vc2'
2024-11-16 23:41:14,147 - INFO: Parsing objects which were marked to be reevaluated
2024-11-16 23:41:14,221 - INFO: Updating changed data in NetBox
2024-11-16 23:41:14,273 - INFO: Pruning orphaned data in NetBox
2024-11-16 23:41:14,356 - INFO: Completed NetBox Sync in 1 minute, 11 seconds

I have cleared cache/ folder, just to rule out the cache messing up things.

In the settings, I do have configured the setting set_primary_ip to always:

; define how the primary IPs should be set
; possible values:
;
;   always:     will remove primary IP from the object where this address is
;               currently set as primary and moves it to new object
;
;   when-undefined:
;               only sets primary IP if undefined, will cause ERRORs if same IP is
;               assigned more then once to different hosts and IP is set as the
;               objects primary IP
;
;   never:      don't set any primary IPs, will cause the same ERRORs
;               as "when-undefined"
;set_primary_ip = when-undefined
set_primary_ip = always

On both vCenters:

$ grep "^set_primary_ip" settings.ini
set_primary_ip = always
set_primary_ip = always

But still, I do have 37 VMs without a Primary IP set: image

Any ideas?

patschi avatar Nov 16 '24 23:11 patschi

Hi,

Have you tried setting log level to debug2 with -l DEBUG2. It should let you know what's going on.

bb-Ricardo avatar Nov 17 '24 08:11 bb-Ricardo

Hey,

would you be able to checkout the latest development branch and test it again with the -l DEBUG2 option?

bb-Ricardo avatar Feb 21 '25 22:02 bb-Ricardo

Sorry, completely lost track of this issue. I also made one strange observation: I set the Primary IP on a VM manually, removed it and it did properly set the Primary IP.

But still, when filtering for PrimaryIP=No and Status=Active, I do have a few VMs without primary IP set (2 Avi SEs are orphaned): Image

Running the current version in development branch doesn't change anything.

For example the decorerouter02 (01 does have a Primary IP), there are no error(s) in the logs:

$ grep "decorerouter02" debug.txt | grep -v "Parsing.*data structure.*vNIC"
2025-02-21 23:29:37,256 - DEBUG: Parsing vCenter VM: decorerouter02
2025-02-21 23:29:37,529 - DEBUG2: Collecting tags for decorerouter02
2025-02-21 23:29:37,971 - DEBUG2: Found a exact matching virtual machine object: decorerouter02 (CLUSTER)
2025-02-21 23:29:37,972 - DEBUG2: Found a matching virtual machine object: decorerouter02 (CLUSTER)
2025-02-21 23:29:37,972 - DEBUG2: Parsing 'virtual machine' data structure: decorerouter02
2025-02-21 23:29:37,972 - DEBUG2: Found a matching vm_role_relation 'Router' (.*router.*) for decorerouter02
2025-02-21 23:29:37,972 - DEBUG2: Parsing 'virtual machine' data structure: decorerouter02
2025-02-21 23:29:37,975 - DEBUG2: Found '6' NICs in NetBox for 'decorerouter02'

patschi avatar Feb 21 '25 23:02 patschi

Hi,

thank you for testing it again.

I'm not sure if just doing a grep on the hostname will reveal the issue. would you mind sending me the whole log (somehow secure)?

There seems to be an issue to determine which of the 6 interfaces is the one with the default route and therefore can't make an assumption which IP address should be the primary one.

This is the bit which tries to figure this out: https://github.com/bb-Ricardo/netbox-sync/blob/3c07a4c001443f50d95ae4668c931599e41efeae/module/sources/vmware/connection.py#L2218-L2239

and one of the IPs need to find into the same network and prefix as the gateway in order to be considered the primary IP address.

bb-Ricardo avatar Feb 22 '25 09:02 bb-Ricardo