Dive into Leveraging
Python on IOS-XE
Adrian Iliesiu – Corporate Technology Engineer
DEVNET-2556
DEVNET-2556
Guest Shell
Guest Shell Application
Linux Shell Environment On Your Switch or Router
• Maintain IOS-XE system integrity
• Isolated User Space
• Fault Isolation
• Resource Isolation
Linux
• On-box rapid prototyping applications
• Device-level API Integration
• Scripting (Python) Guest Shell
• Linux Commands
• Application Hosting Open Application Container
API
• Integrate into your Linux workflow
Network OS
• Integrated with IOS-XE
DEVNET-2556 © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 4
Preparing the Vagrant Image
Initial Setup of Local Image for Lab
1. From csr1kv# prompt:
1. guestshell run bash
2. sudo yum install -y git
3. git clone [Link]
4. ./DevNet2556/[Link]
2. Exit Guest Shell
1. exit
2. copy bootflash:[Link] running-config
3. write mem
DEVNET-2556 © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 5
Guest Shell Overview
Guest Shell is a decoupled execution space running within a Linux Container
(LXC)
From within the Guest Shell the network-admin has the following capabilities:
• Access to the network over Linux network interfaces
• Access to bootflash
• Access to IOS CLI
• The ability to install and run python scripts.
• The ability to install and run 32-bit and 64-bit Linux applications.
DEVNET-2556 © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 6
DEVNET-2556
Python on Guest Shell
Why Python on IOS-XE?
• Python is the de-facto automation
language of the day
• Easy to learn but powerful programming
language
• Helps overcome operational
shortcomings of CLI
• Provides programmatic access to
device’s configuration
[Link]
DEVNET-2556 © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 8
Cisco’s Python Enhancements
IOS-XE 16.5 operating system enables the Python API
• Interactive python prompt
• Running python script
• Zero Touch Provisioning (ZTP)
• Embedded Event Manager (EEM)
DEVNET-2556 © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 9
Let’s Get Started
Open a Browser and go to:
[Link]
Then, click on “Modules” link
DEVNET-2556 © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 10
Module 6 – NETCONF & YANG
What is NETCONF?
• “NETCONF is a protocol defined by the IETF to “install, manipulate, and delete
the configuration of network devices”. NETCONF operations are realised on top
of a Remote Procedure Call (RPC) layer using an XML encoding and provides a
basic set of operations to edit and query configuration on a network device”
• [Link]
• NETCONF RFCs
• [Link] (NETCONF RFC)
• [Link] (NETCONF over SSH)
• [Link] (NETCONF notifications)
DEVNET-2556 © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 12
What is YANG?
• ”YANG is a data modeling language used to model configuration and state
data manipulated by the NETCONF protocol.”
• [Link]
• RFC 6020 - [Link]
DEVNET-2556 © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 13
Q. Why Do We Even Need a Modeling Framework?
We’ve all seen this one, right?
DEVNET-2556 © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 15
A. Simplicity and Automation
• Without a modeling framework, every device and device type must be
configured using a different set of rules.
• How would an automation tool program different device types?
• How would an automation tool determine the structure of data for various device
types?
DEVNET-2556 © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 16
Taking a Look at a YANG Model
DEVNET-2556 © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 17
Elements of Using
NETCONF
Device login info
Opening a
NETCONF session
YANG model info
NETCONF request:
“get_config”
DEVNET-2556 © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 18
Module 7 – A Deeper Look at
NETCONF
Elements of Using
NETCONF
Define class object
two variables returned per object:
name & description
Definition to extract
data from parsed
YANG info
Iterate through GE
interfaces
Iterate through
Loopback interfaces
DEVNET-2556 © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 20
Module 8 – Bringing it All Together
On-Box Python Use Case
• Device has standard QoS policy for egress shaping
• Multiple egress links provide application routing
• If a WAN link fails, want to resize QoS policy since overall bw is reduced
DEVNET-2556 © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 22
On-Box Python Use Case
• Use EEM to monitor for Syslog Message about failed link
• Python running on Guest Shell will execute the Python script
• NETCONF will validate the link being modified is a “WAN” link and is operational
• Python API will execute CLI change to modify the QoS policy on the remaining
“WAN” link
DEVNET-2556 © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 23
Elements of Python
Use Case
Define class object
three variables returned per object:
name, description & state
Open a NETCONF
session and return config
Definition to extract
data from parsed
YANG info and return
data
DEVNET-2556 © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 24
Elements of Python
Use Case (cont.)
Iterate through all
interfaces and return
object data
Match the correct
interface and adjust the
QoS setting
DEVNET-2556 © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 25
Q&A
Complete Your Online
Session Evaluation
• Give us your feedback and
receive a Cisco Live 2018 Cap
by completing the overall event
evaluation and 5 session
evaluations.
• All evaluations can be completed
via the Cisco Live Mobile App.
Don’t forget: Cisco Live sessions will be
available for viewing on demand after the
event at [Link]/Global.
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Thank you