Skip to content

downloading models include rpc-reply #78

@hyberdk

Description

@hyberdk

Im trying out your module, Im fairly new to nornir, but resonable skilled in python.

I have a task that download all models/modules from my cisco router/switches.

it looks something like this:

def get_yang_schemas(task: Task) -> Result:
    rpc_filter = '<modules-state xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-library"/>'

    result = task.run(
        task=netconf_get,
        filter_type="subtree",
        path=rpc_filter
    )

    xml = result[0].result.rpc.xml

    data_dict = xmltodict.parse(xml)

    schemas_to_fetch = []
    for module in data_dict["rpc-reply"]["data"]["modules-state"]["module"]:
        schemas_to_fetch.append(module["name"])

    dir_name = f"{task.host.name}_yang"
    os.makedirs(dir_name, exist_ok=True)

    schemas_result = task.run(netconf_get_schemas, schemas=schemas_to_fetch, schema_path=dir_name)
    return schemas_result

my question is, why does the yang-models include the rpc-reply in the file? should it not unwrap it or am I missing something? I mean, if it where to return the result, sure, but when its writing it to file, is it not used to download the models?

here is an example:

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:a05acb3d-68d8-4538-b506-f58fd45f2ff7" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><data xmlns='urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring'><![CDATA[module cisco-ethernet {
  yang-version 1;
  namespace "urn:cisco:params:xml:ns:yang:cisco-ethernet";
  prefix eth;

  import ietf-interfaces {
    prefix if;
  }
  import iana-if-type {
    prefix ianaift;
  }

  organization
    "Cisco Systems, Inc.";
  contact
    " Cisco Systems, Inc.
     Customer Service

     Postal: 170 W Tasman Drive
     San Jose, CA 95134

     Tel: +1 1800 553-NETS

     E-mail: cs-yang@cisco.com";
  description
    "This module contains a collection of YANG definitions for
     configuring Ethernet Interfaces.
     Copyright (c) 2016 by Cisco Systems, Inc.
     All rights reserved.";
  reference
    "TODO";

  revision 2016-05-10 {
    description
      "Added iana-if-type import";
  }
  revision 2016-03-30 {
    description
      "Update description with copyright notice.";
  }
  revision 2014-05-12 {
    description
      "Proposed";
  }

  identity eth-if-speed {
    description
      "Representing the speed of the ethernet interface";
  }

  identity eth-if-speed-10mb {
    base eth-if-speed;
  }

  identity eth-if-speed-100mb {
    base eth-if-speed;
  }

  identity eth-if-speed-1gb {
    base eth-if-speed;
  }

  identity eth-if-speed-10gb {
    base eth-if-speed;
  }

  identity eth-if-speed-40gb {
    base eth-if-speed;
  }

  identity eth-if-speed-100gb {
    base eth-if-speed;
  }

  augment "/if:interfaces/if:interface" {
    when "if:type = 'ianaift:ethernetCsmacd'";
    container ethernet {
      container transmission-params {
        choice transmission-mode {
          case auto1 {
            leaf auto-negotiate {
              type empty;
            }
          }
          case manual {
            leaf duplex {
              type enumeration {
                enum half;
                enum full;
              }
            }
            leaf speed {
              type identityref {
                base eth-if-speed;
              }
            }
          }
        }
      }
      leaf mtu-size {
        type uint16;
      }
    }
  }

  augment "/if:interfaces-state/if:interface" {
    when "if:type = 'ianaift:ethernetCsmacd'";
    container ethernet {
      leaf duplex {
        type enumeration {
          enum half;
          enum full;
          enum disagree;
        }
      }
      container supported-mtu-range {
        leaf min-mtu-size {
          type uint16;
        }
        leaf max-mtu-size {
          type uint16;
        }
      }
    }
  }
}
]]></data>
</rpc-reply>

my env looks like this:

(venv) eslau@eslau-mac libyang_test % pip list
Package            Version
------------------ --------
bcrypt             4.3.0
certifi            2025.8.3
cffi               2.0.0
charset-normalizer 3.4.3
colorama           0.4.6
cryptography       46.0.1
flake8             7.3.0
Flake8-pyproject   1.2.3
idna               3.10
invoke             2.2.0
libyang            3.1.0
lxml               6.0.2
mccabe             0.7.0
ncclient           0.7.0
nornir             3.5.0
nornir-netbox      0.3.0
nornir_netconf     2.1.0
nornir-utils       0.2.0
paramiko           4.0.0
pip                25.1.1
pycodestyle        2.14.0
pycparser          2.23
pyflakes           3.4.0
PyNaCl             1.6.0
requests           2.32.5
ruamel.yaml        0.18.15
ruamel.yaml.clib   0.2.14
setuptools         80.9.0
urllib3            2.5.0
xmltodict          1.0.2
(venv) eslau@eslau-mac libyang_test % python3 --version
Python 3.11.13

Thanks for a nice project, by the way ;-)

--
Esben

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions