4 # The RemoteHost class provides methods to do operations on a remote host
7 from SSHLibrary import SSHLibrary
13 def __init__(self, host, user, password, rootdir):
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)
23 self.lib.close_connection()
25 def exec_cmd(self, command):
26 print("Executing command %s on host %s" % (command, self.host))
27 rc = self.lib.execute_command(command, return_rc=True)
30 "remote command failed [{0}] with exit code {1}."
31 "For linux-based vms, Please make sure requiretty is disabled in the /etc/sudoers file".format(
36 def mkdir(self, dir_name):
37 self.exec_cmd("mkdir -p " + dir_name)
39 def copy_file(self, src, dest):
41 print("src is None not copy anything to ", dest)
44 if os.path.exists(src) is False:
45 print("Src file " + src + " was not found")
48 print("Copying %s to %s on %s" % (src, dest, self.host))
49 self.lib.put_file(src, dest)
51 def kill_controller(self):
53 "sudo ps axf | grep karaf | grep -v grep "
54 "| awk '{print \"kill -9 \" $1}' | sudo sh"
57 def start_controller(self, dir_name):
58 self.exec_cmd(dir_name + "/odl/bin/start")