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

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

Open
sboutang opened this issue Sep 26, 2023 · 1 comment
Open

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

sboutang opened this issue Sep 26, 2023 · 1 comment

Comments

@sboutang
Copy link

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:

@arthanson
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants