8 if 'host' in self and self['host']:
9 if self['host'] not in ['localhost', self.config.hostname, None]:
11 if 'vserver' in self and self['vserver']:
12 path += '/vservers/%s/' % self['vserver']
13 if 'chroot' in self and self['chroot']:
14 path += self['chroot'] + os.sep
15 if 'homedir' in self and self['homedir']:
16 path += self['homedir'] + os.sep
20 def get_command(self, command):
21 options = " -o StrictHostKeyChecking=no "
23 if 'chroot' in self and self['chroot']:
24 command = " chroot %s %s" % (self['chroot'], command)
26 # Execute vserver exec if necessary
27 if 'vserver' in self and self['vserver']:
28 command = " vserver %s exec %s " % (self['vserver'], command)
30 # Use root key if necessary
31 if 'host' in self and self['host'] not in ['localhost', self.config.hostname]:
32 if 'rootkey' in self and self['rootkey']:
33 options += " -i %s " % self['rootkey']
35 return (command, options)
37 def get_host_command(self, command):
38 (command, options) = self.get_command(command)
39 if 'host' in self and self['host'] not in ['localhost', self.config.hostname]:
40 command = "ssh %s root@%s \"%s\" " % (options, self['host'], command)
43 def get_remote_command(self, command):
44 (command, options) = self.get_command(command)
45 if 'type' in self and self['type'] in ['vm']:
46 if 'redir_port' in self and self['redir_port']:
47 options += " -p %s " % self['redir_port']
49 # attempt ssh self['host'] is not the machine we are running on or
50 # if this is a virtual node
51 if 'host' in self and self['host'] not in ['localhost', self.config.hostname] or \
52 'type' in self and self['type'] in ['vm']:
53 command = "ssh %s root@%s \"%s\" " % (options, self['host'], command)
56 def popen(self, command, fatal = True):
57 command = self.get_remote_command(command)
58 return utils.popen(command, fatal, self.config.verbose)
60 def popen3(self, command):
61 command = self.get_remote_command(command)
62 return utils.popen3(command, self.config.verbose)
64 def commands(self, command, fatal = True):
65 command = self.get_remote_command(command)
66 return utils.commands(command, fatal, self.config.verbose)
68 def scp(self, src, dest):
70 if 'rootkey' in self and self['rootkey'] is not None:
71 options += " -i %s " % (self['rootkey'])
73 if 'chroot' in self and self['chroot'] is not None:
75 if 'vserver' in self and self['vserver'] is not None:
76 path += '/vservers/%s/' % self['vserver']
79 src_parts = src.split(":")
81 dest_parts = dest.split(":")
83 if len(src_parts) == 1:
85 elif src_parts[0].find('localhost') != -1:
86 src_cmd = path + os.sep + src_parts[1]
88 host, file = src_parts[0], src_parts[1]
89 src_cmd = 'root@%(host)s:%(path)s%(file)s ' % locals()
91 if len(dest_parts) == 1:
93 elif dest_parts[0].find('localhost') != -1:
94 dest_cmd = path +os.sep+ dest_parts[1]
96 host, file = dest_parts[0], dest_parts[1]
97 dest_cmd = 'root@%(host)s:%(path)s%(file)s' % locals()
99 command = 'scp %(options)s %(src_cmd)s %(dest_cmd)s' % locals()
100 if self.config.verbose:
101 utils.header(command)
102 return utils.commands(command)