bb-Ricardo / netbox-sync

Sync objects from VMware or redfish sources to NetBox
MIT License
290 stars 65 forks source link

Allow to avoid overriding the Devices Site with the default site (vCenter: <vcenter-name>) #409

Open joachimBurket opened 2 months ago

joachimBurket commented 2 months ago

I have some Hosts in the vCenter for which the site can't be inferred from the name, and therefore are set to the default site (vCenter: <vcenter-name>) by the sync. I then manually put the Devices in the right Site and Rack. But then on the next run of the sync script, those Devices generates errors because the sync tries to override the Site to the default. Example of error:

2024-08-10 02:20:02,151 - ERROR: NetBox returned: PATCH /api/dcim/devices/4707/ Bad Request
2024-08-10 02:20:02,151 - ERROR: NetBox returned body: {'rack': ['Rack XYZ does not belong to site vCenter: <vcenter-name>.']}

Is there a way to bypass the override of the Site when the device already has a Site in NetBox that is not the default one?

bb-Ricardo commented 2 months ago

Hi,

do these devices belong to a cluster? Or are they stand alone ESXi hosts? Please have a look at the cluster_site_relation setting.

joachimBurket commented 2 months ago

Hi! They do belong to clusters, but these clusters have their Site to <NONE>, because our Clusters aren't specific to a Site We therefore used the host_site_relation to place the Hosts depdending on their name, which works for most of our devices. But we still have some devices that aren't named conventionally and are placed in the default site.

A workaround could be to add those Devices in the host_site_relation, but it is not very practical, as we would need to update the settings.yaml for any new unconventional Device.

An interesting feature for us would be to be able to set a default value for the different relations in the settings file (for instance the host_site_relation), and then being able to configure the sync so that it doesn't override the values in NetBox that were changed from the default one to another value. Would it make sense to you?

bb-Ricardo commented 2 months ago

This sounds like to be solvable with some bash, yq and curl glue.

Quick idea:

This way you can automate this process. Or you can set the config option via an environment variable.