move some logic out of get_remote_command to more general call get_command.
authorTony Mack <tmack@cs.princeton.edu>
Wed, 2 Apr 2008 23:06:01 +0000 (23:06 +0000)
committerTony Mack <tmack@cs.princeton.edu>
Wed, 2 Apr 2008 23:06:01 +0000 (23:06 +0000)
qaapi/qa/Remote.py

index c9d36f6..67ebb4c 100644 (file)
@@ -3,36 +3,53 @@ import os
 
 class Remote:
 
-    def get_remote_command(self, command):
-       if 'chroot' in self and self['chroot']:
-           command = " chroot %s %s" % (self['chroot'], command)
-       if 'vserver' in self and self['vserver']:
+    def get_command(self, command):
+       options = ""
+       # Chroot if necessary 
+        if 'chroot' in self and self['chroot']:
+            command = " chroot %s %s" % (self['chroot'], command)
+
+        # Execute vserver exec if necessary
+        if 'vserver' in self and self['vserver']:
             command = " vserver %s exec %s " % (self['vserver'], command)
-        if 'host' in self and self['host'] not in ['localhost', self.config.hostname]:
-            options = ""
-            if 'rootkey' in self and self['rootkey']:
-                options = "-i %s " % self['rootkey']
-            command = "ssh %s root@%s \"%s\" " % (options, self['host'], command)      
        
+       # Use root key if necessary     
+       if 'host' in self and self['host'] not in ['localhost', self.config.hostname]:
+            if 'rootkey' in self and self['rootkey']:
+                options +=  " -i %s " % self['rootkey']
+
+       return (command, options)
+
+    def get_host_command(self, command):
+        (command, options) = self.get_command(command)
+        if 'host' in self and self['host'] not in ['localhost', self.config.hostname]:
+            command = "ssh %s root@%s \"%s\" " % (options, self['host'], command)
        return command
 
+    def get_remote_command(self, command):
+       (command, options) = self.get_command(command)
+       if 'type' in self and self['type'] in ['vm']:
+            if 'redir_port' in self and self['redir_port']:
+                options += " -p %s " % self['redir_port']      
+       
+       # attempt ssh self['host'] is not the machine we are running on or
+       # if this is a virtual node 
+       if 'host' in self and self['host'] not in ['localhost', self.config.hostname] or \
+          'type' in self and self['type'] in ['vm']:
+            command = "ssh %s root@%s \"%s\" " % (options, self['host'], command)
+       return command 
+
     def popen(self, command, fatal = True):
        command = self.get_remote_command(command)
-       if self.config.verbose:
-           utils.header(command)
-       return utils.popen(command, fatal)
+       return utils.popen(command, fatal, self.config.verbose)
 
     def popen3(self, command):
        command = self.get_remote_command(command)
-       if self.config.verbose:
-           utils.header(command)
-       return utils.popen3(command) 
+       return utils.popen3(command, self.config.verbose) 
 
     def commands(self, command, fatal = True):
        command = self.get_remote_command(command) 
-        if self.config.verbose:
-           utils.header(command)
-       return utils.commands(command, fatal)
+       return utils.commands(command, fatal, self.config.verbose)
 
     def scp(self, src, dest):
        options = ""