Migrate Get Requests invocations(libraries)
[integration/test.git] / tools / clustering / cluster-deployer / remote_host.py
1 # remote_host.py
2 #
3 #
4 # The RemoteHost class provides methods to do operations on a remote host
5 #
6
7 from SSHLibrary import SSHLibrary
8
9 import os
10
11
12 class RemoteHost:
13     def __init__(self, host, user, password, rootdir):
14         self.host = host
15         self.user = user
16         self.password = password
17         self.rootdir = rootdir
18         self.lib = SSHLibrary()
19         self.lib.open_connection(self.host)
20         self.lib.login(username=self.user, password=self.password)
21
22     def __del__(self):
23         self.lib.close_connection()
24
25     def exec_cmd(self, command):
26         print "Executing command " + command + " on host " + self.host
27         rc = self.lib.execute_command(command, return_rc=True)
28         if rc[1] != 0:
29             raise Exception('remote command failed [{0}] with exit code {1}.'
30                             'For linux-based vms, Please make sure requiretty is disabled in the /etc/sudoers file'
31                             .format(command, rc))
32
33     def mkdir(self, dir_name):
34         self.exec_cmd("mkdir -p " + dir_name)
35
36     def copy_file(self, src, dest):
37         if src is None:
38             print "src is None not copy anything to " + dest
39             return
40
41         if os.path.exists(src) is False:
42             print "Src file " + src + " was not found"
43             return
44
45         print "Copying " + src + " to " + dest + " on " + self.host
46         self.lib.put_file(src, dest)
47
48     def kill_controller(self):
49         self.exec_cmd("sudo ps axf | grep karaf | grep -v grep "
50                       "| awk '{print \"kill -9 \" $1}' | sudo sh")
51
52     def start_controller(self, dir_name):
53         self.exec_cmd(dir_name + "/odl/bin/start")