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 " + command + " on host " + self.host
27 rc = self.lib.execute_command(command, return_rc=True)
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'
33 def mkdir(self, dir_name):
34 self.exec_cmd("mkdir -p " + dir_name)
36 def copy_file(self, src, dest):
38 print "src is None not copy anything to " + dest
41 if os.path.exists(src) is False:
42 print "Src file " + src + " was not found"
45 print "Copying " + src + " to " + dest + " on " + self.host
46 self.lib.put_file(src, dest)
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")
52 def start_controller(self, dir_name):
53 self.exec_cmd(dir_name + "/odl/bin/start")