Primary IP address remains when underlying IP address object is re-assigned between a device and a VM #4075

Closed
opened 2025-12-29 18:32:58 +01:00 by adam · 6 comments
Owner

Originally created by @cpmills1975 on GitHub (Sep 8, 2020).

Originally assigned to: @jeremystretch on GitHub.

Environment

  • Python version: 3.7.9
  • NetBox version: 2.9.3

Steps to Reproduce

  1. Create a device with some ports
  2. Add a new IP address to one of the ports and mark it as primary for the device
  3. Create a virtual machine with some interfaces
  4. Assign the same IP to the interface, again marking it as primary
  5. Observe that the IP address has been re-assigned (moved) from the source port on the device to the destination interface on the virtual machine
  6. Observe however that the IP address remains listed as the primary IP address on both the device and the virtual machine

Expected Behavior

Ideally the assignment should fail. If it is permitted, the IP address should be removed completely from the original device (both disassociated with the port/interface it was assigned to and the device/VMs primary IP address).

Observed Behavior

When attempting to assign an existing IP to a device that is already the primary IP of another device, the assignment fails. Likewise when attempting to assign an existing IP to a VM that is already the primary IP of another VM, the assignment fails. This behaviour does not occur when assigning an existing IP to a VM that is already a primary IP of a device. While the IP address is disassociated with the source port/interface, it is NOT removed as the primary IP address of the source device/vm leaving two objects both claiming that the IP address is it's primary.

Originally created by @cpmills1975 on GitHub (Sep 8, 2020). Originally assigned to: @jeremystretch on GitHub. <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report, and that any plugins have been disabled. --> ### Environment * Python version: 3.7.9 * NetBox version: 2.9.3 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox. Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox. --> ### Steps to Reproduce 1. Create a device with some ports 2. Add a new IP address to one of the ports and mark it as primary for the device 3. Create a virtual machine with some interfaces 4. Assign the same IP to the interface, again marking it as primary 5. Observe that the IP address has been re-assigned (moved) from the source port on the device to the destination interface on the virtual machine 6. Observe however that the IP address remains listed as the primary IP address on both the device and the virtual machine <!-- What did you expect to happen? --> ### Expected Behavior Ideally the assignment should fail. If it is permitted, the IP address should be removed completely from the original device (both disassociated with the port/interface it was assigned to and the device/VMs primary IP address). <!-- What happened instead? --> ### Observed Behavior When attempting to assign an existing IP to a device that is already the primary IP of another device, the assignment fails. Likewise when attempting to assign an existing IP to a VM that is already the primary IP of another VM, the assignment fails. This behaviour does not occur when assigning an existing IP to a VM that is already a primary IP of a device. While the IP address is disassociated with the source port/interface, it is NOT removed as the primary IP address of the source device/vm leaving two objects both claiming that the IP address is it's primary.
adam added the type: bugstatus: accepted labels 2025-12-29 18:32:58 +01:00
adam closed this issue 2025-12-29 18:32:58 +01:00
Author
Owner

@DanSheps commented on GitHub (Sep 8, 2020):

I am unable to reproduce this on 2.9.3, could you please include all steps to reproduce this?

@DanSheps commented on GitHub (Sep 8, 2020): I am unable to reproduce this on 2.9.3, could you please include all steps to reproduce this?
Author
Owner

@jeremystretch commented on GitHub (Sep 8, 2020):

Note that it's entirely possible to re-assign an IP address from a device to a virtual machine, but in doing so the IP address is no longer assigned to the device.

@jeremystretch commented on GitHub (Sep 8, 2020): Note that it's entirely possible to _re-assign_ an IP address from a device to a virtual machine, but in doing so the IP address is no longer assigned to the device.
Author
Owner

@cpmills1975 commented on GitHub (Sep 8, 2020):

I'd expect that re-assignment was possible - that's no problem.

From a totally blank instance of 2.9.3 (via netbox-docker), I created a new device, added a NEW IP address to one of it's ports and made it primary, created a VM and attempted to assign the same IP (by searching for it in the assign page) to the VM. The IP address shows that it is assigned to the VM and the API reflects this, but if I go back to the device, the device's primary IP is still shown but, ah, the IP is indeed no longer associated with the port so it looks like the bug (feature?) might just be in the setting of the primary IP in the device model rather than a bug in the IP address object. I've just attempted to reassign it back to the device and it is also still shown as the primary address on the VM, but like the device behaviour, appears to have been disassociated with the interface I created there.

So the IP seems to 'move' but remains listed as the primary IP address on the previous object (VM or device)

@cpmills1975 commented on GitHub (Sep 8, 2020): I'd expect that re-assignment was possible - that's no problem. From a totally blank instance of 2.9.3 (via netbox-docker), I created a new device, added a NEW IP address to one of it's ports and made it primary, created a VM and attempted to assign the same IP (by searching for it in the assign page) to the VM. The IP address shows that it is assigned to the VM and the API reflects this, but if I go back to the device, the device's primary IP is still shown but, ah, the IP is indeed no longer associated with the port so it looks like the bug (feature?) might just be in the setting of the primary IP in the device model rather than a bug in the IP address object. I've just attempted to reassign it back to the device and it is also still shown as the primary address on the VM, but like the device behaviour, appears to have been disassociated with the interface I created there. So the IP seems to 'move' but remains listed as the primary IP address on the previous object (VM or device)
Author
Owner

@cpmills1975 commented on GitHub (Sep 8, 2020):

@jeremystretch thinking about this, while it is possible to re-assign an IP to a VM when assigned to a device, should it be? The UI prevents this same behaviour if trying to re-assign within the same model - pointing out that the address is already the primary address of another object. I get the idea of constraints and database tables and stuff, but am not knowledgeable enough to know how these are implemented (or not) in Django.

@cpmills1975 commented on GitHub (Sep 8, 2020): @jeremystretch thinking about this, while it is possible to re-assign an IP to a VM when assigned to a device, should it be? The UI prevents this same behaviour if trying to re-assign within the same model - pointing out that the address is already the primary address of another object. I get the idea of constraints and database tables and stuff, but am not knowledgeable enough to know how these are implemented (or not) in Django.
Author
Owner

@jeremystretch commented on GitHub (Sep 9, 2020):

I created a new device, added a NEW IP address to one of it's ports and made it primary

@cpmills1975 your initial bug report makes no mention of this. Please update your original post to include the complete list of actions being taken.

@jeremystretch commented on GitHub (Sep 9, 2020): > I created a new device, added a NEW IP address to one of it's ports and made it primary @cpmills1975 your initial bug report makes no mention of this. Please update your original post to include the **complete** list of actions being taken.
Author
Owner

@cpmills1975 commented on GitHub (Sep 11, 2020):

@jeremystretch initial description updated to reflect my more recent observations.

@cpmills1975 commented on GitHub (Sep 11, 2020): @jeremystretch initial description updated to reflect my more recent observations.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4075