Added option to purge remaining devices #199

Merged
geektophe merged 4 commits from fix/chriss/purge_remaining_devices into master 2022-02-21 11:36:39 +01:00
geektophe commented 2022-02-08 18:47:23 +01:00 (Migrated from github.com)

This patch adds an option to clear remaining devices in the context of a new device replacing an old one with the same name but with a different hardware.

The serial leading to the bug is described below:

  • A first server is registered under name A with serial X
  • A second server is registered under name B with serial Y
  • The server with serial X is decomissionned, but not removed
  • The server with serial Y is reinstalled with name A

In this case, a device with serial X is well found, and netbox agent tries to update its name. But this raises an error because of the unique constraint on name, as another device already holds this name.

The proposed solution to handle this situation is to delete any device with same name but different serial before handling a device.

As this is not necessarily the expected behavior, it can be enabled by using the --purge-old-devices to avoid breaking existing inventory.

This patch adds an option to clear remaining devices in the context of a new device replacing an old one with the same name but with a different hardware. The serial leading to the bug is described below: - A first server is registered under name `A` with serial `X` - A second server is registered under name `B` with serial `Y` - The server with serial `X` is decomissionned, but not removed - The server with serial `Y` is reinstalled with name `A` In this case, a device with serial `X` is well found, and netbox agent tries to update its name. But this raises an error because of the unique constraint on name, as another device already holds this name. The proposed solution to handle this situation is to delete any device with same `name` but different `serial` before handling a device. As this is not necessarily the expected behavior, it can be enabled by using the `--purge-old-devices` to avoid breaking existing inventory.
Sign in to join this conversation.
No description provided.