cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3304
Views
0
Helpful
1
Replies

Problem with python script - permission denied

AdamBogdan26228
Level 1
Level 1

Hi all,

 

I've been playing with iox and it is super fun but I hit some problem and cannot solve it.
Switch: C3850-48P

IOS: 16.12.4
IOx is enabled on the switch and guestshell is running - so far so good - I wrote super simple/short python script:

import cli
import os
import time

os.system("echo 'Starting the script' > /dev/ttyS2")
time.sleep(1)
os.system("echo 'second line' > /dev/ttyS2")
time.sleep(1)
a = cli.execute('show clock')
print(a)

 and now - if I run this script manually from guestshell - it is working as expected:

[guestshell@guestshell ~]$ python one.py 
*16:10:49.210 CEST Thu Jun 10 2021

1408424: *Jun 10 2021 16:10:47.959 CEST: %IM-5-IOX_INST_NOTICE: Switch 1 R0/0: ioxman: IOX SERVICE guestshell LOG: Starting the script
1408425: *Jun 10 2021 16:10:48.970 CEST: %IM-5-IOX_INST_NOTICE: Switch 1 R0/0: ioxman: IOX SERVICE guestshell LOG: second line

 but - when I try to run that script from EEM script I get permission denied error.

 

Here is simple EEM:

event manager applet check_script authorization bypass
event timer countdown time 5 maxrun 90
action 0010 cli command "enable"
action 0020 cli command "guestshell run python /home/guestshell/one.py"
action 0030 wait 10
action 0040 cli command "conf t"
action 0050 cli command "no event manager applet check_script authorization bypass"
action 0060 cli command "end"

and this is what I get in switch log:

408447: *Jun 10 2021 16:13:43.084 CEST: %HA_EM-6-LOG: check_script : DEBUG(cli_lib) : : CTL : cli_open called.
1408448: *Jun 10 2021 16:13:43.186 CEST: %HA_EM-6-LOG: check_script : DEBUG(cli_lib) : : OUT : test_switch>
1408449: *Jun 10 2021 16:13:43.187 CEST: %HA_EM-6-LOG: check_script : DEBUG(cli_lib) : : IN : test_switch>enable
1408450: *Jun 10 2021 16:13:43.200 CEST: %PARSER-5-CFGLOG_LOGGEDCMD: User:unknown user logged command:!exec: enable
1408451: *Jun 10 2021 16:13:43.299 CEST: %HA_EM-6-LOG: check_script : DEBUG(cli_lib) : : OUT : test_switch#
1408452: *Jun 10 2021 16:13:43.300 CEST: %HA_EM-6-LOG: check_script : DEBUG(cli_lib) : : IN : test_switch#guestshell run python /home/guestshell/one.py
1408456: *Jun 10 2021 16:14:00.744 CEST: %IM-5-IOX_INST_NOTICE: Switch 1 R0/0: ioxman: IOX SERVICE guestshell LOG: Starting the script
1408459: *Jun 10 2021 16:14:01.753 CEST: %IM-5-IOX_INST_NOTICE: Switch 1 R0/0: ioxman: IOX SERVICE guestshell LOG: second line
1408460: *Jun 10 2021 16:14:02.221 CEST: %PNP-6-PNP_SAVING_TECH_SUMMARY: Saving PnP tech summary (pnp-tech-error-summary)... Please wait. Do not interrupt.
1408461: *Jun 10 2021 16:14:03.234 CEST: %SYS-5-CONFIG_P: Configured programmatically by process XEP_pnp_python from console as vty4
1408462: *Jun 10 2021 16:14:11.656 CEST: %SYS-5-CONFIG_P: Configured programmatically by process XEP_pnp_python from console as vty4
1408463: *Jun 10 2021 16:14:12.657 CEST: %PNP-6-PNP_TECH_SUMMARY_SAVED_OK: PnP tech summary (pnp-tech-error-summary) saved successfully.
1408464: *Jun 10 2021 16:14:18.271 CEST: %HA_EM-6-LOG: check_script : DEBUG(cli_lib) : : OUT : Traceback (most recent call last):
1408465: *Jun 10 2021 16:14:18.271 CEST: %HA_EM-6-LOG: check_script : DEBUG(cli_lib) : : OUT : File "/home/guestshell/one.py", line 9, in <module>
1408466: *Jun 10 2021 16:14:18.272 CEST: %HA_EM-6-LOG: check_script : DEBUG(cli_lib) : : OUT : a = cli.execute('show clock')
1408467: *Jun 10 2021 16:14:18.272 CEST: %HA_EM-6-LOG: check_script : DEBUG(cli_lib) : : OUT : File "/usr/lib/python2.7/site-packages/cli/__init__.py", line 102, in execute
1408468: *Jun 10 2021 16:14:18.272 CEST: %HA_EM-6-LOG: check_script : DEBUG(cli_lib) : : OUT : raise CLICommandError(command, str(response))
1408469: *Jun 10 2021 16:14:18.273 CEST: %HA_EM-6-LOG: check_script : DEBUG(cli_lib) : : OUT : cli.CLICommandError: ERROR: PERMISSION_DENIED - authorization failed: There was a problem running the command: "show clock"
1408470: *Jun 10 2021 16:14:18.273 CEST: %HA_EM-6-LOG: check_script : DEBUG(cli_lib) : : OUT :
1408471: *Jun 10 2021 16:14:18.273 CEST: %HA_EM-6-LOG: check_script : DEBUG(cli_lib) : : OUT :

 

Any hints/ideas what I'm missing or doing wrong / how to fix it ??

 

Regards

Adam

1 Reply 1

Alex Stevenson
Cisco Employee
Cisco Employee

 

Hi @AdamBogdan26228 ,

 

Good job getting the script running, at least locally. I agree IOx can be a lot of fun. I spent many hours on the IR829 playing with it. The new IR1800 Series is even smoother!

 

As far as your script, I think we can see the error in this line of output:

 

1408465: *Jun 10 2021 16:14:18.271 CEST: %HA_EM-6-LOG: check_script : DEBUG(cli_lib) : : OUT : File "/home/guestshell/one.py", line 9, in <module>


Line 9 of your code which it refers to, is:

 

a = cli.execute('show clock')


 

This CLI module you import is not a standard library, as os and time are. This means you must install that module into your code. The details can be found here --> https://pythonhosted.org/pyCLI/

 

According to the docs I have just listed, these are the sub-modules for the CLI / pyCLI module:

 

app

log

daemon

profiler

test

 

I don't see a cli.execute and this is the 3.9 docs.

 

Hope this helps!