1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 """
21 ClusterShell RSH support
22
23 It could also handles rsh forks, like krsh or mrsh.
24 This is also the base class for rsh evolutions, like Ssh worker.
25 """
26
27 import os
28 import shlex
29
30 from ClusterShell.Worker.Exec import ExecClient, CopyClient, ExecWorker
31
32
34 """
35 Rsh EngineClient.
36 """
37
39 """
40 Build the shell command line to start the rsh commmand.
41 Return an array of command and arguments.
42 """
43
44 task = self.worker.task
45 path = task.info("rsh_path") or "rsh"
46 user = task.info("rsh_user")
47 options = task.info("rsh_options")
48
49 cmd_l = [os.path.expanduser(pathc) for pathc in shlex.split(path)]
50
51 if user:
52 cmd_l.append("-l")
53 cmd_l.append(user)
54
55
56 if options:
57 cmd_l += shlex.split(options)
58
59 cmd_l.append("%s" % self.key)
60 cmd_l.append("%s" % self.command)
61
62 return (cmd_l, None)
63
64
66 """
67 Rcp EngineClient.
68 """
69
71 """
72 Build the shell command line to start the rcp commmand.
73 Return an array of command and arguments.
74 """
75
76
77 task = self.worker.task
78 path = task.info("rcp_path") or "rcp"
79 user = task.info("rsh_user")
80 options = task.info("rcp_options") or task.info("rsh_options")
81
82 cmd_l = [os.path.expanduser(pathc) for pathc in shlex.split(path)]
83
84 if self.isdir:
85 cmd_l.append("-r")
86
87 if self.preserve:
88 cmd_l.append("-p")
89
90
91 if options:
92 cmd_l += shlex.split(options)
93
94 if self.reverse:
95 if user:
96 cmd_l.append("%s@%s:%s" % (user, self.key, self.source))
97 else:
98 cmd_l.append("%s:%s" % (self.key, self.source))
99
100 cmd_l.append(os.path.join(self.dest, "%s.%s" % \
101 (os.path.basename(self.source), self.key)))
102 else:
103 cmd_l.append(self.source)
104 if user:
105 cmd_l.append("%s@%s:%s" % (user, self.key, self.dest))
106 else:
107 cmd_l.append("%s:%s" % (self.key, self.dest))
108
109 return (cmd_l, None)
110
111
113 """
114 ClusterShell rsh-based worker Class.
115
116 Remote Shell (rsh) usage example:
117 >>> worker = WorkerRsh(nodeset, handler=MyEventHandler(),
118 ... timeout=30, command="/bin/hostname")
119 >>> task.schedule(worker) # schedule worker for execution
120 >>> task.resume() # run
121
122 Remote Copy (rcp) usage example:
123 >>> worker = WorkerRsh(nodeset, handler=MyEventHandler(),
124 ... source="/etc/my.conf",
125 ... dest="/etc/my.conf")
126 >>> task.schedule(worker) # schedule worker for execution
127 >>> task.resume() # run
128
129 connect_timeout option is ignored by this worker.
130 """
131
132 SHELL_CLASS = RshClient
133 COPY_CLASS = RcpClient
134
135 WORKER_CLASS=WorkerRsh
136