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

[VCenter] IP addresses marked as orphan when VM is turned off

Open rizlas opened this issue 2 years ago • 17 comments

Hi, I recently noted that if a VM is turned off the IPs synced in NetBox are marked as orphans. This could lead to a misunderstanding in IPAM documentation because after "orphans cleanup/deletion" that IPs are marked as "free to use" in NetBox but actually they aren't.

Currently running v1.2.3

rizlas avatar May 18 '22 07:05 rizlas

Hi, I have a look. This is not meant to happen.

bb-Ricardo avatar May 18 '22 11:05 bb-Ricardo

Yeah thank you, in the meantime I'll try to do some other tests.

rizlas avatar May 18 '22 12:05 rizlas

Hey @rizlas,

I just checked and figured this is the default. If the VM is stopped, the IP address is not visible via the VMWare API. The IP address was initially found on this interface and added via netbox-sync. Now the IP address can't be found anymore and therefore marked orphaned.

bb-Ricardo avatar May 18 '22 13:05 bb-Ricardo

Unlucky, thank you for digging into this. Sorry also about the issue.

rizlas avatar May 19 '22 06:05 rizlas

Unlucky, thank you for digging into this. Sorry also about the issue.

Don't be sorry about opening an issue. It usually is an "issue" or "unwanted behaviour".

I also thought about this. It seems a bit difficult to implement but: If an IP address belongs to a VM which is currently only "inactive" then we should refrain from marking it as orphan. This is a totally valid use case.

bb-Ricardo avatar May 19 '22 06:05 bb-Ricardo

Good point! Maybe netbox-sync can change only the status of the IpAddress to Reserverd when a VM has an offline status? Just an idea..

rizlas avatar May 20 '22 08:05 rizlas

Hi, i JUST implemented this. Now the IP address will not be marked orphaned if it belongs to a device/vm object which is present but not in status "active".

bb-Ricardo avatar May 20 '22 08:05 bb-Ricardo

Amazing! Thank you!

rizlas avatar May 20 '22 09:05 rizlas

fix is pushed to "development" branch. Can you please test it out?

bb-Ricardo avatar May 20 '22 09:05 bb-Ricardo

So i tried:

  • if delete orphan is set to 0, IP will be deleted anyway
  • Cleaning the tag before run. After run no tag added - Raised delete orphan > 0. Tag is NOT removed

rizlas avatar May 24 '22 16:05 rizlas

Hi, I don't really know what are the preconditions to your findings. Unfortunately I won't be able to test it by myself.

here is the relevant code: https://github.com/bb-Ricardo/netbox-sync/blob/c4e0e7772604bf2b0dab662dca65d00fffb9d719/module/netbox/inventory.py#L314-L325

Enabling or disabling prune_enabled and changing prune_delay_in_days has no effect on tagging objects as orphaned.

Does this information help?

bb-Ricardo avatar May 24 '22 19:05 bb-Ricardo

Preconditions are: VM has state set to Offline, IP address bonded to that VM is already been tagged has orphan.

rizlas avatar May 25 '22 08:05 rizlas

A better explanation.. Currently the update works, but it's is not backward compatible especially if a tag is already there it is not cleaned.

rizlas avatar May 29 '22 13:05 rizlas

This is still ongoing?

rizlas avatar Jul 21 '22 12:07 rizlas

Hi, yes this is still ongoing. Need to take care of it when syncing from NetBox. Only did the part with syncing to NetBox.

Currently on holidays and will have a look once I'm back.

bb-Ricardo avatar Jul 21 '22 17:07 bb-Ricardo

Hi, yes this is still ongoing. Need to take care of it when syncing from NetBox. Only did the part with syncing to NetBox.

Currently on holidays and will have a look once I'm back.

bb-Ricardo avatar Jul 21 '22 17:07 bb-Ricardo

Ah don't worry. It was only for information. Enjoy your holiday 👍🏻

rizlas avatar Jul 22 '22 07:07 rizlas

Hi @rizlas,

sorry for the long wait. I'm back again and I just pushed another change to development. Would you mind testing it? This should solve your issue.

You can close the ticket if the issue is resolved.

bb-Ricardo avatar Aug 24 '22 19:08 bb-Ricardo

Hi, thank you. It is working.

Test:

  • Turn off a Vm
  • Sync
  • IP not removed nor tagged as orphan

rizlas avatar Aug 25 '22 07:08 rizlas

Thank you for testing

bb-Ricardo avatar Aug 25 '22 07:08 bb-Ricardo