netbox-python icon indicating copy to clipboard operation
netbox-python copied to clipboard

bug: nb.ipam.prefixes.update not working as expected

Open sboutang opened this issue 2 years ago • 1 comments

Bug Report

NetBox Python version: 0.1.6

Current behavior: no update happens

When I use nb.ipam.prefixes.update, no update happens Expected behavior: I would expect the http patch data to update and the server to respond with the updated data.

I excpect the server to respond with the changed data Steps to reproduce: Below code, is a simple example of just trying to update a description

Related code:

In the below code I am just trying to change the description. It doesn't update using the netbox-python module

when I re-write it to use the requests module it does update as expected

#!/usr/bin/env python3 import json import requests from netbox_python import NetBoxClient, Result nb = NetBoxClient( base_url="https://netbox.domain.com/", token="<YOUR_TOKEN_HERE>" )

def update_prefix(): prefix_id = 682 data = {"id": 682, "prefix": "192.168.71.0/25", "description": "LAB Management", "site": {"id": 279}, "tenant": {"id": 2}, "vlan": {"id": 637}} ret = nb.ipam.prefixes.update(prefix_id, json=data) print(f"status code: {ret.response.status_code}") print("netbox-python module prefixes update:") print(json.dumps(ret.data, indent=2))

url = "https://netbox.domain.com/api/ipam/prefixes/{}/".format(prefix_id)
headers = {
    "Authorization": "Token <YOUR_TOKEN_HERE>",
    "Content-Type": "application/json"
    }
data = {"id": 682, "prefix": "192.168.71.0/25", "description": "LAB Management", "site": {"id": 279}, "tenant": {"id": 2}, "vlan": {"id": 637}}
ret = requests.patch(url, json=data, headers=headers)
print(f"status code: {ret.status_code}")
print("requests module prefixes update:")
print(json.dumps(ret.json(), indent=2))

if name == "main": update_prefix()


output below: status code: 200 netbox-python module prefixes update: { "id": 682, "url": "http://netbox.domain.com/api/ipam/prefixes/682/", "family": { "value": 4, "label": "IPv4" }, "prefix": "192.168.71.0/25", "site": { "id": 279, "url": "http://netbox.domain.com/api/dcim/sites/279/", "name": "LAB", "slug": "lab" }, "vrf": null, "tenant": { "id": 2, "url": "http://netbox.domain.com/api/tenancy/tenants/2/", "name": "SCA", "slug": "sca" }, "vlan": { "id": 637, "url": "http://netbox.domain.com/api/ipam/vlans/637/", "vid": 100, "name": "Management", "display_name": "Management (100)" }, "status": { "value": "active", "label": "Active" }, "role": null, "is_pool": false, "description": "BAD BAD BAD Description", "tags": [], "custom_fields": { "ActiveDirectorySite": false }, "created": "2023-09-26", "last_updated": "2023-09-26T13:10:43.854351Z" } status code: 200 requests module prefixes update: { "id": 682, "url": "http://netbox.domain.com/api/ipam/prefixes/682/", "family": { "value": 4, "label": "IPv4" }, "prefix": "192.168.71.0/25", "site": { "id": 279, "url": "http://netbox.domain.com/api/dcim/sites/279/", "name": "LAB", "slug": "lab" }, "vrf": null, "tenant": { "id": 2, "url": "http://netbox.domain.com/api/tenancy/tenants/2/", "name": "SCA", "slug": "sca" }, "vlan": { "id": 637, "url": "http://netbox.domain.com/api/ipam/vlans/637/", "vid": 100, "name": "Management", "display_name": "Management (100)" }, "status": { "value": "active", "label": "Active" }, "role": null, "is_pool": false, "description": "LAB Management", "tags": [], "custom_fields": { "ActiveDirectorySite": false }, "created": "2023-09-26", "last_updated": "2023-09-26T13:10:44.357695Z" }

insert short code snippets here

Other information:

sboutang avatar Sep 26 '23 13:09 sboutang

@sboutang thank you for the report, will take a look into it.

arthanson avatar Sep 26 '23 14:09 arthanson