ExtremeXOS - JSON Based CLI Output from python process - how?

  • 17 December 2019
  • 2 replies

Hey Extreme,


So, I am trying to build a stateful python api that lives on the switch, reason being is I want to dump a json based document of a “state”, and have the switch get it’s self to this state - think automation without poking configure commands via ssh.


Mostly everything is working, if I run as a “script”, everything works via exsh python environment which lets me call commands, get XML back and process the data. I can also configure the switch to a state that I want it to be in nicely.


However, when running as a process on the switch, it’s not letting me import exsh (this is OK, I guess, as it’s a different environment). I am trying to use api.exec_cli, api.exec_exsh_cli et all to grab the data, however that’s … not working either. I can call api.exec_cli([‘’show port no]) to get unstructured output, however when I call api.exec_cli([‘run script show port 1’]), it’s not returning any data and is throwing a CLICommandError exception - with run script not supported. If I use the api.exec_exsh_cli method (that uses subprocesses).

(debug) # show conf | inc process
create process test python-module test start auto vr VR-Mgmt


Per Dave Hammers reply in another thread, using subprocess here also is not working, I am getting a exit return 255 and it’s just .. not returning anything.

def showcmd(cmds):
return subprocess.check_output(
"/exos/bin/exsh -c 'run script show port no'", shell=True

except subprocess.CalledProcessError as e:
logger.error("Exception hello(), {}".format(e), exc_info=True)

return api.exec_cli(["run script show port no"])

except BaseException as e:
logger.error("Exception hello(), {}".format(e), exc_info=True)

ERROR:ExpyRunner:test:showcmd.46:: Exception hello(), Command '/exos/bin/exsh -c 'run script show port no'' returned non-zero exit status 255
… snip ...
CalledProcessError: Command '/exos/bin/exsh -c 'run script show port no'' returned non-zero exit status 255


The return data, from the second try block (that does return)

This command ("run script show port no") is not supported using execCLI XML



Taking this a step further, if I break into developer_mode :wink: and run with a base python command, it actually works perfectly and gives the raw + json output. I feel like there is a permission issue that’s causing this within the expy environment used for processes - or am I doing something wrong?

/exos/bin # cat /tmp/
import subprocess
print(subprocess.check_output("/exos/bin/exsh -c 'run script show port no'", shell=True ))

/exos/bin # python /tmp/
[{"CLIoutput": "Port Summary\nPort ... snip ... "}, "status": "SUCCESS"}]


I am testing this all against a VirtualBox based image. I’d need a solution that works on and greater.


Any thoughts on how I can get structured data back (XML or JSON) from a show command, in a python process under expy, that actually works without running all the boxes in developer mode?


Cheers & Merry Christmas!

2 replies

Userlevel 2

Hi Nick,

old topic, but maybe still of interest: Have you had a look at the REST API provided by the switches themselves? As far as I have seen, that API returns JSON by default.

Userlevel 7



old thread, but maybe still needing an answer?

If you want json output for any commands, you either have to use jsonrpc (21.1+), restconf (22.1+) if available or use debug cfgmgr show commands that are… undocumented and impossibe to guess as for the parameters to (eventually) provide.

As for running nested script, I doubt it works fine, because they are in different sessions.