<?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 RE: python process termination in ExtremeSwitching (EXOS/Switch Engine)</title>
    <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-process-termination/m-p/53945#M15289</link>
    <description>Sorry, I wasn't clear. This has to be run from the EXOS process environment i.e. from the python that you give to 'create process'. &lt;BR /&gt;
&lt;BR /&gt;
My test stub was a bad example since I bypassed the restrictions to validate the class.&lt;BR /&gt;
&lt;BR /&gt;
If you include the class in your applications and call cli.exos_cli2xml(cmd) within the application, it should work for you. &lt;BR /&gt;
&lt;BR /&gt;
The parts that are available from the normal CLI are:&lt;BR /&gt;
run script cli2xml.py &lt;CMD&gt; &amp;lt; - this would be your new 3 line script&lt;BR /&gt;
run script cli2json.py &lt;CMD&gt; &amp;lt;-this is the script already shipping with EXOS&lt;BR /&gt;
(run script cli2json.py &lt;B&gt;-d&lt;/B&gt; &lt;CMD&gt; creates a more human readable output)&lt;/CMD&gt;&lt;/CMD&gt;&lt;/CMD&gt;</description>
    <pubDate>Mon, 23 Jan 2017 23:54:00 GMT</pubDate>
    <dc:creator>Dave_Hammers</dc:creator>
    <dc:date>2017-01-23T23:54:00Z</dc:date>
    <item>
      <title>python process termination</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-process-termination/m-p/53939#M15283</link>
      <description>I have a question on what happens when a process is terminated.&lt;BR /&gt;
&lt;BR /&gt;
I create a process:  &lt;B&gt;create process Proc python-module [python file] start on-demand&lt;/B&gt; &lt;BR /&gt;
&lt;BR /&gt;
I then start it: &lt;B&gt;start process Proc slot 1&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
When I terminate it: &lt;B&gt;terminate process Proc gracefully slot 1&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
Is there an exception that I can catch in my python script so I can do some kind of cleanup or extra logging before the process completely dies?&lt;BR /&gt;
&lt;BR /&gt;</description>
      <pubDate>Wed, 18 Jan 2017 22:41:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-process-termination/m-p/53939#M15283</guid>
      <dc:creator>bw447</dc:creator>
      <dc:date>2017-01-18T22:41:00Z</dc:date>
    </item>
    <item>
      <title>RE: python process termination</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-process-termination/m-p/53940#M15284</link>
      <description>Unfortunately, no.&lt;BR /&gt;
The 'create process' in EXOS runs the python code in its own thread which means python threading rules apply.&lt;BR /&gt;
&lt;BR /&gt;
A possible future enhancement would be to signal the thread in some fashion that a SystemExit exception occurred, but that doesn't help you in currently shipping EXOS. ﻿</description>
      <pubDate>Thu, 19 Jan 2017 21:53:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-process-termination/m-p/53940#M15284</guid>
      <dc:creator>Dave_Hammers</dc:creator>
      <dc:date>2017-01-19T21:53:00Z</dc:date>
    </item>
    <item>
      <title>RE: python process termination</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-process-termination/m-p/53941#M15285</link>
      <description>&lt;B&gt;@Dave&lt;/B&gt;, Thanks for the explanation!</description>
      <pubDate>Thu, 19 Jan 2017 22:04:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-process-termination/m-p/53941#M15285</guid>
      <dc:creator>bw447</dc:creator>
      <dc:date>2017-01-19T22:04:00Z</dc:date>
    </item>
    <item>
      <title>RE: python process termination</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-process-termination/m-p/53942#M15286</link>
      <description>@Dave,  Currently we are running 16.1.3.6&lt;BR /&gt;
&lt;BR /&gt;
I prefer to get the output from a command as xml when running a script: &lt;BR /&gt;
&lt;BR /&gt;
exsh.clicmd(cmd, xml=True) &lt;BR /&gt;
&lt;BR /&gt;
Are there plans to be able to get xml output from a process?  From what I see in the Python doc it's only possible to receive output as regular text.&lt;BR /&gt;
&lt;BR /&gt;
Thanks!&lt;BR /&gt;
&lt;BR /&gt;</description>
      <pubDate>Fri, 20 Jan 2017 22:36:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-process-termination/m-p/53942#M15286</guid>
      <dc:creator>bw447</dc:creator>
      <dc:date>2017-01-20T22:36:00Z</dc:date>
    </item>
    <item>
      <title>RE: python process termination</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-process-termination/m-p/53943#M15287</link>
      <description>There is a way to do this but it's a bit involved. We do something similar to return JSON from CLI commands.when writing EXOS python apps.&lt;BR /&gt;
&lt;BR /&gt;
Create a script cli2xml.py with the following 3 lines:&lt;BR /&gt;
import sys&lt;BR /&gt;
cmd = ' '.join(sys.argv[1:])&lt;BR /&gt;
print exsh.clicmd(cmd, xml=True)&lt;B&gt;&lt;/B&gt;You can test this by the CLI command: run script cli2xml.py show port 1 no-refresh&lt;BR /&gt;
It's also handy when you want to see what the XML output of a command looks like before writing any code. &lt;BR /&gt;
&lt;BR /&gt;
In your python application, invoke the EXOS command shell to run cli2xml.py with your command. &lt;BR /&gt;
Below is an example:&lt;BR /&gt;
# This is an example of a class that would interface to cli2xml.py in the Python application # environment&lt;BR /&gt;
import subprocess&lt;BR /&gt;
class ExosCliToXml(object):&lt;BR /&gt;
    def __init__(self):&lt;BR /&gt;
        self.dummy = None&lt;BR /&gt;
   &lt;B&gt;@staticmethod&lt;/B&gt;&lt;BR /&gt;
    def exos_cli2xml(cmd):&lt;BR /&gt;
        shell_cmd = "/exos/bin/exsh -n 0 -b -c 'run script cli2xml.py {0}'".format(cmd)&lt;BR /&gt;
        p = subprocess.Popen([shell_cmd], shell=True,&lt;BR /&gt;
                stdin=subprocess.PIPE,&lt;BR /&gt;
                stdout=subprocess.PIPE,&lt;BR /&gt;
                stderr=subprocess.PIPE)&lt;BR /&gt;
        (stdoutdata, stderrdata) = p.communicate()&lt;BR /&gt;
        return (stdoutdata, stderrdata)&lt;BR /&gt;
&lt;BR /&gt;
# test stub&lt;BR /&gt;
cli = ExosCliToXml()&lt;BR /&gt;
while True:&lt;BR /&gt;
    cmd = raw_input('enter command &amp;gt; ')&lt;BR /&gt;
    if cmd in ['quit', 'exit']:&lt;BR /&gt;
        break&lt;BR /&gt;
    (stdoutdata, stderrdata) = cli.exos_cli2xml(cmd)    # print the XML output from the command&lt;BR /&gt;
    print stdoutdata&lt;BR /&gt;
If you wanted to use JSON, there is already a script shipping with EXOS: cli2json.py&lt;BR /&gt;
E.g. run script cli2json.py show port 1In the class, change cli2xml.py to cli2json.py for JSON output.to change from XML to JSON</description>
      <pubDate>Sat, 21 Jan 2017 01:57:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-process-termination/m-p/53943#M15287</guid>
      <dc:creator>Dave_Hammers</dc:creator>
      <dc:date>2017-01-21T01:57:00Z</dc:date>
    </item>
    <item>
      <title>RE: python process termination</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-process-termination/m-p/53944#M15288</link>
      <description>Hello Dave,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for the info. Below I'm getting the following Permission denied when I run your test script up above.  I'm seeing the Permission denied output because I added 'print stderrdata' after your last print stdoutdata statement up above.&lt;BR /&gt;
&lt;BR /&gt;
&lt;I&gt;* Slot-1 Kenn-B.8 # run script CliToXml.py&lt;/I&gt;&lt;BR /&gt;
&lt;I&gt;enter command &amp;gt; show version&lt;/I&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;I&gt;/bin/sh: /exos/bin/exsh: Permission denied&lt;/I&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;I&gt;enter command &amp;gt; quit&lt;/I&gt;&lt;BR /&gt;
&lt;BR /&gt;
I tried it with the JSON output by changing the script name as you said at then end of your comment and I received the same Persmission denied error.&lt;BR /&gt;
&lt;BR /&gt;
I'm running this script as the local admin account.&lt;BR /&gt;
&lt;BR /&gt;
Any thoughts?  &lt;BR /&gt;
&lt;BR /&gt;</description>
      <pubDate>Mon, 23 Jan 2017 23:40:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-process-termination/m-p/53944#M15288</guid>
      <dc:creator>bw447</dc:creator>
      <dc:date>2017-01-23T23:40:00Z</dc:date>
    </item>
    <item>
      <title>RE: python process termination</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-process-termination/m-p/53945#M15289</link>
      <description>Sorry, I wasn't clear. This has to be run from the EXOS process environment i.e. from the python that you give to 'create process'. &lt;BR /&gt;
&lt;BR /&gt;
My test stub was a bad example since I bypassed the restrictions to validate the class.&lt;BR /&gt;
&lt;BR /&gt;
If you include the class in your applications and call cli.exos_cli2xml(cmd) within the application, it should work for you. &lt;BR /&gt;
&lt;BR /&gt;
The parts that are available from the normal CLI are:&lt;BR /&gt;
run script cli2xml.py &lt;CMD&gt; &amp;lt; - this would be your new 3 line script&lt;BR /&gt;
run script cli2json.py &lt;CMD&gt; &amp;lt;-this is the script already shipping with EXOS&lt;BR /&gt;
(run script cli2json.py &lt;B&gt;-d&lt;/B&gt; &lt;CMD&gt; creates a more human readable output)&lt;/CMD&gt;&lt;/CMD&gt;&lt;/CMD&gt;</description>
      <pubDate>Mon, 23 Jan 2017 23:54:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-process-termination/m-p/53945#M15289</guid>
      <dc:creator>Dave_Hammers</dc:creator>
      <dc:date>2017-01-23T23:54:00Z</dc:date>
    </item>
    <item>
      <title>RE: python process termination</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-process-termination/m-p/53946#M15290</link>
      <description>Got it!  Thank you sir!</description>
      <pubDate>Wed, 25 Jan 2017 03:05:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-process-termination/m-p/53946#M15290</guid>
      <dc:creator>bw447</dc:creator>
      <dc:date>2017-01-25T03:05:00Z</dc:date>
    </item>
  </channel>
</rss>

