Fetching Running Configurations using NETCONF (2)
Fetching Running Configurations using NETCONF (2)
In this lab, we will explore how to use the ncclient library to establish an SSH connection to a network device and
fetch the running configurations from a router. The ncclient library allows us to interact with network devices using
NETCONF protocol, which is a standardized protocol for managing network devices.
- Go to your eve-ng and add a Cisco CSR 1000V Routers and connect to Cloud1 to establish connectivity between
PC and router, make sure you modify the resources like shown below.
- Boot the router and provide IP to the management interface using DHCP.
enable
configure terminal
interface gig 1
ip address dhcp
no shutdown
exit
ip domain-name abc.com
cryptokey generate rsa general-keys modulus 1024
ip ssh ver 2
username admin privilege 15 password cisco
line vty 0 4
login local
transport input all
exit
netconf ssh
netconf-yang
- Verify the reachability by pinging the IP address of router from local device.
- Go to the terminal of your device using VS code or using cmd and run the following command to begin the
installation of the library ncclient:
- Import the library into your code. Getpass is used to collect the information in hidden manner. parseString from
xml.dom.minidom is used to convert the deserialized output of data in serialized manner.
- Call the manager.connect module to connect with the router. (** before the dictionary name is used to tell the
python to consider the content of the dictionary as key-value pairs instead of single elements.)
- Following statements will fetch out the running configurations from the device and will print the output. You will
observe that the output will be printed out in deserialized manner.
- Now let’s try to convert this into serialized form by using the module parseString.
- Let’s also understand how we can write this data into a text file. We will create a text file and will open it in the
script using the path of that file like shown below. Write module helps in writing data inside the file.