05-09-2023 06:58 AM - edited 05-09-2023 06:58 AM
Hi dear community,
Can someone please assist me in fixing the following error messages in the python3 interpreter in Guestshell ?
Router#guestshell run sudo python3
Python 3.6.8 (default, Aug 24 2020, 18:22:40)
[GCC 8.3.1 20191121 (Red Hat 8.3.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cli
>>> cli.clip("show ip int brief")
Unexpected Error
>>> cli.executep("show ip int brief")
Unexpected Error
>>> output = cli.execute("show ip int brief")
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/cli/__init__.py", line 284, in cli
stderr=subprocess.STDOUT, shell=True)
File "/usr/lib64/python3.6/subprocess.py", line 356, in check_output
**kwargs).stdout
File "/usr/lib64/python3.6/subprocess.py", line 438, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command 'iosp_client -om 3 -o /tmp/.iosp_2023_05_09_13_58_56_008499_971558159.output -i /tmp/.iosp_2023_05_09_13_58_56_008499_971558159.cmd' returned non-zero exit status 4.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/site-packages/cli/__init__.py", line 336, in execute
return (cli(command))
File "/usr/lib/python3.6/site-packages/cli/__init__.py", line 298, in cli
raise IOSPUnexpectedError
cli.IOSPUnexpectedError: Unexpected Error
Thanks in advance,
Regards,
Jerems
Solved! Go to Solution.
05-09-2023 07:52 AM
You need to import clip for that to work
from cli import clip
From cli you can do
>>> import cli >>> cli.cli('show version')
05-09-2023 07:52 AM
You need to import clip for that to work
from cli import clip
From cli you can do
>>> import cli >>> cli.cli('show version')
05-09-2023 08:43 AM
Hi Stuart,
Thank you so much for your quick reply.
"import cli" is not enough?
Thanks in advance
05-09-2023 10:01 AM
I was wondering this after i posted tried... as i was wondering why
>>> dir(cli)
['BKUP_LOGFILE', 'CLICommandError', 'ConfigResult', 'IOSPCLIConfError', 'IOSPCLIError', 'IOSPSetupInProgress', 'IOSPSystemError', 'IOSPUnexpectedError', 'LOGFILE', 'MAX_WAIT_TIME', '_SUPERFLUOUS_CONFIG_LINE', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', '__warningregistry__', '_log_output_file', '_log_to_file', 'check_and_set_iosp_env', 'check_iosp_session', 'cli', 'clip', 'configure', 'configurep', 'copy', 'datetime', 'execute', 'executep', 'get_current_caf_app_id', 'glob', 'netconf_disable_guestshell', 'netconf_enable_guestshell', 'os', 'parser_dict', 'random', 're', 'shutil', 'subprocess', 'sys', 'valid']
On this version is it ok
>>> cli.clip("show version | inc Ver")
Cisco IOS XE Software, Version 17.09.02a
Cisco IOS Software [Cupertino], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 17.9.2a, RELEASE SOFTWARE (fc4)
So it looks like you did sudo
csr8000v#guestshell run sudo python3
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 more information.
>>> import cli
>>> cli.clip("show ip int brief")
Unexpected Error
So.....
csr8000v#guestshell run python3
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 more information.
>>> import cli
>>> cli.clip("show ip int brief")
Interface IP-Address OK? Method Status Protocol
GigabitEthernet1 10.10.20.148 YES NVRAM up up
GigabitEthernet2 unassigned YES NVRAM administratively down down
GigabitEthernet3 unassigned YES NVRAM administratively down down
Loopback0 10.0.0.1 YES NVRAM up up
Loopback10 unassigned YES unset up up
Loopback109 10.255.255.9 YES NVRAM up up
VirtualPortGroup0 192.168.1.1 YES NVRAM up up
I had to dig the docs
> During the Guest Shell installation, SSH access is setup with a key-based authentication. The access to the Guest Shell is restricted to the user with the highest privilege (15) in Cisco IOS. This user is granted access into the Linux container as the guestshell Linux user, who is a sudoer, and can perform all root operations. Commands executed through the Guest Shell are executed with the same privilege that a user has when logged into the Cisco IOS terminal.
So if you are logged in as priv 15 - no need to use sudo.
Hope this helps.
05-09-2023 02:51 PM
Thanks you for sharing this explaination.
Actually, i want to achieve the automatic registration of an "outofthebox" router to netbox so my python script (downloaded by the device at bootup thanks to dhcp options) aims to make sure that i can install the necessary librairies (pynetbox) during the inital bootup of the device thanks to guestshell.
From my understanding, this process can not be achieved easily in one script but i might be wrong.
If you have some clues, please let me know ;-).
Thanks again
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide