6 def get_command(self, command):
9 if 'chroot' in self and self['chroot']:
10 command = " chroot %s %s" % (self['chroot'], command)
12 # Execute vserver exec if necessary
13 if 'vserver' in self and self['vserver']:
14 command = " vserver %s exec %s " % (self['vserver'], command)
16 # Use root key if necessary
17 if 'host' in self and self['host'] not in ['localhost', self.config.hostname]:
18 if 'rootkey' in self and self['rootkey']:
19 options += " -i %s " % self['rootkey']
21 return (command, options)
23 def get_host_command(self, command):
24 (command, options) = self.get_command(command)
25 if 'host' in self and self['host'] not in ['localhost', self.config.hostname]:
26 command = "ssh %s root@%s \"%s\" " % (options, self['host'], command)
29 def get_remote_command(self, command):
30 (command, options) = self.get_command(command)
31 if 'type' in self and self['type'] in ['vm']:
32 if 'redir_port' in self and self['redir_port']:
33 options += " -p %s " % self['redir_port']
35 # attempt ssh self['host'] is not the machine we are running on or
36 # if this is a virtual node
37 if 'host' in self and self['host'] not in ['localhost', self.config.hostname] or \
38 'type' in self and self['type'] in ['vm']:
39 command = "ssh %s root@%s \"%s\" " % (options, self['host'], command)
42 def popen(self, command, fatal = True):
43 command = self.get_remote_command(command)
44 return utils.popen(command, fatal, self.config.verbose)
46 def popen3(self, command):
47 command = self.get_remote_command(command)
48 return utils.popen3(command, self.config.verbose)
50 def commands(self, command, fatal = True):
51 command = self.get_remote_command(command)
52 return utils.commands(command, fatal, self.config.verbose)
54 def scp(self, src, dest):
56 if 'rootkey' in self and self['rootkey'] is not None:
57 options += " -i %s " % (self['rootkey'])
59 if 'chroot' in self and self['chroot'] is not None:
61 if 'vserver' in self and self['vserver'] is not None:
62 path += '/vservers/%s/' % self['vserver']
65 src_parts = src.split(":")
67 dest_parts = dest.split(":")
69 if len(src_parts) == 1:
71 elif src_parts[0].find('localhost') != -1:
72 src_cmd = path + os.sep + src_parts[1]
74 host, file = src_parts[0], src_parts[1]
75 src_cmd = 'root@%(host)s:%(path)s%(file)s ' % locals()
77 if len(dest_parts) == 1:
79 elif dest_parts[0].find('localhost') != -1:
80 dest_cmd = path +os.sep+ dest_parts[1]
82 host, file = dest_parts[0], dest_parts[1]
83 dest_cmd = 'root@%(host)s:%(path)s%(file)s' % locals()
85 command = 'scp %(options)s %(src_cmd)s %(dest_cmd)s' % locals()
86 if self.config.verbose:
88 return utils.commands(command)