Salome HOME
[EDF27562] : Fix clustertest
[modules/kernel.git] / src / Container / ScriptsTemplate / SALOME_CM_REMOTE_OLD.py
1 import sys
2
3 class ScriptRemoteParameters:
4     def __init__(self, args):
5         import KernelBasis
6         self.debug = KernelBasis.VerbosityActivated()
7         self.protocol = args[0]
8         self.user = self._read_arg(args[1], "NULL")
9         self.host = self._read_arg(args[2], "NULL")
10         self.appli = self._read_arg(args[3], "NULL")
11         self.workdir = self._read_arg(args[4], "NULL")
12         self.ssl = True if args[5] == "1" else False
13         self.nshost = args[6]
14         self.nsport = args[7]
15         self.remote_script = self._read_arg(args[8], "NULL")
16         self.naming_service = self._read_arg(args[9], "NULL")
17         self.appli_mode = args[10]
18
19         import platform
20         self.Windows = platform.system() == "Windows"
21
22     def _read_arg(self, value, null_value):
23         if value == null_value:
24             return None
25         return value
26
27     def __str__(self):
28         str = []
29         str.append("protocol: %s" % self.protocol)
30         str.append("user: %s" % self.user)
31         str.append("hostname: %s" % self.host)
32         str.append("appli: %s" % self.appli)
33         str.append("workdir: %s" % self.workdir)
34         str.append("ssl: %s" % self.ssl)
35         str.append("nshost: %s" % self.nshost)
36         str.append("nsport: %s" % self.nsport)
37         str.append("remote_script: %s" % self.remote_script)
38         str.append("naming_service: %s" % self.naming_service)
39         str.append("appil_mode: %s" % self.appli_mode)
40         str.append("--")
41         return "\n".join(str)
42
43 # ----------------------------------------------
44 def command(args):
45     import KernelBasis
46     options = ScriptRemoteParameters(args)
47     if options.debug:
48         KernelBasis.WriteInStdout( str(options) )
49
50     # build command depending on protocol
51     cmd = []
52     envd = (options.protocol != "srun")
53
54     if options.protocol == "rsh":
55         # RSH command
56         cmd.append("rsh")
57         if options.user:
58             cmd.append("-l " + options.user)
59         cmd.append(options.host)
60
61     elif options.protocol == "ssh":
62         # SSH command
63         cmd.append("ssh")
64         if options.user:
65             cmd.append("-l " + options.user)
66         cmd.append(options.host)
67
68     elif options.protocol == "srun":
69         # srun command
70         cmd.append("srun")
71         cmd.append("-n 1 -N 1 -s --mem-per-cpu=0 --cpu-bind=none")
72         cmd.append("--nodelist=" + options.host)
73
74     elif options.protocol == "pbsdsh":
75         # pbsdh command
76         cmd.append("pbsdsh")
77         cmd.append("-o -h")
78         cmd.append(options.host)
79
80     elif options.protocol == "blaunch":
81         # blaunch command
82         cmd.append("blaunch")
83         cmd.append("-no-shell")
84         cmd.append(options.host)
85
86     else:
87         # unknown protocol
88         raise ValueError("Unknown protocol: %s" % options.protocol)
89
90
91     if options.appli_mode == "dir":
92         cmd.append(options.appli + "/" + options.remote_script)
93         if not envd:
94             cmd.append("--noenvd")
95         if options.ssl:
96             cmd.append(options.naming_service)
97         else:
98             cmd.append(options.nshost)
99             cmd.append(options.nsport)
100
101         if options.workdir:
102             cmd.append(" WORKINGDIR '%s'" % options.workdir)
103
104     elif options.appli_mode == "launcher":
105         cmd.append(options.appli + " remote")
106         if not options.ssl:
107             cmd.append("-m %s -p %s" % (options.nshost, options.nsport))
108
109         if options.workdir:
110             cmd.append("-d " + options.workdir)
111         cmd.append("--")
112
113     # elif ignore other appli_mode value
114
115     return " ".join(cmd)