From: caremoli Date: Fri, 21 Jan 2011 17:18:05 +0000 (+0000) Subject: CCAR: add the kill_remote_containers.py procedure to the SALOME application X-Git-Tag: Start_BR_19998_21191~93 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b57705a40d2548370a896f3cbeea3a6b233f6da3;p=modules%2Fkernel.git CCAR: add the kill_remote_containers.py procedure to the SALOME application --- diff --git a/bin/appli_clean.sh b/bin/appli_clean.sh index 09ad9d3fe..38bafd466 100644 --- a/bin/appli_clean.sh +++ b/bin/appli_clean.sh @@ -23,7 +23,7 @@ #clean appli -DELCOM="rm -rf bin lib share doc idl env.d envd USERS getAppliPath.py searchFreePort.sh runAppli runConsole runSession runRemote.sh runTests SalomeApp.xml runSalomeScript update_catalogs.py *.pyc *~ .bashrc" +DELCOM="rm -rf bin lib share doc idl env.d envd USERS getAppliPath.py searchFreePort.sh runAppli runConsole runSession runRemote.sh runTests SalomeApp.xml runSalomeScript update_catalogs.py kill_remote_containers.py *.pyc *~ .bashrc" DOIT="false" if [ $# -gt 0 ] diff --git a/bin/appli_gen.py b/bin/appli_gen.py index f6e5bcc7e..0e21700b0 100644 --- a/bin/appli_gen.py +++ b/bin/appli_gen.py @@ -193,6 +193,7 @@ def install(prefix,config_file,verbose=0): 'runSalomeScript', 'runTests', 'update_catalogs.py', + 'kill_remote_containers.py', '.bashrc', ): virtual_salome.symlink("./bin/salome/appliskel/"+fn,os.path.join(home_dir, fn)) diff --git a/bin/appliskel/kill_remote_containers.py b/bin/appliskel/kill_remote_containers.py new file mode 100755 index 000000000..8360c4afd --- /dev/null +++ b/bin/appliskel/kill_remote_containers.py @@ -0,0 +1,132 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +""" +import sys,os,shutil,glob,socket +import optparse + +import getAppliPath +appli_local=os.path.realpath(os.path.dirname(__file__)) +APPLI=getAppliPath.relpath(appli_local,os.path.realpath(os.getenv('HOME'))) + +usage="""usage: %prog [options] + +This procedure kill all containers that have been launched in a SALOME session on remote machines. +A SALOME session is identified by a machine name and a port number. + +You need to have a well installed SALOME application with a CatalogResources.xml file. +This file is used (parsed) to collect all remote resources. +Remote resources are all the resources on remote machines not including the main local SALOME application. +""" + +try: + # cElementTree from Python 2.5+ + import xml.etree.cElementTree as etree_ +except ImportError: + try: + import xml.etree.ElementTree as etree_ + except ImportError: + try: + import cElementTree as etree_ + except ImportError: + try: + # normal ElementTree install + import elementtree.ElementTree as etree_ + except ImportError: + raise + +class ParseError(Exception): + pass + +catalog_file=os.path.join(appli_local,"CatalogResources.xml") + +SEP=":" +if sys.platform == "win32":SEP=";" + +def get_hostname(): + return socket.gethostname().split('.')[0] + +class Resource: + """Define a SALOME resource + - components : the list of available components of the resource + """ + def __init__(self,node): + self.node=node + self.components=[] + self.resource_dir=None + + def get_rcp(self): + protocol= self.node.get("protocol") + if protocol and protocol[0]=='s':return "scp" + else:return "rcp" + + def get_rsh(self): + protocol= self.node.get("protocol") + if protocol and protocol[0]=='s':return "ssh" + else:return "rsh" + + def get_user(self): + userName= self.node.get("userName") + if not userName: + userName=os.getenv('USER') + return userName + + def get_host(self): + hostname= self.node.get("hostname") + return hostname + + def get_name(self): + name= self.node.get("name") + if name:return name + return self.get_host() + + def get_appliPath(self): + appliPath= self.node.get("appliPath") + if appliPath is None: + appliPath=APPLI + return appliPath + +def main(): + parser = optparse.OptionParser(usage=usage) + parser.add_option('-p','--port', dest="port", + help="The SALOME session port (default NSPORT or 2810)") + + + options, args = parser.parse_args() + + if not os.path.exists(catalog_file): + print "ERROR: the catalog file %s is mandatory" % catalog_file_base + sys.exit(1) + + #Parse CatalogResource.xml + doc = etree_.parse(catalog_file) + + rootNode = doc.getroot() + if rootNode.tag != "resources": + raise ParseError("First level tag must be resources not %s" % rootNode.tag) + + resources=[] + + #Extract resources + for child in rootNode: + if child.tag != "machine": + raise ParseError("Second level tag must be machine not %s" % child.tag) + resources.append(Resource(child)) + + local_names=("localhost",get_hostname()) + + for resource in resources: + if resource.get_host() in local_names:continue + command=resource.get_rsh() +" -l "+resource.get_user()+" "+resource.get_host() + command=command+ " " + os.path.join(resource.get_appliPath(),"runRemote.sh") + if options.port: + port=options.port + else: + port=os.getenv("NSPORT") or "2810" + command=command+ " " + get_hostname() + " " + port +" killSalomeWithPort.py " + port + print command + os.system(command) + +if __name__ == '__main__': + main() +