Unable to set VM primary_ip4 or primary_ip6 via API #4017

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

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

Environment

  • Python version: 3.6.9
  • NetBox version: 2.9.1

Steps to Reproduce

  1. Create a VM (note the ID: in this example it's 74)
  2. Create an interface attached to the VM
  3. Create IPv4 and IPv6 addresses attached to the VM (note the IDs: here 242 and 243)
  4. Attempt to use the API to set primary_ip4 and primary_ip6 on the VM to point to the addresses created in (3)
# curl -X PATCH -H 'authorization: Token XXXXXXXX' -H 'Content-Type: application/json' \
-d '{"primary_ip4":{"id":242},"primary_ip6":{"id":243}}' http://netbox.example.net/api/virtualization/virtual-machines/74/

Expected Behavior

primary_ip4 and primary_ip6 to be set

Observed Behavior

{"primary_ip4":["The specified IP address (192.0.2.99/32) is not assigned to this VM."]}

However it clearly is assigned to the VM, as the following API query demonstrates:

root@nuc1:~# curl -Ss http://netbox.example.net/api/ipam/ip-addresses/242/ | python3 -m json.tool
{
    "id": 242,
    "url": "http://netbox.example.net/api/ipam/ip-addresses/242/",
    "family": {
        "value": 4,
        "label": "IPv4"
    },
    "address": "192.0.2.99/32",
    "vrf": null,
    "tenant": null,
    "status": {
        "value": "active",
        "label": "Active"
    },
    "role": null,
    "assigned_object_type": "virtualization.vminterface",
    "assigned_object_id": 39,
    "assigned_object": {
        "id": 39,
        "url": "http://netbox.example.net/api/virtualization/interfaces/39/",
        "virtual_machine": {
            "id": 74,
            "url": "http://netbox.example.net/api/virtualization/virtual-machines/74/",
            "name": "foobar"
        },
        "name": "eth0"
    },
    "nat_inside": null,
    "nat_outside": null,
    "dns_name": "foobar.example.net",
    "description": "",
    "tags": [],
    "custom_fields": {},
    "created": "2020-08-23",
    "last_updated": "2020-08-23T10:17:39.125794Z"
}

This is presumably related to #4721

Originally created by @candlerb on GitHub (Aug 23, 2020). ### Environment * Python version: 3.6.9 * NetBox version: 2.9.1 ### Steps to Reproduce 1. Create a VM (note the ID: in this example it's 74) 2. Create an interface attached to the VM 3. Create IPv4 and IPv6 addresses attached to the VM (note the IDs: here 242 and 243) 4. Attempt to use the API to set primary_ip4 and primary_ip6 on the VM to point to the addresses created in (3) ``` # curl -X PATCH -H 'authorization: Token XXXXXXXX' -H 'Content-Type: application/json' \ -d '{"primary_ip4":{"id":242},"primary_ip6":{"id":243}}' http://netbox.example.net/api/virtualization/virtual-machines/74/ ``` ### Expected Behavior primary_ip4 and primary_ip6 to be set ### Observed Behavior ``` {"primary_ip4":["The specified IP address (192.0.2.99/32) is not assigned to this VM."]} ``` However it clearly *is* assigned to the VM, as the following API query demonstrates: ``` root@nuc1:~# curl -Ss http://netbox.example.net/api/ipam/ip-addresses/242/ | python3 -m json.tool { "id": 242, "url": "http://netbox.example.net/api/ipam/ip-addresses/242/", "family": { "value": 4, "label": "IPv4" }, "address": "192.0.2.99/32", "vrf": null, "tenant": null, "status": { "value": "active", "label": "Active" }, "role": null, "assigned_object_type": "virtualization.vminterface", "assigned_object_id": 39, "assigned_object": { "id": 39, "url": "http://netbox.example.net/api/virtualization/interfaces/39/", "virtual_machine": { "id": 74, "url": "http://netbox.example.net/api/virtualization/virtual-machines/74/", "name": "foobar" }, "name": "eth0" }, "nat_inside": null, "nat_outside": null, "dns_name": "foobar.example.net", "description": "", "tags": [], "custom_fields": {}, "created": "2020-08-23", "last_updated": "2020-08-23T10:17:39.125794Z" } ``` This is presumably related 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

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

Fixed in 6e28490 under #5038

@jeremystretch commented on GitHub (Aug 24, 2020): Fixed in 6e28490 under #5038
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4017