class SlamwaredControl(object): def __init__(self, ip, user, password): self.logflag = "Slamwared Control" self.ls = LogShow(self.logflag) self.ip = ip self.ssh = Ssh(ip, user, password) self.ssh.Connect() def startslamwared(self): self.ls.log_print("system", "start the slamwared on " + str(self.ip)) self.ssh.Exec("systemctl start slamwared") self.ls.log_print("system", "start the slamwared success") def stopslamwared(self): self.ls.log_print("system", "stop the slamwared on " + str(self.ip)) self.ssh.Exec("systemctl stop slamwared") self.ls.log_print("system", "stop the slamwared success") def reloadslamwared(self): self.ls.log_print("system", "reload the slamwared on " + str(self.ip)) self.ssh.Exec("systemctl daemon-reload") self.ls.log_print("system", "reload the slamwared success") def rmstmslog(self): self.ls.log_print("system", "remove the log of stms on " + str(self.ip)) self.ssh.Exec( "if [ -f /home/root/slamware.stms ]; then rm /home/root/slamware.stms fi" ) self.ls.log_print("system", "remove the log of stms success")
def UnSimulator(self): try: ssh = Ssh(self.ip, self.ssh_user, self.ssh_pass) ssh.Connect() ssh.Exec( "mv /etc/sdp_ref_rplidar.json /home/root/sdp_ref_simulator.json " ) ssh.Exec("mv /home/root/sdp_ref.json /etc/sdp_ref_rplidar.json ") ssh.Exec("reboot -n") ssh.Close() self.ls.log_print("system", "[Simulator Mode] switch successful") except: self.ls.log_print("system", '[UnSimulator] wrong')
def TestRealSense(self): try: ssh = Ssh(self.ip, self.ssh_user, self.ssh_pass) ssh.Connect() ssh.Exec( "echo /usr/bin/slamware_console depthcam -c tcp status > testrealsense.sh" ) ssh.Exec("chmod a+x testrealsense.sh") ssh.Exec("./testrealsense.sh | grep Successfully > realsense.log") ssh.Close() sf = Sftp(self.ip) sf.Connect() sf.GetFile("/home/root/realsense.log", ".\\realsense.log") sf.Close() self.ls.log_print("system", "[Test Realsense] - successful ") except: self.ls.log_print("system", "[Test Realsense] - fail to ")
def log_get_systemlog(self, ip, logname): ssh = Ssh(ip, self.user, self.password) ssh.Exec("journalctl > /home/root/system.log") ssh.Close() self.ls.log_print("system", "[getlog] start get log") sf = Sftp(ip) sf.GetFile("/home/root/system.log","log\\"+logname) # sf.GetFile("/home/root/slamware.stms","log\\slamawre.stms") sf.Close()
def GetUnlock(self): try: ssh = Ssh(self.unlock_info['ip'], self.unlock_info['user'], self.unlock_info['pass']) ssh.Connect() self.snunlock = ssh.Exec("cd unlock && ./gen_challenge_token.sh " + self.sn)[2] ssh.Close() self.ls.log_print("system", "[sn-unlock-num] " + self.snunlock) self.data_debug = {'cha-token': self.snunlock} except Exception, e: self.ls.log_print("system", '[sn-unlock] wrong with get sn unlock') raise e
def GetLog(self, logname): try: ssh = Ssh(self.ip, self.ssh_user, self.ssh_pass) ''' while True: try: ssh.Connect() ssh.Exec_noretrun("reboot") print "[getlog] waitting for rebooting to get the log file" break except: print "[getlog] wrong with reboot" time.sleep(3) continue while True: try: ssh.Connect() ssh.Close() print "[getlog] waitting for rebooting to get the log file" break except: print "[getlog] waitting for rebooting to get the log file" time.sleep(3) continue ''' ssh.Connect() ssh.Exec("journalctl > /home/root/system.log") ssh.Close() self.ls.log_print("system", "[getlog] start get log") sf = Sftp(self.ip) sf.Connect() sf.GetFile("/home/root/system.log", "log\\" + logname) # sf.GetFile("/home/root/slamware.stms","log\\slamawre.stms") sf.Close() self.ls.log_print("system", "[getlog] switch successful") except: self.ls.log_print("system", '[UnSimulator] wrong')
class SlamwaredControl(object): def __init__(self): self.class_name = "SlamwaredControl" self.ls = LogShow(self.class_name) self.ssh_flag = False self.sftp_flag = False def __str__(self): return self.class_name def getSSH(self, ipadd, username, password): if isinstance(ipadd, str): self.sship = ipadd self.ip = ipadd else: self.sship = str(ipadd) self.ip = str(ipadd) if isinstance(username, str): self.sshusername = username else: self.sshusername = str(username) if isinstance(password, str): self.sshpassword = password else: self.sshusername = str(password) self.ssh = Ssh(self.sship, self.sshusername, self.sshpassword) self.ssh.Connect() self.ssh_flag = True def getSftp(self, ipadd, username, password): if isinstance(ipadd, str): self.sftpip = ipadd self.ip = ipadd else: self.sftpip = str(ipadd) self.ip = str(ipadd) if isinstance(username, str): self.sftpusername = username else: self.sftpusername = str(username) if isinstance(password, str): self.sftppassword = password else: self.sftppassword = str(password) self.sftp = Sftp(self.sftpip, self.sftpusername, self.sftppassword) self.sftp.Connect() self.sftp_flag = True def startslamwared(self): self.ls.log_print("system", "start the slamwared on " + str(self.ip), self.startslamwared.__name__) self.ssh.Exec("systemctl start slamwared") self.ls.log_print("system", "start the slamwared success", self.startslamwared.__name__) def getstatusSlamwared(self): self.ls.log_print("system", "start get the status", self.getstatusSlamwared.__name__) output = str(self.ssh.Exec('systemctl status slamwared')) self.ls.log_print('system', output, self.getstatusSlamwared.__name__) def stopslamwared(self): self.ls.log_print("system", "stop the slamwared on " + str(self.ip), self.stopslamwared.__name__) self.ssh.Exec("systemctl stop slamwared") self.ls.log_print("system", "stop the slamwared success", self.stopslamwared.__name__) def reloadslamwared(self): self.ls.log_print("system", "reload the slamwared on " + str(self.ip), self.reloadslamwared.__name__) self.ssh.Exec("systemctl daemon-reload") self.ls.log_print("system", "reload the slamwared success", self.reloadslamwared.__name__) def rmstmslog(self): self.ls.log_print("system", "remove the log of stms on " + str(self.ip), self.rmstmslog.__name__) self.ssh.Exec( "if [ -f /home/root/slamware.stms ]; then rm /home/root/slamware.stms fi" ) #| here can using sftp to remove the file self.ls.log_print("system", "remove the log of stms success", self.rmstmslog.__name__) def getmotor(self): self.stopslamwared() motor = str( self.ssh.Exec("slamware_base_console -c slamware-core motor")) self.startslamwared() print motor if "Successfully" in motor: temp = motor.split(",")[7].split(":") left = temp[1].strip().split(" ")[0].split("mm")[0] right = temp[2].strip().split("mm")[0] result_motor = [left, right] else: result_motor = False return result_motor
# result_file_path = "/result_nginx_test" # sftp.GetFile(result_file_path, "./result_nginx_test") # f = open("./result_nginx_test") # test_result = f.readlines() # f.close() # print(test_result) # if "successful" in test_result: # print("nginx test ok") # else: # print("nginx test failed ,please check config file") # sys.exit(1) ''' restart nginx server ''' cmd = "/etc/init.d/nginx restart" test_result_service_restart = ssh.Exec(cmd) if "failed" not in test_result_service_restart: print("nginx restart ok") print("$$$$" + str(ip) + " is ok ") else: print("nginx restart failed") print("$$$$" + str(ip) + " is failed ") sftp.Close()