<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic ExtremeXOS - JSON Based CLI Output from python process - how? in Scripting</title>
    <link>https://community.extremenetworks.com/t5/scripting/extremexos-json-based-cli-output-from-python-process-how/m-p/68939#M397</link>
    <description>&lt;P&gt;Hey Extreme,&lt;/P&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt; &lt;P&gt;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.&lt;/P&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt; &lt;P&gt;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.&lt;/P&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt; &lt;P&gt;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 …&amp;nbsp;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 cli2json.py 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).&lt;/P&gt; &lt;PRE&gt;&lt;CODE&gt;(debug) pe1.dev.49 # show conf | inc process&lt;BR /&gt;create process test python-module test start auto vr VR-Mgmt&lt;/CODE&gt;&lt;/PRE&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt; &lt;P&gt;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.&lt;/P&gt; &lt;PRE&gt;&lt;CODE class="language-python"&gt;def showcmd(cmds):&lt;BR /&gt; try:&lt;BR /&gt; return subprocess.check_output(&lt;BR /&gt; "/exos/bin/exsh -c 'run script cli2json.py show port no'", shell=True&lt;BR /&gt; )&lt;BR /&gt;&lt;BR /&gt; except subprocess.CalledProcessError as e:&lt;BR /&gt; logger.error("Exception hello(), {}".format(e), exc_info=True)&lt;BR /&gt;&lt;BR /&gt; try:&lt;BR /&gt; return api.exec_cli(["run script cli2json.py show port no"])&lt;BR /&gt;&lt;BR /&gt; except BaseException as e:&lt;BR /&gt; logger.error("Exception hello(), {}".format(e), exc_info=True)&lt;/CODE&gt;&lt;/PRE&gt; &lt;BLOCKQUOTE&gt; &lt;P&gt;ERROR:ExpyRunner:test:showcmd.46:: Exception hello(), Command '/exos/bin/exsh -c 'run script cli2json.py show port no'' returned non-zero exit status 255&lt;BR /&gt; …&amp;nbsp;snip ...&lt;BR /&gt; CalledProcessError: Command '/exos/bin/exsh -c 'run script cli2json.py show port no'' returned non-zero exit status 255&lt;/P&gt; &lt;/BLOCKQUOTE&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt; &lt;P&gt;The return data, from the second try block (that does return)&lt;/P&gt; &lt;BLOCKQUOTE&gt; &lt;P&gt;This command ("run script cli2json.py show port no") is not supported using execCLI XML&lt;/P&gt; &lt;P&gt;API.&lt;/P&gt; &lt;/BLOCKQUOTE&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt; &lt;P&gt;Taking this a step further, if I break into developer_mode&amp;nbsp;&lt;IMG alt=":wink:" src="https://cdn.jsdelivr.net/emojione/assets/png/1f609.png?v=2.2.7" /&gt; and run with a base python&amp;nbsp;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?&lt;/P&gt; &lt;PRE&gt;&lt;CODE&gt;/exos/bin # cat /tmp/test.py&lt;BR /&gt;import subprocess&lt;BR /&gt;print(subprocess.check_output("/exos/bin/exsh -c 'run script cli2json.py show port no'", shell=True ))&lt;BR /&gt;&lt;BR /&gt;/exos/bin # python /tmp/test.py&lt;BR /&gt;[{"CLIoutput": "Port Summary\nPort ... snip ... "}, "status": "SUCCESS"}]&lt;/CODE&gt;&lt;/PRE&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt; &lt;P&gt;I am testing this all against a VirtualBox&amp;nbsp;30.2.1.8 based image. I’d need a solution that works on 16.1.4.2 and greater.&lt;/P&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt; &lt;P&gt;Any thoughts on how I can get structured data back (XML or JSON)&amp;nbsp;from a show command, in a python process under expy, that actually works&amp;nbsp;without running all the boxes in developer mode?&lt;/P&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt; &lt;P&gt;Cheers &amp;amp; Merry Christmas!&lt;BR /&gt; Nick&lt;/P&gt;</description>
    <pubDate>Tue, 17 Dec 2019 10:55:10 GMT</pubDate>
    <dc:creator>nicko170</dc:creator>
    <dc:date>2019-12-17T10:55:10Z</dc:date>
    <item>
      <title>ExtremeXOS - JSON Based CLI Output from python process - how?</title>
      <link>https://community.extremenetworks.com/t5/scripting/extremexos-json-based-cli-output-from-python-process-how/m-p/68939#M397</link>
      <description>&lt;P&gt;Hey Extreme,&lt;/P&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt; &lt;P&gt;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.&lt;/P&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt; &lt;P&gt;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.&lt;/P&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt; &lt;P&gt;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 …&amp;nbsp;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 cli2json.py 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).&lt;/P&gt; &lt;PRE&gt;&lt;CODE&gt;(debug) pe1.dev.49 # show conf | inc process&lt;BR /&gt;create process test python-module test start auto vr VR-Mgmt&lt;/CODE&gt;&lt;/PRE&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt; &lt;P&gt;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.&lt;/P&gt; &lt;PRE&gt;&lt;CODE class="language-python"&gt;def showcmd(cmds):&lt;BR /&gt; try:&lt;BR /&gt; return subprocess.check_output(&lt;BR /&gt; "/exos/bin/exsh -c 'run script cli2json.py show port no'", shell=True&lt;BR /&gt; )&lt;BR /&gt;&lt;BR /&gt; except subprocess.CalledProcessError as e:&lt;BR /&gt; logger.error("Exception hello(), {}".format(e), exc_info=True)&lt;BR /&gt;&lt;BR /&gt; try:&lt;BR /&gt; return api.exec_cli(["run script cli2json.py show port no"])&lt;BR /&gt;&lt;BR /&gt; except BaseException as e:&lt;BR /&gt; logger.error("Exception hello(), {}".format(e), exc_info=True)&lt;/CODE&gt;&lt;/PRE&gt; &lt;BLOCKQUOTE&gt; &lt;P&gt;ERROR:ExpyRunner:test:showcmd.46:: Exception hello(), Command '/exos/bin/exsh -c 'run script cli2json.py show port no'' returned non-zero exit status 255&lt;BR /&gt; …&amp;nbsp;snip ...&lt;BR /&gt; CalledProcessError: Command '/exos/bin/exsh -c 'run script cli2json.py show port no'' returned non-zero exit status 255&lt;/P&gt; &lt;/BLOCKQUOTE&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt; &lt;P&gt;The return data, from the second try block (that does return)&lt;/P&gt; &lt;BLOCKQUOTE&gt; &lt;P&gt;This command ("run script cli2json.py show port no") is not supported using execCLI XML&lt;/P&gt; &lt;P&gt;API.&lt;/P&gt; &lt;/BLOCKQUOTE&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt; &lt;P&gt;Taking this a step further, if I break into developer_mode&amp;nbsp;&lt;IMG alt=":wink:" src="https://cdn.jsdelivr.net/emojione/assets/png/1f609.png?v=2.2.7" /&gt; and run with a base python&amp;nbsp;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?&lt;/P&gt; &lt;PRE&gt;&lt;CODE&gt;/exos/bin # cat /tmp/test.py&lt;BR /&gt;import subprocess&lt;BR /&gt;print(subprocess.check_output("/exos/bin/exsh -c 'run script cli2json.py show port no'", shell=True ))&lt;BR /&gt;&lt;BR /&gt;/exos/bin # python /tmp/test.py&lt;BR /&gt;[{"CLIoutput": "Port Summary\nPort ... snip ... "}, "status": "SUCCESS"}]&lt;/CODE&gt;&lt;/PRE&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt; &lt;P&gt;I am testing this all against a VirtualBox&amp;nbsp;30.2.1.8 based image. I’d need a solution that works on 16.1.4.2 and greater.&lt;/P&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt; &lt;P&gt;Any thoughts on how I can get structured data back (XML or JSON)&amp;nbsp;from a show command, in a python process under expy, that actually works&amp;nbsp;without running all the boxes in developer mode?&lt;/P&gt; &lt;P&gt;&amp;nbsp;&lt;/P&gt; &lt;P&gt;Cheers &amp;amp; Merry Christmas!&lt;BR /&gt; Nick&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 10:55:10 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/scripting/extremexos-json-based-cli-output-from-python-process-how/m-p/68939#M397</guid>
      <dc:creator>nicko170</dc:creator>
      <dc:date>2019-12-17T10:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: ExtremeXOS - JSON Based CLI Output from python process - how?</title>
      <link>https://community.extremenetworks.com/t5/scripting/extremexos-json-based-cli-output-from-python-process-how/m-p/68940#M398</link>
      <description>&lt;P&gt;Hi Nick,&lt;/P&gt; &lt;P&gt;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.&lt;/P&gt; &lt;P&gt;&lt;A href="https://rawgit.com/extremenetworks/EXOS_Apps/master/REST/docs/RESTCONF.html" target="_blank" rel="nofollow noreferrer noopener"&gt;https://rawgit.com/extremenetworks/EXOS_Apps/master/REST/docs/RESTCONF.html&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://github.com/extremenetworks/EXOS_Apps/blob/master/REST/examples/restget.py" target="_blank" rel="nofollow noreferrer noopener"&gt;https://github.com/extremenetworks/EXOS_Apps/blob/master/REST/examples/restget.py&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2020 20:37:54 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/scripting/extremexos-json-based-cli-output-from-python-process-how/m-p/68940#M398</guid>
      <dc:creator>rbrt</dc:creator>
      <dc:date>2020-01-27T20:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: ExtremeXOS - JSON Based CLI Output from python process - how?</title>
      <link>https://community.extremenetworks.com/t5/scripting/extremexos-json-based-cli-output-from-python-process-how/m-p/68941#M399</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;  &lt;P&gt;&amp;nbsp;&lt;/P&gt;  &lt;P&gt;old thread, but maybe still needing an answer?&lt;/P&gt;  &lt;P&gt;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.&lt;/P&gt;  &lt;P&gt;As for running nested script, I doubt it works fine, because they are in different sessions.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2020 19:02:55 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/scripting/extremexos-json-based-cli-output-from-python-process-how/m-p/68941#M399</guid>
      <dc:creator>Stephane_Grosj1</dc:creator>
      <dc:date>2020-06-23T19:02:55Z</dc:date>
    </item>
  </channel>
</rss>

