]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
CCAR: add the kill_remote_containers.py procedure to the SALOME application
authorcaremoli <caremoli>
Fri, 21 Jan 2011 17:18:05 +0000 (17:18 +0000)
committercaremoli <caremoli>
Fri, 21 Jan 2011 17:18:05 +0000 (17:18 +0000)
bin/appli_clean.sh
bin/appli_gen.py
bin/appliskel/kill_remote_containers.py [new file with mode: 0755]

index 09ad9d3fe9ae22ce40e80d35c01a917b03e26515..38bafd46693a39e64166598530d29f3dde198326 100644 (file)
@@ -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 ]
index f6e5bcc7e70062fcafd384ef826ba0b93a69b11b..0e21700b01198b7764e5f43b0fdb252f0114d56c 100644 (file)
@@ -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 (executable)
index 0000000..8360c4a
--- /dev/null
@@ -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()
+