Can't assign primary IP when creating new IP address #8218

Closed
opened 2025-12-29 20:33:57 +01:00 by adam · 4 comments
Owner

Originally created by @blipnet on GitHub (Jun 21, 2023).

Originally assigned to: @abhi1693 on GitHub.

NetBox version

v3.5.4

Python version

3.8

Steps to Reproduce

  1. Click add new IP address
  2. Assign address to an Interface
  3. Check "Make this primary IP for device/VM"
  4. Click Create button

This is not possible anymore, getting below error message

image

Expected Behavior

  1. Click add new IP address
  2. Assign address to an Interface
  3. Check "Make this primary IP for device/VM"
  4. Click Create button

Observed Behavior

image

Originally created by @blipnet on GitHub (Jun 21, 2023). Originally assigned to: @abhi1693 on GitHub. ### NetBox version v3.5.4 ### Python version 3.8 ### Steps to Reproduce 1. Click add new IP address 2. Assign address to an Interface 3. Check "Make this primary IP for device/VM" 4. Click Create button This is not possible anymore, getting below error message ![image](https://github.com/netbox-community/netbox/assets/28634241/57a22238-592a-434d-8ae6-90a0212847af) ### Expected Behavior 1. Click add new IP address 2. Assign address to an Interface 3. Check "Make this primary IP for device/VM" 4. Click Create button ### Observed Behavior ![image](https://github.com/netbox-community/netbox/assets/28634241/ba7eae8d-137b-49b9-a6e8-117db3b137f3)
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 20:33:57 +01:00
adam closed this issue 2025-12-29 20:33:57 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jun 21, 2023):

Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.

@jeremystretch commented on GitHub (Jun 21, 2023): Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.
Author
Owner

@kkthxbye-code commented on GitHub (Jun 21, 2023):

I can replicate this fine. The fix here is broken:

b64b19a3f4 (diff-04bd663083dc2a523d431cef07afcaba54ea042bd1113aabcf88afd3d92de1d3R350)

For new objects self.instance will be an empty IPAddress object so it will always fail. It needs a check for self.instance.pk before doing the comparison.

Replication steps if the original were not enough:

  1. Create a manufacturer mf
  2. Create a site si
  3. Create a device role dr
  4. Create a device type dt with manufacturer set to mf
  5. Create a device d of device type dt on site si
  6. Create an interface on the d device named inf of 1000BASE-T (1GE).
  7. Create an IP address 9.9.9.9/29 with assignment to interface inf and mark the primary IP field.
  8. Save the IP
@kkthxbye-code commented on GitHub (Jun 21, 2023): I can replicate this fine. The fix here is broken: https://github.com/netbox-community/netbox/commit/b64b19a3f4011be1fc3889d2668b26e3135cadf2#diff-04bd663083dc2a523d431cef07afcaba54ea042bd1113aabcf88afd3d92de1d3R350 For new objects `self.instance` will be an empty IPAddress object so it will always fail. It needs a check for `self.instance.pk` before doing the comparison. Replication steps if the original were not enough: 1. Create a manufacturer `mf` 2. Create a site `si` 3. Create a device role `dr` 4. Create a device type `dt` with manufacturer set to `mf` 5. Create a device `d` of device type `dt` on site `si` 6. Create an interface on the `d` device named `inf` of 1000BASE-T (1GE). 7. Create an IP address `9.9.9.9/29` with assignment to interface `inf` and mark the primary IP field. 8. Save the IP
Author
Owner

@lethargosapatheia commented on GitHub (Jul 8, 2023):

Hello,

I've come across this issue in previous versions and then found a related issue from 2018 (https://github.com/netbox-community/netbox/issues/2342), then someone pointed to me that the issue has been solved in a following release, unfortunately this isn't the case.

The way I'm testing it is this:
I have the virtual machines ceph-mon-001 and ceph-mon-002, each with their own IP, both IPs are primary IPs.
ceph-mon-001's IP is 10.88.88.175
ceph-mon-002's IP is 10.88.88.176

I'm making the changes through the API (pynetbox).
I've assigned IP 10.88.88.176 to ceph-mon-001's interface:

In [62]: my_ip.assigned_object_id
Out[62]: 92

92 is the id of the ceph-mon-002's network interface.
I'm reassigning it to ceph-mon-001 (whose network interface ID is 40):

In [68]: my_ip.assigned_object_id = 40

In [69]: my_ip.save()
Out[69]: True

However the primary IP of ceph-mon-002 doesn't change:

In [72]: ceph2.name
Out[72]: 'ceph-mon-002'

In [73]: ceph2.primary_ip
Out[73]: 10.88.88.176/24

This is confirmed on the GUI, in that, in the VM section, I can see the primary ip:
primip1

But when I try to edit the VM, I'm not seeing it set as primary ip:
ipedit

The only way I can remove it as a primary IP is through pynetbox:

In [85]: ceph2.primary_ip4 = None

In [86]: ceph2.save()
Out[86]: True

I'm using version 3.5.5 on Ubuntu 22.04

@lethargosapatheia commented on GitHub (Jul 8, 2023): Hello, I've come across this issue in previous versions and then found a related issue from 2018 (https://github.com/netbox-community/netbox/issues/2342), then someone pointed to me that the issue has been solved in a following release, unfortunately this isn't the case. The way I'm testing it is this: I have the virtual machines ceph-mon-001 and ceph-mon-002, each with their own IP, both IPs are primary IPs. ceph-mon-001's IP is 10.88.88.175 ceph-mon-002's IP is 10.88.88.176 I'm making the changes through the API (pynetbox). I've assigned IP 10.88.88.176 to ceph-mon-001's interface: ``` In [62]: my_ip.assigned_object_id Out[62]: 92 ``` 92 is the id of the ceph-mon-002's network interface. I'm reassigning it to ceph-mon-001 (whose network interface ID is 40): ``` In [68]: my_ip.assigned_object_id = 40 In [69]: my_ip.save() Out[69]: True ``` However the primary IP of ceph-mon-002 doesn't change: ``` In [72]: ceph2.name Out[72]: 'ceph-mon-002' In [73]: ceph2.primary_ip Out[73]: 10.88.88.176/24 ``` This is confirmed on the GUI, in that, in the VM section, I can see the primary ip: <img width="629" alt="primip1" src="https://github.com/netbox-community/netbox/assets/22618815/486d3b89-971c-40a1-b9cc-45209f7d184d"> But when I try to edit the VM, I'm not seeing it set as primary ip: <img width="682" alt="ipedit" src="https://github.com/netbox-community/netbox/assets/22618815/077d0a2e-1a51-4b76-a2ff-fbcc02e62c24"> The only way I can remove it as a primary IP is through pynetbox: ``` In [85]: ceph2.primary_ip4 = None In [86]: ceph2.save() Out[86]: True ``` I'm using version 3.5.5 on Ubuntu 22.04
Author
Owner

@lethargosapatheia commented on GitHub (Jul 9, 2023):

I will translate here the commands from pynetbox to plain curl requests (as someone on the slack channel has suggested) so that this is unambiguous:

curl -H "Authorization: Token <TOKEN>" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" -X PATCH -d '{"assigned_object_id": 40}' https://netbox-company.com/api/ipam/ip-addresses/735/

So in this case I'm reassigning IP id 735(10.88.88.176/24) from the network id of ceph-mon-002 (92) to the network id of ceph-mon-001 (40).

At this point ceph-mon-002's only network interface has no ip at all. Nonetheless I'm still seeing the ip 10.88.88.176 as primary IP:

cephmon002

Also checking the primary IPs of ceph-mon-002 directly through curl confirms this:

curl -H "Authorization: Token <TOKEN>" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" -X GET https://netbox-company.com/api/virtualization/virtual-machines/72/
{
  "id": 735,
  "url": "https://netbox-company.com/api/ipam/ip-addresses/735/",
  "display": "10.88.88.176/24",
  "family": 4,
  "address": "10.88.88.176/24"
}
{
  "id": 735,
  "url": "https://netbox-company.com/api/ipam/ip-addresses/735/",
  "display": "10.88.88.176/24",
  "family": 4,
  "address": "10.88.88.176/24"
}
@lethargosapatheia commented on GitHub (Jul 9, 2023): I will translate here the commands from pynetbox to plain curl requests (as someone on the slack channel has suggested) so that this is unambiguous: ```bash curl -H "Authorization: Token <TOKEN>" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" -X PATCH -d '{"assigned_object_id": 40}' https://netbox-company.com/api/ipam/ip-addresses/735/ ``` So in this case I'm reassigning IP id `735`(`10.88.88.176/24`) from the network id of ceph-mon-002 (`92`) to the network id of ceph-mon-001 (`40`). At this point ceph-mon-002's only network interface has no ip at all. Nonetheless I'm still seeing the ip `10.88.88.176` as primary IP: <img width="711" alt="cephmon002" src="https://github.com/netbox-community/netbox/assets/22618815/04605e8e-4707-4421-80c1-fac78b792382"> Also checking the primary IPs of ceph-mon-002 directly through curl confirms this: ``` curl -H "Authorization: Token <TOKEN>" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" -X GET https://netbox-company.com/api/virtualization/virtual-machines/72/ ``` ```json { "id": 735, "url": "https://netbox-company.com/api/ipam/ip-addresses/735/", "display": "10.88.88.176/24", "family": 4, "address": "10.88.88.176/24" } { "id": 735, "url": "https://netbox-company.com/api/ipam/ip-addresses/735/", "display": "10.88.88.176/24", "family": 4, "address": "10.88.88.176/24" } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8218