2.2 Lab - CLI Automation With Python Using Netmiko
2.2 Lab - CLI Automation With Python Using Netmiko
2.2 Lab - CLI Automation With Python Using Netmiko
Objectives
Part 1: Install the netmiko Python module
Part 2: Connect to IOS XE’s SSH service using netmiko
Part 3: Use netmiko to gather information from the device
Part 4: Use netmiko to alter configuration on the device
Background / Scenario
For simple network automation using a remote telnet or ssh based command line, network administrators
have been using various screen scraping techniques for a long period of time. Initially the “expect” based
scripts we utilized to automate entering commands when a specific expected string appeared on the
command line. With the evolution of the Python language, the netmiko Python module has emerged as an
open source project hosted and maintained on GitHub.com that provides a simple network automation
interface using similar techniques like the “expect” based scripts.
In this lab activity, you will identify the potential but also the limitations of using netmiko to transport CLI
commands for network automation.
Required Resources
• Access to a router with the IOS XE operating system version 16.6 or higher.
• Access to the Internet
• Python 3.x environment
Instructions
© 2017 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 1 of 4 www.netacad.com
Lab – CLI Automation with Python using netmiko
b. In the new Python script file editor, import the “ConnectHandler()” function from the netmiko module:
c. Setup a sshCli connection object using the ConnectHandler() function to the IOS XE device.
© 2017 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 2 of 4 www.netacad.com
Lab – CLI Automation with Python using netmiko
If you have not saved the script file yet, you will be prompted to save it before it is executed.
c. Verify the results:
Quesion
d. Verify the data type of the “output” variable. How would you extract the IP address and the Interface
Name into variables? What if there were multiple interfaces?
output = sshCli.send_config_set(config_commands)
Why does the output from “show ip int brief” not include the “loopback1” interface?
How to execute and display the output from the “show ip int brief” command after the loopback interfaces was
created?
© 2017 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 3 of 4 www.netacad.com
Lab – CLI Automation with Python using netmiko
Add code to create a new loopback interface (loopback2) with the same IP address as on the existing loopback
interface, only with a different description.
Execute the Python script file and verify the results.
Questions
End of Document
© 2017 - 2020 Cisco and/or its affiliates. All rights reserved. Cisco Public Page 4 of 4 www.netacad.com