Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
blipnet opened this issue Jun 21, 2023 · 4 comments · Fixed by #12979
Closed

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

blipnet opened this issue Jun 21, 2023 · 4 comments · Fixed by #12979
Assignees
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@blipnet
Copy link

blipnet commented Jun 21, 2023

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

@blipnet blipnet added the type: bug A confirmed report of unexpected behavior in the application label Jun 21, 2023
@jeremystretch
Copy link
Member

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 jeremystretch added the status: revisions needed This issue requires additional information to be actionable label Jun 21, 2023
@kkthxbye-code
Copy link
Contributor

kkthxbye-code commented Jun 21, 2023

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

b64b19a#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 kkthxbye-code added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation and removed status: revisions needed This issue requires additional information to be actionable labels Jun 21, 2023
@abhi1693 abhi1693 self-assigned this Jun 21, 2023
@abhi1693 abhi1693 added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Jun 21, 2023
abhi1693 added a commit that referenced this issue Jun 23, 2023
@jeremystretch jeremystretch added the severity: medium Results in substantial degraded or broken functionality for specfic workflows label Jun 23, 2023
jeremystretch pushed a commit that referenced this issue Jun 23, 2023
jeremystretch added a commit that referenced this issue Jun 23, 2023
@lethargosapatheia
Copy link

lethargosapatheia commented Jul 8, 2023

Hello,

I've come across this issue in previous versions and then found a related issue from 2018 (#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
Copy link

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"
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants