RESTCONF POST¤
Use restconf_post to send a POST request to a device RESTCONF resource. Depending on the
device and resource, POST creates configuration or invokes an operation.
Output¤
Each host's reply appears under post. JSON responses become structured data; other responses
remain text. Successful operations may return an empty string. Connection and device errors mark
hosts failed. add_details=True includes execution details; to_dict=False returns list records.
Examples¤
The example sets interface configuration using POST. Paths and payload fields must match the device's supported YANG models.
nf# nornir restconf post FL ceos-spine-1 url openconfig-interfaces:interfaces/interface=Loopback100/config data '{"openconfig-interfaces:name":"Loopback100","openconfig-interfaces:type":"iana-if-type:softwareLoopback","openconfig-interfaces:description":"configured using NorFab"}'
result = client.run_job(
"nornir",
"restconf_post",
workers="nornir-worker-1",
kwargs={
"FL": ["ceos-spine-1"],
"url": "openconfig-interfaces:interfaces/interface=Loopback100/config",
"data": '{"openconfig-interfaces:name":"Loopback100","openconfig-interfaces:type":"iana-if-type:softwareLoopback","openconfig-interfaces:description":"configured using NorFab"}',
},
)
Replace the address and token with those of your FastAPI service.
Python requests
import requests
response = requests.post(
"http://localhost:8000/api/nornir/restconf_post/",
headers={"Authorization": "Bearer YOUR_TOKEN"},
json={
"workers": "nornir-worker-1",
"FL": ["ceos-spine-1"],
"url": "openconfig-interfaces:interfaces/interface=Loopback100/config",
"data": '{"openconfig-interfaces:name":"Loopback100","openconfig-interfaces:type":"iana-if-type:softwareLoopback","openconfig-interfaces:description":"configured using NorFab"}',
},
timeout=60,
)
response.raise_for_status()
print(response.json())
curl
curl -X POST 'http://localhost:8000/api/nornir/restconf_post/' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
--data '{
"workers": "nornir-worker-1",
"FL": [
"ceos-spine-1"
],
"url": "openconfig-interfaces:interfaces/interface=Loopback100/config",
"data": "{\"openconfig-interfaces:name\":\"Loopback100\",\"openconfig-interfaces:type\":\"iana-if-type:softwareLoopback\",\"openconfig-interfaces:description\":\"configured using NorFab\"}"
}'
Use the NorFab Nornir RESTCONF post tool to configure Loopback100 on ceos-spine-1
as a software loopback with the description "configured using NorFab".
Report whether the operation succeeded.
Use a payload file¤
Publish a JSON payload as restconf/interface.json.j2 under the FileSharing inventory root.
For example, this template sets the interface description to the selected host's name:
{"openconfig-interfaces:description": "configured on {{ host.name }}"}
Supply nf://restconf/interface.json.j2 as data through any interface. Inline data also supports
Jinja2. Use job_data to provide additional template values. The payload is sent as text; configure
its Content-Type in HTTP inventory. Resource paths are not rendered.
Notes¤
Configure the device endpoint, credentials, TLS verification, HTTP timeout and default headers in
HTTP inventory. Relative resource
paths use its RESTCONF base URL. Use params for query parameters and headers when a request
needs different headers; supplied headers replace the inventory mapping.
The CLI timeout controls waiting for the NorFab job. Device requests use the configured Nornir
runner, including its retry settings. Review those settings before configuration changes.
Task Command Shell Reference¤
nf# man tree nornir.restconf.post
Python API Reference¤
Create or update a RESTCONF resource using POST.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job
|
NorFab job metadata. |
required |
url
|
str
|
Literal resource relative to inventory base_url, or absolute URL. |
None
|
params
|
dict[str, Any]
|
HTTP query parameters. |
None
|
headers
|
dict[str, str]
|
HTTP headers replacing inventory headers when supplied. |
None
|
data
|
str
|
Request body text or inline/nf:// Jinja2 template. |
None
|
job_data
|
Any
|
Template context data or URL to a YAML data file. |
None
|
**kwargs
|
Any
|
Common Nornir host filters, processors, runner and result options. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
Per-host response payloads keyed by the HTTP verb, or list records. HTTP failures remain failed host results; no_match means no selected hosts. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If a template cannot be downloaded. |
ValueError
|
If the removed json argument is supplied. |
Source code in norfab\workers\nornir_worker\restconf_task.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |