Professional Documents
Culture Documents
Use NETCONF Python Ncclient To Retrieve The Configuration of IOS
Use NETCONF Python Ncclient To Retrieve The Configuration of IOS
PNETLAB Store
PNETLab.com
Lab Topology:
I. Requirement
II. Prerequisite
1
Download PNETLab Platform
PNETLAB Store
PNETLab.com
When you guys load the lab to your PNETlab, it will get all things of this lab except
Ubuntu_server docker. Therefore, you should install by yourself an Ubuntu_server docker and
connect to R2. Now I will show you how to do.
Step 1. Go to Device item of PNETlab site to get Ubuntu_server docker
Step 2. Read the guide to know how to do, or follow my method below.
Step 2.1 After you get Device, then go back to running lab on PNETlab box. Click “Add an
Object” , then Add new Node, then you choose the docker.io. After choosing that box, please
input information follow this picture
2
Download PNETLab Platform
PNETLAB Store
PNETLab.com
Step 2.2 Then you go to Start up configure section. Insert one command line: dhclient eth1
Then save it, enable it. Follow the picture blow.
3
Download PNETLab Platform
PNETLAB Store
PNETLab.com
Step 2.3 Now you have Ubunto_server docker, it is time to connect it to Cloud_NAT
All things related to Ubuntu_server docker are okay. Just click to that device and telnet . Then
just enjoy your Ubuntu in PNETlab now.
4
Download PNETLab Platform
PNETLAB Store
PNETLab.com
Step 3. Check python version. Make sure it has suitable version. Version 3 is new version of
Python. // Click and telnet to your Ubunto , sodu -i with pass : admin to go to admin level.
admin@Ubuntu_server:~$ python3
Python 3.8.2 (default, Jul 16 2020, 14:00:26)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
Step 5. Create a Directory for Python that it is easy to control python files
mkdir python_on_PNETlab
cd python_on_PNETlab
python3 -m venv env
If problem happen here please use this command again: sudo apt-get install python3-venv
Then execute command again, make sure it is okay now : python3 -m venv env
5
Download PNETLab Platform
PNETLAB Store
PNETLab.com
Step 7 Configure initial cfg and ssh info, account for IOS XE
enable
configure terminal
hostname IOS_XE
no ip domain lookup
line vty 0 15
6
Download PNETLab Platform
PNETLAB Store
PNETLab.com
exec-t 0 0
logg sync
login local
transport input ssh
ip domain name example.pnetlab.com
crypto key generate rsa modulus 2048
username cisco priv 15 password cisco
netmiko 2.4.2
paramiko 2.6.0
pip 20.0.2
PyGObject 3.36.0
PyNaCl 1.3.0
pyserial 3.4
requests 2.22.0
scp 0.13.0
setuptools 45.2.0
six 1.14.0
ssh-import-id 5.10
textfsm 1.1.0
urllib3 1.25.8
wheel 0.34.2
root@Ubuntu_server:~/python_on_PNETlab#
Don’t have ncclient module yet so you we should install it . We use the
common command: pip3 install ncclient
root@Ubuntu_server:~/python_on_PNETlab# pip3 list --
format=columns
Package Version
------------- ----------
bcrypt 3.1.7
ncclient 0.6.9
8
Download PNETLab Platform
PNETLAB Store
PNETLab.com
9
Download PNETLab Platform
PNETLAB Store
PNETLab.com
#You can use the get_config() method of the m NETCONF session object
to retrieve the configuration for IOS_XE.
#The get_config() method expects a source string parameter that
specifies the source NETCONF datastore. Use a print function to display
the results.
#The only NETCONF datastore currently on IOS_XE is the running
datastore. You can verify this with the show netconf-yang datastores
command.
#If you want to skip displaying the output from Part 3, comment out
the block of statements that print the capabilities, as shown in the
following:
netconf_reply = m.get_config(source="running")
print(xml.dom.minidom.parseString(netconf_reply.xml).toprettyxml())
10
Download PNETLab Platform
PNETLAB Store
PNETLab.com
netconf_filter = """
<filter>
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native" />
</filter>
"""
netconf_reply = m.get_config(source="running", filter=netconf_filter)
print(xml.dom.minidom.parseString(netconf_reply.xml).toprettyxml())
11
Download PNETLab Platform
PNETLAB Store
PNETLab.com
netconf_hostname = """
<config>
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<hostname>IOS_XE_NEW</hostname>
</native>
</config>
"""
netconf_reply = m.edit_config(target="running",
config=netconf_hostname)
print(xml.dom.minidom.parseString(netconf_reply.xml).toprettyxml())
netconf_loopack = """
<config>
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<interface>
<Loopback>
<name>100</name>
<description>Loopback 100</description>
<ip>
12
Download PNETLab Platform
PNETLAB Store
PNETLab.com
<address>
<primary>
<address>100.1.1.1</address>
<mask>255.255.255.255</mask>
</primary>
</address>
</ip>
</Loopback>
</interface>
</native>
</config>
"""
netconf_reply = m.edit_config(target="running",
config=netconf_loopack)
print(xml.dom.minidom.parseString(netconf_reply.xml).toprettyxml())
#the end of code, enjoy your lab.
13