4 # The RemoteHost class provides methods to do operations on a remote host
7 from SSHLibrary import SSHLibrary
11 def __init__(self, host, user, password, rootdir):
14 self.password = password
15 self.rootdir = rootdir
17 def exec_cmd(self, command):
18 print "Executing command " + command + " on host " + self.host
20 lib.open_connection(self.host)
21 lib.login(username=self.user, password=self.password)
22 rc = lib.execute_command(command, return_rc=True)
23 lib.close_connection()
25 raise Exception('remote command failed [{0}] with exit code {1}'.format(command, rc))
27 def mkdir(self, dir_name):
28 self.exec_cmd("mkdir -p " + dir_name)
30 def copy_file(self, src, dest):
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()
38 def kill_controller(self):
39 self.exec_cmd("ps axf | grep karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sh")
41 def start_controller(self, dir_name):
42 self.exec_cmd(dir_name + "/odl/bin/start")