Merge "adding missing example flows"
[integration/test.git] / test / tools / 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 class RemoteHost:
10         def __init__(self, host, user, password, rootdir):
11                 self.host = host
12                 self.user = user
13                 self.password = password
14                 self.rootdir = rootdir
15
16         def exec_cmd(self, command):
17                 print "Executing command " + command + " on host " + self.host
18                 lib = SSHLibrary()
19                 lib.open_connection(self.host)
20                 lib.login(username=self.user,password=self.password)
21                 rc = lib.execute_command(command, return_rc = True)
22                 lib.close_connection()
23                 if rc[1] != 0:
24                    raise Exception('remote command failed [{0}] with exit code {1}'.format(command, rc))
25
26
27         def mkdir(self, dir_name):
28                 self.exec_cmd("mkdir -p " + dir_name)
29
30         def copy_file(self, src, dest):
31             lib = SSHLibrary()
32             lib.open_connection(self.host)
33             lib.login(username=self.user, password=self.password)
34             print "Copying " + src + " to " + dest + " on " + self.host
35             lib.put_file(src, dest)
36             lib.close_connection()
37
38         def kill_controller(self):
39             self.exec_cmd("ps axf | grep karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sh")
40
41         def start_controller(self, dir_name):
42                 self.exec_cmd(dir_name + "/odl/bin/start")