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