Network Automation Using Python
Network Automation Using Python
Vinit Jain
CCIE# 22854
Twitter - @vinugenie
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 2
Win a free
signed copy!
2 Free copies
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 3
Meet the Author
Configuration
Visibility & Telemetry
Management
Network Infrastructure
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 7
Network Programmability
• It’s a set of tools to deploy, manage and troubleshoot a network
device
• Network engineer perspective – interacting with a device or group of
devices
• Software developer perspective – abstracting the network. Seeing
the whole network as a single device and manipulating it with
software
Infrastructure
Applications API
(Routers,
(Python) (JSON / XML)
Switches..)
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 8
Benefits of Network Programmability
• Reduced OPEX
• Customization
• Reduced human error
• Operational flexibility
• Increased opportunity for innovation
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 9
Application Programming Interface (API)
• APIs are mechanisms used to Application
communicate with applications and
other software. Northbound API
GET Read
POST Create
PATCH Update / Modify
PUT Update / Replace
DELETE Delete
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 11
HTTP Status Codes
HTTP STATUS RESULT COMMON REASON
CODE
200 Ok Using GET or POST to exchange data with
an API
201 Created Creating resources by using a REST API call
400 Bad Request Request failed due to client-side issue
401 Unauthorized Client not authenticated to access site or
API call
403 Forbidden Access not granted based on supplied
credentials
404 Not Found Page at HTTP URL location does not exist
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Confidential
or is hidden 12
Netmiko
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 13
Netmiko Overview
• Netmiko – Python library used extensively to interact with network
devices
• Multi-vendor library
• Cisco IOS/IOS-XE, NX-OS, firewalls, etc.
• Extended support of Paramiko library’s SSH functionality
• Going into configuration modes
• Sending commands
• Retrieving outputs
• Taking care of yes/no prompts
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 14
NAPALM
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 15
NAPALM Overview
• NAPALM - Network automation and programmability abstraction
layer with multi-vendor support
• Provides functions that allows:
• Configuration operations (commit or rollback)
• Retrieve state data from network devices
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 16
NAPALM Operations
• Replace – Allows users to replace the existing running configuration with an
entirely new configuration.
• Merge – Allows users to merge configuration changes from a file to the
running configuration on the device.
• Compare – Compare the newly proposed configuration with the existing
one. Only applies to replace operation and not for merge operation.
• Discard – Resets the merge configuration file to an empty file. Thus, not
allowing the new configuration to be applied on the device.
• Commit – Commits the proposed configuration to the network device. In
other words, used to deploy a staged configuration.
• Rollback – Rollback (revert back) the running configuration to the saved
configured prior to the last commit.
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 17
Jinja
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 18
Templating with Jinja2
• Jinja is a modern templating language for Python – Modelled after
Django templates
• Allows user to easily interact with Python program
• Use data to quickly generate dynamic content
• Benefits:
• Template inheritance
• Optimal just-in-time compilation
• Easy debuggability
• Configurable syntax
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 20
Nornir
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 21
Nornir Overview
• Python based automation framework
• Manage network and host inventory and provide common
framework to write plugins for the network devices and hosts
• Requires minimum Python version 3.6.2
• Multi-threaded – Defaults to 20 worker threads
• Initialized using config file – references couple other files
• Host inventory file
• Group file
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 23
Submit Your
Questions Now!
Cisco Press
Network Programmability and Automation Fundamentals [Learn more]
News
CCNP and CCIE Security Core SCOR 350-701 Official Cert Guide
https://www.ciscopress.com/store/ccnp-and-ccie-security-core-scor-350-701-official-cert-9780135971970
Vinit’s publications
http://www.ciscopress.com/authors/bio/255ee209-1418-4938-9a42-d3bece2b46c6
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 25
Congratulations
winners!
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 27
Thanks For Joining today!
© 2020 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 28