NETCONF



Install



pip install ncclient


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

YANG Model Data with NETCONF and NCClient



• Full NETCONF Manager (i.e. client) implementation in Python
◇ see later section on NETCONF
• Handle all details including authentication, RPC and operations
• Deals in raw XML

#! /usr/bin/env python
"""
api_ncclient_example.py
Illustrate the following concepts:
- Making NETCONF calls using ncclient library
- Intended to be entered into an interactive
  interpreter
"""


from ncclient import manager
from pprint import pprint
import xmltodict

router = {"ip""10.10.20.48",
          "port"830,                  # NETCONF port no.
          "user""cisco",
          "pass""cisco_1234!"}

netconf_filter = """
<filter>
  <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
    <interface>
      <name>GigabitEthernet1</name>
    </interface>
  </interfaces>
</filter>
"""


m = manager.connect(host=router["ip"],
                    port=router["port"],
                    username=router["user"],
                    password=router["pass"],
                    hostkey_verify=False)

interface_netconf = m.get_config("running", netconf_filter)

interface_python = xmltodict.parse(interface_netconf.xml)["rpc-reply"]["data"]

pprint(interface_python["interfaces"]["interface"]["name"]["#text"])


Index