Пример #1
0
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 __init__(self, ip):
     self.func_name = "GetSysInfo"
     self.ls = LogShow(self.func_name)
     self.ip = ip
     self.user = "******"
     self.password = "******"
     self.ssh = Ssh(self.ip, self.user, self.password)
Пример #3
0
 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
Пример #5
0
    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 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')
 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 ")
Пример #9
0
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
Пример #10
0
 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()
class GetSysInfo(object):
    def __init__(self, ip):
        self.func_name = "GetSysInfo"
        self.ls = LogShow(self.func_name)
        self.ip = ip
        self.user = "******"
        self.password = "******"
        self.ssh = Ssh(self.ip, self.user, self.password)

    def __str__(self, ip):
        return self.func_name

    def getTopInfo(self):
        try:
            while True:
                try:
                    self.ssh.Connect()
                    self.data_slamwared = {}
                    tempx_slamwared = self.ssh.Exec_system("pidof slamwared")
                    if len(tempx_slamwared) > 0:
                        self.pidofslamwared = tempx_slamwared[0].replace(
                            "\n", "")
                    else:
                        continue
                    tempx_agent = self.ssh.Exec_system("pidof slamware_agent")
                    if len(tempx_agent) > 0:
                        self.pidofslamware_agent = tempx_agent[0].replace(
                            "\n", "")
                    else:
                        continue
                    out = self.ssh.Exec_system("top -n1 | grep " +
                                               str(self.pidofslamwared))
                    out_1 = self.ssh.Exec_system("top -n1 | grep " +
                                                 str(self.pidofslamware_agent))
                    if len(out) > 0:
                        self.slamwared_info = str(out[0]).replace("\n", "")
                    else:
                        continue

                    if len(self.slamwared_info) > 0:
                        self.data_slamwared[
                            "slamwared"] = self.slamwared_info.split(" ")
                    else:
                        continue
                    self.data_slamwared[
                        "origin_slamwared"] = self.slamwared_info

                    if len(out_1) > 0:
                        self.slamware_agent_info = str(out_1[0]).replace(
                            "\n", "")
                    else:
                        continue
                    if len(self.slamware_agent_info) > 0:
                        self.data_slamwared[
                            "slamware_agent"] = self.slamware_agent_info.split(
                                " ")
                    else:
                        continue

                    self.data_slamwared[
                        "origin_slamware_agent"] = self.slamware_agent_info
                    return self.data_slamwared
                except Exception, e:
                    continue
        except Exception, e:
            self.ls.log_print("error", str(e))
Пример #12
0
import time,datetime,sys

from SSH import Ssh
from Sftp import Sftp
from getDate import getDate

#ip = "10.16.1.1"
ip = "10.16.1.1"
user = "******"
passwd = "password"


sftp = Sftp(ip, username=user, password=passwd)

ssh = Ssh(ip,username=user,password=passwd)

#ssh.Exec_noreturn("./serial2tcp --config config.json")

'''
back sorce file
'''
source_path_nginx = "/etc/nginx/sites-available/demo.nginx.conf"

localname = "/home/royzou/backup/nginx/backup/" + getDate.getdatetoday()

sftp.GetFile(source_path_nginx, localname)


'''
update config file
'''