Tacent 2005
Tacent 2005
#CiscoLive
Cisco Webex App
Questions?
Use Cisco Webex App to chat
with the speaker after the session
How
1 Find this session in the Cisco Live Mobile App
3 Install the Webex App or go directly to the Webex space Enter your personal notes here
#CiscoLive TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 3
• Introduction
• Guestshell Overview
• Why Guestshell?
• Interacting with Python
Agenda • Conclusion & Additional
Resources
TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 4
Guestshell Overview
• Guestshell is a lightweight
linux container based off the
CentOS distribution
• Available on all IOS-XE
based routing & switching
platforms
• Based off Cisco’s
application hosting
framework (IOx)
#CiscoLive TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 5
Guestshell Considerations
#CiscoLive TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 6
Guestshell and EEM Applications
IOS
IOS-XE
Guestshell
Email Syslog
IOS-XE
IOS
SNMP
ARP Embedded BGP
Process Event Router
Manager Process
#CiscoLive TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 7
Guestshell Setup interface VirtualPortGroup0
vrf forwarding GS
Internet: 8.8.8.8
ip address 192.168.35.101 255.255.255.0
ip nat inside
interface GigabitEthernet1
ip address 172.31.12.136 255.255.240.0
ip nat outside
iox
Eth0: 192.168.35.102
app-hosting appid guestshell
app-vnic gateway1 virtualportgroup 0 guest-interface 0
guest-ipaddress 192.168.35.102 netmask 255.255.255.0
app-default-gateway 192.168.35.101 guest-interface 0
name-server0 8.8.8.8
#CiscoLive TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 8
Customizing
cat8kv2#show app-hosting detail
App id : guestshell
Guestshell
Owner : iox
State : RUNNING
Application
Type : lxc
Name : GuestShell
• Operational state of the Version
Description
:
:
3.3.0
Cisco Systems Guest Shell XE for x86_64
container is viewed with Author
Path
:
:
Cisco Systems
/guestshell/:guestshell.tar
show app-hosting detail URL Path :
Activated profile name : custom
Port forwarding
Table-entry Service Source-port Destination-port
---------------------------------------------------
table1 tcp 888 8888
#CiscoLive TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 9
Calling Guestshell
cat8kv1#guestshell enable Guestshell is created
Interface will be selected if configured in app-hosting
Please wait for completion and started with
guestshell installed successfully
guestshell enable and
Current state is: DEPLOYED
guestshell activated successfully made operational
Current state is: ACTIVATED
guestshell started successfully
Current state is: RUNNING
Guestshell enabled successfully
cat8kv1#guestshell
[guestshell@guestshell ~]$
Access to guestshell is
made with command
guestshell
#CiscoLive TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 10
Inside Guestshell [guestshell@guestshell ~]$ whoami
guestshell
#CiscoLive TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 11
Host and Guestshell Interaction
Commands can be executed between host device or within guestshell
[guestshell@guestshell ~]$ dohost 'show version | i Cisco IOS XE'
Cisco IOS XE Software, Version 17.06.05
[guestshell@guestshell ~]$
cat8kv1#dir bootflash:/guest-share
Directory of bootflash:/guest-share/
#CiscoLive TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 12
Incorporating
Python
Using Python within Guestshell
list of available modules:
>>> help('modules')
[guestshell@guestshell ~]$ ls /bin | grep python Please wait a moment while I gather a list of all available
python3 modules...
python3.6
python3.6m
_compression cli logging six
unversioned-python
_pydecimal eem pathlib this
_hashlib crypt ncclient string
_osx_support dohost paramiko termios
_io csv nntplib subprocess
[guestshell@guestshell ~]$ python3
<snip>
Python 3.6.8 (default, Dec 22 2020, 19:04:08)
[GCC 8.4.1 20200928 (Red Hat 8.4.1-1)] on linux
Type "help", "copyright", "credits" or "license" for >>> import subprocess
more information. >>> help(subprocess)
>>> Help on module subprocess:
NAME
subprocess - Subprocesses with accessible I/O streams
#CiscoLive TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 14
Importing Python
Libraries [guestshell@guestshell ~]$ ls /bin | grep pip
pip-3
pip-3.6
pip3
TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 15
Setting up Configuration Tasks
>>> import cli
>>> cli.configure("hostname test-config-change")
'Line 1 SUCCESS: hostname test-config-change\n’
>>> cmdlist = []
>>> for x in range(1,4):
... cmdlist.append(f'interface loopback{x}, ip address 1.1.1.{x}
255.255.255.255')
...
>>> for x in cmdlist:
... cli.configurep(x.split(','))
#CiscoLive TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 16
Polling Operational State with a Show Command
>>> cli.execute('show ip int brief’) # Returns a string
'Interface IP-Address OK? Method Status
Protocol\nGigabitEthernet1
up \nLoopback0
172.31.12.136
unassigned
YES DHCP
YES unset
up
up
Prints the
up \nLoopback1 1.1.1.1 YES manual up results with
up \nLoopback2 1.1.1.2 YES other up
up \nLoopback3 1.1.1.3 YES other up cli.executep()
up \nVirtualPortGroup0 192.168.35.101 YES TFTP up
up \n’
#CiscoLive TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 17
Setting up a Reactive Task
cat8kv1#show run | section event
event manager applet high-memory-usage authorization bypass
event syslog pattern "%PLATFORM-3-ELEMENT_CRITICAL"
action 1.0 cli command "enable"
action 1.1 syslog msg "This is coming from EEM"
action 1.2 cli command "guestshell run python3 eem-call-example.py"
action 1.3 cli command "exit"
#CiscoLive © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 18
Using SMTP via Amazon’s SES
#CiscoLive TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 19
Using SMTP via Amazon’s SES
Verifying an Identity
Allows for emails to be sent to the user
#CiscoLive TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 20
Using SMTP via Amazon’s SES
#CiscoLive TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 21
Using TAC support APIs - CXD
#CiscoLive TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 23
Additional Resources
DevNet Guestshell Quick Start Guide
#CiscoLive TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 24
Thank you
#CiscoLive
Fill out your session surveys!
These points help you get on the leaderboard and increase your chances of winning daily and grand prizes
#CiscoLive TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 26
• Visit the Cisco Showcase
for related demos
TACENT-2005 © 2023 Cisco and/or its affiliates. All rights reserved. Cisco Public 27
#CiscoLive