Skip to content

NETCONF Copy Configuration¤

Use netconf_copy_config to replace one datastore with configuration from another.

Use Cases¤

Save running configuration to startup, stage running configuration in candidate, or restore running configuration from startup when supported.

How It Works¤

Specify different source and target datastores: running, candidate, or startup. The target is replaced, not merged. A running replacement takes effect immediately; candidate changes need a separate commit. The task does not lock or back up configuration. This interface accepts datastores rather than inline XML or URLs.

Output¤

Each host's XML reply appears under copy_config. Successful datastore operations normally return <ok/>; RPC replies depend on the operation. RPC and connection errors mark hosts as failed. add_details=True includes execution metadata; to_dict=False returns serialized records. XML processors can convert or filter replies.

Examples¤

nf# nornir netconf copy-config source running target startup FL router-1
from norfab.core.nfapi import NorFab

with NorFab(inventory="inventory.yaml") as nf:
    client = nf.make_client()
    result = client.run_job(
        "nornir", "netconf_copy_config",
        kwargs={'source': 'running', 'target': 'startup', 'FL': ['router-1']},
    )
    print(result)

Task Command Shell Reference¤

nf# man tree nornir.netconf.copy_config

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

root
└── nornir:    Nornir service
    └── netconf:    Manage devices using NETCONF
        └── copy-config:    Copy configuration between NETCONF datastores
            ├── 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
            ├── 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'
            ├── source (R):    Datastore to copy from
            └── target (R):    Datastore to replace
nf#

Common host filters, job options, XML processors, and serialization options are also available. ncclient is the default backend; select plugin scrapli to use Scrapli NETCONF.

Python API Reference¤

Replace a target datastore with configuration from another datastore.

Parameters:

Name Type Description Default
job Job

NorFab job metadata.

required
source str

Datastore to copy from: running, candidate, or startup.

required
target str

Datastore to replace: running, candidate, or startup. Must differ from source. Device support is required for both datastores.

required
plugin str

NETCONF backend: ncclient (default) or scrapli.

'ncclient'
**kwargs Any

Common host filters, processors, retries, XML processors, to_dict and add_details serialization options.

{}

Returns:

Name Type Description
Result Result

XML replies under copy_config, normally an ok reply. Replaces the target rather than merging. Running replacements take effect immediately; candidate changes need a separate commit. Does not lock, validate, or commit. Inline XML and URL sources are not exposed. RPC and connection errors mark hosts failed; unmatched hosts return status no_match. to_dict=False returns serialized records. Retries may copy a newer source configuration.

Source code in norfab\workers\nornir_worker\netconf_task.py
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
@Task(
    fastapi={"methods": ["POST"]},
    input=NetconfCopyConfigInput,
    output=NetconfResult,
    mcp={
        "annotations": {
            "title": "NETCONF Copy Configuration",
            "readOnlyHint": False,
            "destructiveHint": True,
            "idempotentHint": True,
            "openWorldHint": True,
        }
    },
)
def netconf_copy_config(
    self,
    job: Job,
    source: str,
    target: str,
    plugin: str = "ncclient",
    **kwargs: Any,
) -> Result:
    """Replace a target datastore with configuration from another datastore.

    Args:
        job: NorFab job metadata.
        source: Datastore to copy from: running, candidate, or startup.
        target: Datastore to replace: running, candidate, or startup. Must
            differ from source. Device support is required for both datastores.
        plugin: NETCONF backend: ncclient (default) or scrapli.
        **kwargs: Common host filters, processors, retries, XML processors,
            to_dict and add_details serialization options.

    Returns:
        Result: XML replies under copy_config, normally an ok reply.
            Replaces the target rather than merging. Running replacements
            take effect immediately; candidate changes need a separate commit.
            Does not lock, validate, or commit. Inline XML and URL sources
            are not exposed. RPC and connection errors mark hosts failed;
            unmatched hosts return status no_match. to_dict=False returns
            serialized records. Retries may copy a newer source configuration.
    """
    return self._run_netconf(
        job,
        call="copy_config",
        plugin=plugin,
        source=source,
        target=target,
        **kwargs,
    )