Unable to set VM primary_ip4 or primary_ip6 via GUI #4016

Closed
opened 2025-12-29 18:32:37 +01:00 by adam · 1 comment
Owner

Originally created by @candlerb on GitHub (Aug 23, 2020).

Originally assigned to: @jeremystretch on GitHub.

Environment

  • Python version: 3.6.9
  • NetBox version: 2.9.1

Steps to Reproduce

  1. Create a VM with one interface and IPv4 and IPv6 addresses attached to that interface (as per #5037)
  2. In the GUI, edit the VM
  3. Select dropdowns for "primary_ip4" and "primary_ip6"

Expected Behavior

To be able to select the IPv4/IPv6 addresses as primary

Observed Behavior

image

(Note "dcim.Interface.None" is broken). Then when you click Save:

image

However the addresses clearly are assigned to this VM.

Relates to #4721

Originally created by @candlerb on GitHub (Aug 23, 2020). Originally assigned to: @jeremystretch on GitHub. ### Environment * Python version: 3.6.9 * NetBox version: 2.9.1 ### Steps to Reproduce 1. Create a VM with one interface and IPv4 and IPv6 addresses attached to that interface (as per #5037) 2. In the GUI, edit the VM 3. Select dropdowns for "primary_ip4" and "primary_ip6" ### Expected Behavior To be able to select the IPv4/IPv6 addresses as primary ### Observed Behavior ![image](https://user-images.githubusercontent.com/44789/90976561-13b75c80-e536-11ea-8d67-b2ecc26d1e93.png) (Note "dcim.Interface.None" is broken). Then when you click Save: ![image](https://user-images.githubusercontent.com/44789/90976573-2762c300-e536-11ea-934a-d0bada52418d.png) However the addresses clearly *are* assigned to this VM. Relates to #4721
adam added the type: bugstatus: accepted labels 2025-12-29 18:32:38 +01:00
adam closed this issue 2025-12-29 18:32:38 +01:00
Author
Owner

@candlerb commented on GitHub (Aug 24, 2020):

I'm not sure if this is the right fix, but based on what dcim.Interface is doing I changed it as follows and it seems to work:

--- netbox/virtualization/forms.py.orig	2020-08-24 10:14:19.897596228 +0000
+++ netbox/virtualization/forms.py	2020-08-24 10:33:21.664067592 +0000
@@ -333,7 +333,7 @@
                 if interface_ips:
                     ip_choices.append(
                         ('Interface IPs', [
-                            (ip.id, '{} ({})'.format(ip.address, ip.interface)) for ip in interface_ips
+                            (ip.id, '{} ({})'.format(ip.address, ip.assigned_object)) for ip in interface_ips
                         ])
                     )
                 # Collect NAT IPs
(venv) root@netbox:/opt/netbox# diff -u netbox/virtualization/models.py{.orig,}
--- netbox/virtualization/models.py.orig	2020-08-24 10:11:03.993217700 +0000
+++ netbox/virtualization/models.py	2020-08-24 10:31:30.311129430 +0000
@@ -335,9 +335,9 @@
         for field in ['primary_ip4', 'primary_ip6']:
             ip = getattr(self, field)
             if ip is not None:
-                if ip.interface in interfaces:
+                if ip.assigned_object in interfaces:
                     pass
-                elif self.primary_ip4.nat_inside is not None and self.primary_ip4.nat_inside.interface in interfaces:
+                elif self.primary_ip4.nat_inside is not None and self.primary_ip4.nat_inside.assigned_object in interfaces:
                     pass
                 else:
                     raise ValidationError({

This fixes #5037 as well.

@candlerb commented on GitHub (Aug 24, 2020): I'm not sure if this is the right fix, but based on what dcim.Interface is doing I changed it as follows and it seems to work: ``` --- netbox/virtualization/forms.py.orig 2020-08-24 10:14:19.897596228 +0000 +++ netbox/virtualization/forms.py 2020-08-24 10:33:21.664067592 +0000 @@ -333,7 +333,7 @@ if interface_ips: ip_choices.append( ('Interface IPs', [ - (ip.id, '{} ({})'.format(ip.address, ip.interface)) for ip in interface_ips + (ip.id, '{} ({})'.format(ip.address, ip.assigned_object)) for ip in interface_ips ]) ) # Collect NAT IPs (venv) root@netbox:/opt/netbox# diff -u netbox/virtualization/models.py{.orig,} --- netbox/virtualization/models.py.orig 2020-08-24 10:11:03.993217700 +0000 +++ netbox/virtualization/models.py 2020-08-24 10:31:30.311129430 +0000 @@ -335,9 +335,9 @@ for field in ['primary_ip4', 'primary_ip6']: ip = getattr(self, field) if ip is not None: - if ip.interface in interfaces: + if ip.assigned_object in interfaces: pass - elif self.primary_ip4.nat_inside is not None and self.primary_ip4.nat_inside.interface in interfaces: + elif self.primary_ip4.nat_inside is not None and self.primary_ip4.nat_inside.assigned_object in interfaces: pass else: raise ValidationError({ ``` This fixes #5037 as well.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4016