Skip to content

NETCONF Cancel Commit¤

Use netconf_cancel_commit to roll back a pending confirmed commit immediately, instead of waiting for its rollback timer to expire.

Use Cases¤

Cancel a configuration rollout when connectivity or service checks fail after a confirmed commit. Supply the commit's persistence token to cancel it from another NETCONF session.

How It Works¤

The task sends a NETCONF cancel-commit request. The device restores the running configuration to its state before the pending confirmed commit. It must support cancel-commit; normal commits and commits already confirmed cannot be undone with this task.

For a persistent commit, supply its original token as persist_id. Without a token, target the same worker and backend that started the nonpersistent commit, while its NETCONF connection remains open.

Output¤

Each host's XML reply appears under cancel_commit for ncclient or rpc for Scrapli, normally containing <ok/> on success. Unsupported operations, missing pending commits, incorrect tokens, 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¤

Cancel a pending persistent confirmed commit started with persist="change-123":

nf# nornir netconf cancel-commit persist-id change-123 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_cancel_commit",
        kwargs={"persist_id": "change-123", "FL": ["router-1"]},
    )
    print(result)

Task Command Shell Reference¤

nf# man tree nornir.netconf.cancel_commit

cancel-commit: Cancel a pending confirmed commit
├── plugin: NETCONF backend, default ncclient
└── persist-id: Token identifying the persistent confirmed commit to cancel

Common host filters, job options, XML processors, and serialization options are also available.

Python API Reference¤

Cancel a pending confirmed commit and request immediate rollback.

Parameters:

Name Type Description Default
job Job

NorFab job metadata.

required
plugin str

NETCONF backend: ncclient (default) or scrapli.

'ncclient'
persist_id str

Token supplied as persist when starting a persistent confirmed commit. Omit for a nonpersistent commit, which must be cancelled through its original NETCONF session.

None
**kwargs Any

Common host filters, processors, retries, XML processors (xmltodict, xpath, xml_flake), to_dict and add_details options.

{}

Returns:

Name Type Description
Result Result

XML replies under cancel_commit for ncclient or rpc for Scrapli, normally an ok reply on success, or serialized records when to_dict=False. Requires device support for cancel-commit and a pending confirmed commit. RPC, capability and connection errors mark hosts failed; unmatched hosts return status no_match. Does not undo a normal or already confirmed commit. Target the original worker and backend for nonpersistent commits. Retries may report failure after an earlier cancellation succeeded.

Source code in norfab\workers\nornir_worker\netconf_task.py
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
@Task(
    fastapi={"methods": ["POST"]},
    input=NetconfCancelCommitInput,
    output=NetconfResult,
    mcp={
        "annotations": {
            "title": "NETCONF Cancel Commit",
            "readOnlyHint": False,
            "destructiveHint": True,
            "idempotentHint": False,
            "openWorldHint": True,
        }
    },
)
def netconf_cancel_commit(
    self,
    job: Job,
    plugin: str = "ncclient",
    persist_id: str = None,
    **kwargs: Any,
) -> Result:
    """Cancel a pending confirmed commit and request immediate rollback.

    Args:
        job: NorFab job metadata.
        plugin: NETCONF backend: ncclient (default) or scrapli.
        persist_id: Token supplied as persist when starting a persistent
            confirmed commit. Omit for a nonpersistent commit, which must
            be cancelled through its original NETCONF session.
        **kwargs: Common host filters, processors, retries, XML processors
            (xmltodict, xpath, xml_flake), to_dict and add_details options.

    Returns:
        Result: XML replies under cancel_commit for ncclient or rpc for
            Scrapli, normally an ok reply on success, or serialized records
            when to_dict=False. Requires device support for cancel-commit
            and a pending confirmed commit. RPC, capability and connection
            errors mark hosts failed; unmatched hosts return status no_match.
            Does not undo a normal or already confirmed commit. Target the
            original worker and backend for nonpersistent commits. Retries
            may report failure after an earlier cancellation succeeded.
    """
    if plugin == "scrapli":
        rpc = Element(
            "cancel-commit", xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
        )
        if persist_id is not None:
            SubElement(rpc, "persist-id").text = persist_id
        return self._run_netconf(
            job,
            call="rpc",
            plugin=plugin,
            filter_=tostring(rpc, encoding="unicode"),
            **kwargs,
        )
    return self._run_netconf(
        job, call="cancel_commit", plugin=plugin, persist_id=persist_id, **kwargs
    )