Package ClusterShell :: Package Worker :: Module Rsh
[hide private]
[frames] | no frames]

Source Code for Module ClusterShell.Worker.Rsh

  1  # 
  2  # Copyright (C) 2013-2015 CEA/DAM 
  3  # 
  4  # This file is part of ClusterShell. 
  5  # 
  6  # ClusterShell is free software; you can redistribute it and/or 
  7  # modify it under the terms of the GNU Lesser General Public 
  8  # License as published by the Free Software Foundation; either 
  9  # version 2.1 of the License, or (at your option) any later version. 
 10  # 
 11  # ClusterShell is distributed in the hope that it will be useful, 
 12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 14  # Lesser General Public License for more details. 
 15  # 
 16  # You should have received a copy of the GNU Lesser General Public 
 17  # License along with ClusterShell; if not, write to the Free Software 
 18  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 
 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   
33 -class RshClient(ExecClient):
34 """ 35 Rsh EngineClient. 36 """ 37
38 - def _build_cmd(self):
39 """ 40 Build the shell command line to start the rsh commmand. 41 Return an array of command and arguments. 42 """ 43 # Does not support 'connect_timeout' 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 # Add custom options 56 if options: 57 cmd_l += shlex.split(options) 58 59 cmd_l.append("%s" % self.key) # key is the node 60 cmd_l.append("%s" % self.command) 61 62 return (cmd_l, None)
63 64
65 -class RcpClient(CopyClient):
66 """ 67 Rcp EngineClient. 68 """ 69
70 - def _build_cmd(self):
71 """ 72 Build the shell command line to start the rcp commmand. 73 Return an array of command and arguments. 74 """ 75 76 # Does not support 'connect_timeout' 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 # Add custom rcp options 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
112 -class WorkerRsh(ExecWorker):
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