Skip to content

NETCONF Get Schema¤

Retrieve a YANG module with netconf_get_schema using ncclient or Scrapli. The device must implement NETCONF monitoring get-schema.

Output¤

Use XML processors to convert replies to dictionaries (xmltodict), select XML elements (xpath), or extract flat values (xml-flake).

Per-host XML replies contain the schema text. The operation key is get_schema for ncclient and rpc for Scrapli, which sends the standard RPC directly. Missing modules and unsupported operations mark hosts as failed.

Examples¤

nf# nornir netconf get-schema identifier openconfig-system plugin ncclient FL ceos-spine-1
nf# nornir netconf get-schema identifier openconfig-system plugin scrapli FL ceos-spine-1
from norfab.core.nfapi import NorFab

with NorFab(inventory="inventory.yaml") as nf:
    client = nf.make_client()
    result = client.run_job(
        "nornir", "netconf_get_schema",
        kwargs={"identifier": "openconfig-system", "plugin": "scrapli",
                "FL": ["ceos-spine-1"]},
    )
    print(result)

Notes¤

  • Select an identifier from module names advertised in capabilities, YANG Library, or the NETCONF monitoring schema list. Capabilities may be incomplete and do not guarantee that schema retrieval is available.
  • version selects a revision, usually YYYY-MM-DD. Omit it for server selection.
  • format accepts yang (default) or yin. Imports are not fetched automatically.
  • Configure the backend in the NETCONF inventory.

Troubleshooting¤

For missing-schema errors, verify the identifier and revision against the device schema list. An unsupported-operation error means the device cannot serve the schema through this RPC.

Task Command Shell Reference¤

nf#man tree nornir.netconf.get_schema

R - required field, M - supports multiline input, D - dynamic key

root
└── nornir:    Nornir service
    └── netconf:    Manage devices using NETCONF
        └── get-schema:    Retrieve a YANG module
            ├── timeout:    Job timeout
            ├── workers:    Filter workers to target, default 'all'
            ├── verbose-result:    Control output details, default 'False'
            ├── nowait:    Do not wait for job to complete, default 'False'
            ├── FO:    Filter hosts using a Nornir-Salt Filter Object
            ├── FB:    Filter hosts by name using glob patterns
            ├── FH:    Filter hosts by hostname
            ├── FC:    Filter hosts by name containment pattern
            ├── FR:    Filter hosts by name using regular expressions
            ├── FG:    Filter hosts by group
            ├── FP:    Filter hosts by hostname using IP prefix
            ├── FL:    Filter hosts by names list
            ├── FM:    Filter hosts by platform
            ├── FX:    Exclude hosts by name
            ├── FN:    Negate the host filter match
            ├── on-failed:    Run task on hosts currently marked as failed by Nornir, default 'False'
            ├── to-dict:    Return task results as a dictionary keyed by host, default 'True'
            ├── add-details:    Add Nornir task execution details to results, default 'False'
            ├── progress:    Emit progress events during task execution, default 'True'
            ├── num-workers:    RetryRunner number of threads for task execution
            ├── num-connectors:    RetryRunner number of threads for device connections
            ├── connect-retry:    RetryRunner number of connection attempts
            ├── task-retry:    RetryRunner number of attempts to run each task
            ├── reconnect-on-fail:    RetryRunner reconnects to a host after task failure
            ├── connect-check:    RetryRunner tests TCP connectivity before opening connection
            ├── connect-timeout:    RetryRunner TCP connection check timeout in seconds
            ├── creds-retry:    RetryRunner connection credentials and parameters to retry
            ├── tf:    File group name to save task results on the worker
            ├── tf-skip-failed:    Skip failed task results when saving to file
            ├── diff:    File group name to diff task results against
            ├── diff-last:    Previous saved file version to diff against
            ├── identifier (R):    YANG module name
            ├── version:    Module revision
            ├── format:    Schema format, default 'NetconfSchemaFormat.yang'
            ├── xmltodict:    Convert XML replies to dictionaries with DataProcessor, default 'False'
            ├── xpath:    XPath expression to run with DataProcessor
            ├── xml-flake:    XML flake pattern for DataProcessor
            └── plugin:    NETCONF backend, default 'NetconfPlugin.ncclient'
nf#

Common host filters and job options apply.

Python API Reference¤

Retrieve a YANG module using NETCONF monitoring get-schema.

Parameters:

Name Type Description Default
job Job

NorFab job metadata.

required
identifier str

Module name from capabilities, YANG Library, or the NETCONF monitoring schema list. Capabilities may be incomplete.

required
version str

Optional module revision, normally YYYY-MM-DD. Omit to let the server select a version.

None
format str

Schema format: yang (default) or yin.

'yang'
plugin str

Backend name: ncclient (default) or scrapli.

'ncclient'
**kwargs Any

Common host filters, retries, XML processors (xmltodict, xpath, xml_flake) and serialization options applicable to this task.

{}

Returns:

Name Type Description
Result Result

XML replies containing schema text under get_schema for ncclient or rpc for Scrapli. Missing modules and unsupported schema retrieval mark hosts as failed. Unmatched hosts return status no_match. Imports are not downloaded automatically. Requires the device to implement NETCONF monitoring get-schema.

Source code in norfab\workers\nornir_worker\netconf_task.py
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
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
@Task(
    fastapi={"methods": ["POST"]},
    input=NetconfGetSchemaInput,
    output=NetconfResult,
    mcp={
        "annotations": {
            "title": "NETCONF Get Schema",
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": True,
        }
    },
)
def netconf_get_schema(
    self,
    job: Job,
    identifier: str,
    version: str = None,
    format: str = "yang",
    plugin: str = "ncclient",
    **kwargs: Any,
) -> Result:
    """Retrieve a YANG module using NETCONF monitoring get-schema.

    Args:
        job: NorFab job metadata.
        identifier: Module name from capabilities, YANG Library, or the
            NETCONF monitoring schema list. Capabilities may be incomplete.
        version: Optional module revision, normally YYYY-MM-DD. Omit to let
            the server select a version.
        format: Schema format: yang (default) or yin.
        plugin: Backend name: ncclient (default) or scrapli.
        **kwargs: Common host filters, retries, XML processors (xmltodict,
            xpath, xml_flake) and serialization options applicable to this task.

    Returns:
        Result: XML replies containing schema text under get_schema for
            ncclient or rpc for Scrapli. Missing modules and unsupported
            schema retrieval mark hosts as failed. Unmatched hosts return
            status no_match. Imports are not downloaded automatically.
            Requires the device to implement NETCONF monitoring get-schema.
    """
    if plugin == "scrapli":
        rpc = Element(
            "get-schema",
            xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring",
        )
        SubElement(rpc, "identifier").text = identifier
        if version is not None:
            SubElement(rpc, "version").text = version
        SubElement(rpc, "format").text = format
        return self._run_netconf(
            job,
            call="rpc",
            plugin=plugin,
            filter_=tostring(rpc, encoding="unicode"),
            **kwargs,
        )
    return self._run_netconf(
        job,
        call="get_schema",
        plugin=plugin,
        identifier=identifier,
        version=version,
        format=format,
        **kwargs,
    )