cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
282
Views
5
Helpful
5
Replies

Running python in guestshell on 9300

rasmus.elmholt
Level 7
Level 7

Hi all,

I am trying to figure out how to use the guestshell to run a python script as shown in this link: https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/prog/configuration/1712/b_1712_programmability_cg/m_1712_prog_eem_python.html

I am running on a 9300L on version 17.12.5 and trying to follow the programmability guide.

But I cannot get it to run the python script as it seems like python is not installed in the guestshell.

eem_script.py:

import sys
from cli import cli,clip,execute,executep,configure,configurep

intf= sys.argv[1:]
intf = ''.join(intf[0])


print ('This script is going to unshut interface %s and then print show ip interface brief'%intf)

if intf == 'loopback55': 
configurep(["interface loopback55","no shutdown","end"])
else :
cmd='int %s,no shut ,end' % intf
configurep(cmd.split(','))

executep('show ip interface brief')

Running it on the CLI:

TST-SW#guestshell run python /flash/eem_script.py loop55
env: 'python': No such file or directory

TST-SW#

Does anyone know why this is not working?

 

1 Accepted Solution

Accepted Solutions

@rasmus.elmholt the error you get would indicate the python executable not being in the shell's path. You can try run 

guestshell run python3 /flash/eem_script.py loop55

You can run

! Validate the Python version.
[guestshell@guestshell ~]$ python3 --version
Python 3.6.8

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

View solution in original post

5 Replies 5

@rasmus.elmholt the error you get would indicate the python executable not being in the shell's path. You can try run 

guestshell run python3 /flash/eem_script.py loop55

You can run

! Validate the Python version.
[guestshell@guestshell ~]$ python3 --version
Python 3.6.8

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

@bigevilbeard it worked when I used python3 but is there any way to reference the flash directory from the guestshell?

Shouldn't the documentation reflect that python3 is used and that there are no alias for python?

TST-SW#dir flash:eem_script.py
Directory of flash:/eem_script.py

655394  -rw-              420  Jun 11 2025 14:03:17 +02:00  eem_script.py


TST-SW#guestshell run python3 /flash/eem_script.py loop55
python3: can't open file '/flash/eem_script.py': [Errno 2] No such file or directory




[guestshell@guestshell ~]$ python3 --version
Python 3.6.8

 

Thats good, it does look like the docs are out of date or they have been copied over to your version from past versions, even tho python3 is now used.

So if i recall, flash: from the IOS XE CLI is not the same as /flash/ inside the Guestshell's Linux environment. In theory you can use which in guestshell

guestshell@guestshell:~$ which python
guestshell@guestshell:~$ which python3
 
The which python3 should return something like /usr/bin/python3 and if which python returns nothing, then the python alias simply isn't set, and you should definitely use python3.
Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

@bigevilbeard  thank you for the support in this. It looks like the python2 was removed after version 17.3.1. And now only python3 is supported.

Luckily the folder /flash/guest-share is mounted from the flash and if I move my script into it I am able to call the script from within the guestshell.

TST-SW#copy flash:eem_script.py flash:guest-share/
Destination filename [guest-share/eem_script.py]?
Copy in progress...C
420 bytes copied in 0.032 secs (13125 bytes/sec)

TST-SW#guestshell run bash
[guestshell@guestshell ~]$ cd /flash/guest-share/
[guestshell@guestshell guest-share]$ python3 eem_script.py loopback55
This script is going to unshut interface loopback55 and then print show ip interface brief
Line 1 SUCCESS:  interface loopback55
Line 2 SUCCESS:  no shutdown
Line 3 SUCCESS:  end

Interface              IP-Address      OK? Method Status                Protocol
Te1/1/3                unassigned      YES unset  up                    up
Te1/1/4                unassigned      YES unset  up                    up
Ap1/0/1                unassigned      YES unset  up                    up
Bluetooth0/4           unassigned      YES unset  administratively down down
Loopback55             unassigned      YES unset  up                    up

[guestshell@guestshell guest-share]$ exit
TST-SW#guestshell run python3 /flash/guest-share/eem_script.py loopback55
This script is going to unshut interface loopback55 and then print show ip interface brief
Line 1 SUCCESS:  interface loopback55
Line 2 SUCCESS:  no shutdown
Line 3 SUCCESS:  end

Interface              IP-Address      OK? Method Status                Protocol
GigabitEthernet1/0/6   unassigned      YES unset  down                  down
GigabitEthernet1/0/7   unassigned      YES unset  down                  down
GigabitEthernet1/0/8   unassigned      YES unset  down                  down
GigabitEthernet1/0/9   unassigned      YES unset  down                  down
GigabitEthernet1/0/10  unassigned      YES unset  down                  down
GigabitEthernet1/0/11  unassigned      YES unset  down                  down
GigabitEthernet1/0/12  unassigned      YES unset  down                  down
GigabitEthernet1/0/13  unassigned      YES unset  down                  down
GigabitEthernet1/0/14  unassigned      YES unset  down                  down
GigabitEthernet1/0/15  unassigned      YES unset  down                  down
GigabitEthernet1/0/16  unassigned      YES unset  down                  down
GigabitEthernet1/0/17  unassigned      YES unset  down                  down
GigabitEthernet1/0/18  unassigned      YES unset  down                  down
GigabitEthernet1/0/19  unassigned      YES unset  down                  down
GigabitEthernet1/0/20  unassigned      YES unset  down                  down
GigabitEthernet1/0/21  unassigned      YES unset  down                  down
GigabitEthernet1/0/22  unassigned      YES unset  down                  down
GigabitEthernet1/0/23  unassigned      YES unset  down                  down
GigabitEthernet1/0/24  unassigned      YES unset  down                  down
GigabitEthernet1/0/25  unassigned      YES unset  down                  down
GigabitEthernet1/0/26  unassigned      YES unset  down                  down
GigabitEthernet1/0/27  unassigned      YES unset  down                  down
GigabitEthernet1/0/28  unassigned      YES unset  down                  down
Te1/1/3                unassigned      YES unset  up                    up
Te1/1/4                unassigned      YES unset  up                    up
Ap1/0/1                unassigned      YES unset  up                    up
Bluetooth0/4           unassigned      YES unset  administratively down down
Loopback55             unassigned      YES unset  up                    up

 Great success. Thank you @bigevilbeard 

Awesome! Glad i could help here.

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io