Skip to content

RESTCONF PUT¤

Use restconf_put to replace configuration at a RESTCONF resource. Choose PUT when you intend to supply the configuration for the addressed resource, rather than merge selected values.

Output¤

Each host's reply appears under put. 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 the Loopback100 configuration. Paths and payload fields must match the device's supported YANG models.

nf# nornir restconf put 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_put",
    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_put/",
    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_put/' \
  -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 put tool to replace the configuration of Loopback100
on ceos-spine-1. Set its type to software loopback and its description to
"configured using NorFab". Report the result.

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.

PUT replaces configuration at the addressed resource; use PATCH when the device supports merging selected values.

Task Command Shell Reference¤

nf# man tree nornir.restconf.put

Python API Reference¤

Replace a RESTCONF resource.

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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
@Task(
    input=RestconfPutInput,
    output=NornirSerializedResult,
    fastapi={"methods": ["POST"]},
    mcp={
        "annotations": {
            "title": "RESTCONF Put",
            "readOnlyHint": False,
            "destructiveHint": True,
            "idempotentHint": True,
            "openWorldHint": True,
        }
    },
)
def restconf_put(
    self,
    job: Job,
    url: str = None,
    params: dict[str, Any] = None,
    headers: dict[str, str] = None,
    data: str = None,
    job_data: Any = None,
    **kwargs: Any,
) -> Result:
    """Replace a RESTCONF resource.

    Args:
        job: NorFab job metadata.
        url: Literal resource relative to inventory base_url, or absolute URL.
        params: HTTP query parameters.
        headers: HTTP headers replacing inventory headers when supplied.
        data: Request body text or inline/nf:// Jinja2 template.
        job_data: Template context data or URL to a YAML data file.
        **kwargs: Common Nornir host filters, processors, runner and result options.

    Returns:
        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:
        FileNotFoundError: If a template cannot be downloaded.
        ValueError: If the removed json argument is supplied.
    """
    return self._run_restconf(
        job,
        "put",
        url=url,
        params=params,
        headers=headers,
        data=data,
        job_data=job_data,
        **kwargs,
    )