Skip to content

RESTCONF PATCH¤

Use restconf_patch to update selected values in a RESTCONF resource. The device must support PATCH and the payload format you send.

Output¤

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

nf# nornir restconf patch FL ceos-spine-1 url openconfig-interfaces:interfaces/interface=Loopback100/config data '{"openconfig-interfaces:description":"configured using NorFab"}'
result = client.run_job(
    "nornir",
    "restconf_patch",
    workers="nornir-worker-1",
    kwargs={
        "FL": ["ceos-spine-1"],
        "url": "openconfig-interfaces:interfaces/interface=Loopback100/config",
        "data": '{"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_patch/",
    headers={"Authorization": "Bearer YOUR_TOKEN"},
    json={
        "workers": "nornir-worker-1",
        "FL": ["ceos-spine-1"],
        "url": "openconfig-interfaces:interfaces/interface=Loopback100/config",
        "data": '{"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_patch/' \
  -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:description\":\"configured using NorFab\"}"
}'
Use the NorFab Nornir RESTCONF patch tool to update the description of Loopback100
on ceos-spine-1 to "configured using NorFab". Leave other settings unchanged
and 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.

PATCH payloads and media types vary by device. Set the required Content-Type in inventory or the request headers; NorFab does not convert between patch formats.

Task Command Shell Reference¤

nf# man tree nornir.restconf.patch

Python API Reference¤

Update 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
@Task(
    input=RestconfPatchInput,
    output=NornirSerializedResult,
    fastapi={"methods": ["POST"]},
    mcp={
        "annotations": {
            "title": "RESTCONF Patch",
            "readOnlyHint": False,
            "destructiveHint": True,
            "idempotentHint": False,
            "openWorldHint": True,
        }
    },
)
def restconf_patch(
    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:
    """Update 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,
        "patch",
        url=url,
        params=params,
        headers=headers,
        data=data,
        job_data=job_data,
        **kwargs,
    )