Email: evarainbow@evarainbow.com

Capabilities in the Guest Shell – Cisco Automation and Scripting Tools

The Guest Shell is populated with CentOS 7 Linux, which provides the ability to YUM install software packages built for this distribution. The Guest Shell is prepopulated with many of the common tools that would naturally be expected on a networking device, including net-tools, iproute, tcpdump, and OpenSSH. Python 2.7.5 is included by default, as is the PIP for installing additional Python packages.

The Guest Shell has access to the Linux network interfaces used to represent the management and data ports of the switch. Typical Linux methods and utilities like ifconfig and ethtool can be used to collect counters, as shown in Example 16-7. When an interface is placed into a Virtual Routing and Forwarding (VRF) in the NX-OS CLI, the Linux network interface is placed into a network namespace for that VRF. You can see the name spaces at /var/run/netns and can use the ip netns utility to run in the context of different namespaces. A couple of utilities, chvrf and vrfinfo, are provided as a convenience for running in a different namespace and getting information about which namespace or VRF a process is running in.

Example 16-7 Displaying Counters for Ethernet 1/47 Interface Inside Guest Shell

switch# guestshell
[guestshell@guestshell ~]$ ifconfig Eth1-47
Eth1-47: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 13.0.0.47 netmask 255.255.255.0 broadcast 13.0.0.255
ether 54:7f:ee:8e:27:bc txqueuelen 100 (Ethernet)
RX packets 311442 bytes 21703008 (20.6 MiB)
RX errors 0 dropped 185 overruns 0 frame 0
TX packets 12967 bytes 3023575 (2.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

The Guest Shell provides an application to allow the user to issue NX-OS commands from the Guest Shell environment to the host network element. The dohost application accepts any valid NX-OS configuration or exec commands and issues them to the host network element.

When you are invoking the dohost command, each NX-OS command may be in single or double quotes:

dohost “<NXOS CLI>”

Example 16-8 shows how to use the dohost command.

Example 16-8 Using the dohost Command

[guestshell@guestshell ~]$ dohost “sh lldp time | in Hold” “show cdp global”
Holdtime in seconds: 120
Global CDP information:
CDP enabled globally
Refresh time is 21 seconds
Hold time is 180 seconds
CDPv2 advertisements is enabled
DeviceID TLV in System-Name(Default) Format
[guestshell@guestshell ~]$

Python can be used interactively, or Python scripts can be run in the Guest Shell, as shown in Example 16-9.

Example 16-9 Running Python Inside the Guest Shell

guestshell:~$ python
Python 2.7.5 (default, Jun 24 2019, 00:41:19)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>>
guestshell:~$

The Pip Python Package Manager is included in the Guest Shell to allow the network-admin to install new Python packages, as shown in Example 16-10.

Example 16-10 Using Pip Python Package Manager to Install a Python Package

[guestshell@guestshell ~]$ sudo su
[root@guestshell guestshell]# pip install Markdown
Collecting Markdown
Downloading Markdown-2.6.2-py2.py3-none-any.whl (157kB)
100% |################################| 159kB 1.8MB/s
Installing collected packages: Markdown
Successfully installed Markdown-2.6.2
[root@guestshell guestshell]# pip list | grep Markdown
Markdown (2.6.2)
[root@guestshell guestshell]#

To preserve the integrity of the files within the Guest Shell, the file systems of the Guest Shell are not accessible from the NX-OS CLI. For the host, bootflash: and volatile: are mounted as /bootflash and /volatile within the Guest Shell. A network-admin can access files on this media using the NX-OS exec commands from the host or using Linux commands from within the Guest Shell.

Leave a Reply

Your email address will not be published. Required fields are marked *