Netbox REST Task¤
task api name:
rest
Sends a direct HTTP request to the configured NetBox REST API. Use this task when a dedicated NetBox worker task does not exist for the endpoint you need.
Inputs¤
| Parameter | Required | Description |
|---|---|---|
api |
Yes | NetBox API path under /api, for example dcim/devices |
method |
No | HTTP method to use, default get |
instance |
No | NetBox instance name to target |
branch |
No | NetBox Branching plugin branch name to use |
**kwargs |
No | Additional request arguments passed to requests, such as params, json, or data |
Output¤
Returns the decoded JSON response from NetBox when possible. If the response is not JSON, the task returns response text or the HTTP status code.
Notes / Gotchas¤
apiis joined under the configured NetBox URL as/api/<api>/.- Request headers, token, SSL verification, and default timeout are set by the worker.
- When
branchis supplied, the worker creates it if missing, rejects a merged branch, waits for it to become ready, and sends its schema ID in theX-NetBox-Branchheader. - On HTTP errors, the task returns the response status code in
result. - The current NFCLI command model does not expose
rest, so use the Python API or other task surfaces.
Examples¤
Context manager:
from norfab.core.nfapi import NorFab
with NorFab(inventory="./inventory.yaml") as nf:
client = nf.make_client()
result = client.run_job(
"netbox",
"rest",
workers="any",
kwargs={
"api": "dcim/devices",
"method": "get",
"params": {"q": "ceos-leaf"},
},
)
Direct lifecycle:
from norfab.core.nfapi import NorFab
nf = NorFab(inventory="./inventory.yaml")
try:
nf.start()
client = nf.make_client()
result = client.run_job(
"netbox",
"rest",
workers="any",
kwargs={
"api": "extras/tags",
"method": "post",
"branch": "planned-change",
"json": {
"name": "automation-managed",
"slug": "automation-managed",
},
},
)
finally:
nf.destroy()
Python API Reference¤
Sends a request to the Netbox REST API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
str
|
The Netbox instance name to get parameters for. |
None
|
branch
|
str
|
NetBox branching plugin branch name to use. |
None
|
method
|
str
|
The HTTP method to use for the request (e.g., 'get', 'post'). Defaults to "get". |
'get'
|
api
|
str
|
The API endpoint to send the request to. Defaults to "". |
''
|
**kwargs
|
Any
|
Additional arguments to pass to the request (e.g., params, data, json). |
{}
|
Returns:
| Type | Description |
|---|---|
Result
|
Union[dict, list]: The JSON response from the API, parsed into a dictionary or list. |
Raises:
| Type | Description |
|---|---|
HTTPError
|
If the HTTP request returned an unsuccessful status code. |
Source code in norfab\workers\netbox_worker\netbox_worker.py
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 | |