Skip to content

Question: yang-diff vs. netconf diff. #2475

@hyberdk

Description

@hyberdk

First of all, thank you for awesome software.. Amazing..

Im using libyang 4.4.2 and the latest libyang-python wrapper to parse my configuration of my Cisco routers and switches. I can also generate my intent, and then I can diff the two with libyang

I have two DNodes base (intent) and running (actual), I diff them like this:

base = running.diff(base)
print_yang(out_fmt=format, data=base)

    def print_yang(
        self,
        data: str | dict,
        out_fmt: DataFormat = DataFormat.JSON,
        with_siblings: bool = True,
        pretty: bool = True,
        keep_empty_containers: bool = False,
    ) -> str:
        """Prints the YANG data in the specified format.

        Args:
            data (str | dict): The YANG data to print.
            out_fmt (DataFormat, optional): The output format. Defaults to DataFormat.JSON.
            with_siblings (bool, optional): Whether to include sibling in containers. Defaults to True.
            pretty (bool, optional): Whether to pretty-print the output. Defaults to True.
            keep_empty_containers (bool, optional): Whether to keep empty containers in the output. Defaults to False.

        Returns:
            str: The printed YANG data as string.
        """
        tree = self.parse(data)

        return tree.print_mem(str(out_fmt).lower(), with_siblings=with_siblings, pretty=pretty, keep_empty_containers=keep_empty_containers)

The print gives an output like this:

<nacm xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-acm" xmlns:yang="urn:ietf:params:xml:ns:yang:1" yang:operation="none">
  <write-default yang:operation="replace" yang:orig-default="false" yang:orig-value="permit">deny</write-default>
  <rule-list yang:operation="none">
    <name>readonly</name>
    <group yang:operation="delete">PRIV06</group>
    <group yang:operation="create">PRIV05</group>
    <rule yang:operation="none">
      <name>deny-cisco-rpc</name>
      <action yang:operation="replace" yang:orig-default="false" yang:orig-value="permit">deny</action>
    </rule>
  </rule-list>
</nacm>

Anyways, I know this is the c-version of libyang, but it was just for context..

my questions is as follows: I really really would like to make my diff a "netconf" compliant xml, so I can send that to my router or switch.. Since the yang:operation="none" yang:orig-default="false" yang:orig-value="permit" etc is not really "allowed" netconf commands, I would like to convert it to something I can actually send to my equipment..

I cannot find a way to do, this.. Am I just shit out of luck or what would you guys do in my situation? can it be solved within libyang?

Any help is appreciated, and ohh yeah.. awesome work guys (did I say that?)

Esben

Metadata

Metadata

Assignees

No one assigned

    Labels

    is:questionIssue is actually a question.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions