-
Notifications
You must be signed in to change notification settings - Fork 450
/
api_ncclient_example.py
42 lines (36 loc) · 1.12 KB
/
api_ncclient_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#! /usr/bin/env python
"""
Learning Series: Network Programmability Basics
Module: Programming Fundamentals
Lesson: Python Part 3
Author: Hank Preston <hapresto@cisco.com>
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,
"user": "developer",
"pass": "C1sco12345"}
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"])