- Added Node, Site, Slice, Person, and PLC classes useful for defining a default...
[tests.git] / qaapi / qa / Remote.py
1 import utils
2
3 class Remote:
4
5     def get_remote_command(self, command):
6         if 'chroot' in self and self['chroot']:
7             command = " chroot %s %s" % (self['chroot'], command)
8         if 'vserver' in self and self['vserver']:
9             command = " vserver %s exec '%s' " % (self['vserver'], command)
10         if 'host' in self and self['host'] not in ['localhost']:
11             options = ""
12             if 'rootkey' in self and self['rootkey']:
13                 options = "-i %s " % self['rootkey']
14             command = "ssh %s root@%s \"%s\" " % (options, self['host'], command)       
15         
16         return command
17
18     def popen(self, command, fatal = True):
19         command = self.get_remote_command(command)
20         #utils.header(command)
21         return utils.popen(command, fatal)
22
23     def commands(self, command, fatal = True):
24         command = self.get_remote_command(command) 
25         #utils.header(command)
26         return utils.commands(command, fatal)
27
28     def scp(self, src, dest):
29         options = "" 
30         if 'rootkey' in self and self['rootkey'] is not None:
31              options += " -i %s " % (self['rootkey']) 
32         path = ""
33         if 'chroot' in self and self['chroot'] is not None:
34             path += "/plc/root/"
35         if 'vserver' in self and self['vserver'] is not None:
36             path += '/vservers/%s/' % self['vserver']           
37
38         src_cmd = ""
39         src_parts = src.split(":")
40         dest_cmd = ""
41         dest_parts = dest.split(":")
42         command = "scp "
43         if len(src_parts) == 1:
44             src_cmd = src
45         elif src_parts[0].find('localhost')  != -1: 
46             src_cmd = src_parts[1]
47         else:
48             host, file  = src_parts[0], src_parts[1]
49             src_cmd = 'root@%(host)s:%(path)s%(file)s ' % locals()
50
51         if len(dest_parts) == 1:
52             dest_cmd = dest
53         elif dest_parts[0].find('localhost') != -1:
54             dest_cmd = dest_parts[1]
55         else:
56             host, file = dest_parts[0], dest_parts[1]
57             dest_cmd = 'root@%(host)s:%(path)s%(file)s'  % locals()
58
59         print dest_parts
60         command = 'scp %(options)s %(src_cmd)s %(dest_cmd)s' % locals()
61         utils.header(command)
62         return utils.commands(command)      
63