示例#1
0
def inside_records_export():
    if "park_name" in request.form:
        park_name = request.form.get("park_name")
        ssh = frp.get_conn(conn_name=park_name)
    else:
        host = request.form.get('hostname')
        port = int(request.form.get('port'))
        ssh, _ = try_login(host=host, port=port)
    end_time = str(request.form.get('end_time'))
    try:
        path = os.path.join(
            os.path.dirname(
                os.path.dirname(os.path.dirname(os.path.dirname(__file__)))),
            "static", "scripts", "inside_records_export.py")
        job = RemoteScriptJob(ssh, path)
        job.run((end_time, ))

        for out_put in job.read_all():
            if "FilePath" in out_put.str:
                f_path = out_put.str[10:]
                sftp = ssh.open_sftp()
                tool_run_time = time.strftime('%Y%m%d_%H%M%S',
                                              time.localtime())
                l_path = 'static/download/inside_records_%s.xlsx' % str(
                    tool_run_time)
                sftp.get(f_path, l_path)
                return json.dumps({"result": 0, "download_url": l_path})
        return json.dumps({"result": 1})
    except Exception as e:
        return json.dumps({"result": str(e)})
示例#2
0
def api_all_arm_restart():
    if "park_name" in request.form:
        park_name = request.form.get("park_name")
        ssh, _ = frp.get_conn(conn_name=park_name)
        if "current_ip" in request.form:
            current_ip = request.form.get("current_ip")
            ssh, _ = make_tunnel(ssh, current_ip)
            _, stdout, _ = ssh.exec_command("cd /home/park;sh restart.sh")
            return json.dumps({"result": 0})
    else:
        host = request.form.get('hostname')
        port = int(request.form.get('port'))
        ssh, _ = try_login(host=host, port=port)
    try:
        path = os.path.join(
            os.path.dirname(
                os.path.dirname(os.path.dirname(os.path.dirname(__file__)))),
            "static", "scripts", "all_arm_restart.py")
        job = RemoteScriptJob(ssh, path)
        job.run()

        for out_put in job.read_all():
            if "success" in out_put.str:
                return json.dumps({"result": 0})
        return json.dumps({"result": 1})
    except Exception as e:
        return json.dumps({"result": str(e)})
示例#3
0
def _v3(client, p_name):
    j = RemoteScriptJob(client, 'static/scripts/3500bugfix.py')
    j.run()
    for output in j.read_all():
        if output.str == 'ok':
            print p_name, ' is ok'
            return
    print p_name, ' is wrong'
示例#4
0
def get_mysql_addr(ssh_client):
    """
    :param ssh_client:
    :return:
        ('192.168.55.248', 3306)
    """
    j = RemoteScriptJob(ssh_client, 'static/scripts/get_mysql_addr.py')
    j.run()
    for log in j.read_all():
        addr = log.str.strip().split(' ')
        return addr[0], int(addr[1])
示例#5
0
    def task(ssh_client, ip, version):
        inner_j = RemoteScriptJob(ssh_client, 'static/scripts/llrp_info.py')
        inner_j.run()

        logs = []
        for j_log in inner_j.read_all():
            if j_log.log_type == LogType.INFO:
                logs.append(j_log.str.decode('utf-8'))

        safe_log('%s %s:%s' % (info['name'], ip, u';'.join(logs)))
        all_task.remove(info['name'])
        ssh_client.close()
示例#6
0
    def _get_all_arm(self):
        j = RemoteScriptJob(self.ssh_client, 'static/scripts/get_all_arm_ip.py')
        jobsystem.add_job(j)
        jobsystem.run(j.job_id)
        output = []

        for j_log in j.read_all():
            msg = j_log.str.strip()
            if msg != '':
                output.append(msg)

        return output
示例#7
0
 def work():
     try:
         print 'trying ', info['name'], ' ', ip
         inner_j = RemoteScriptJob(ssh_client,
                                   'static/scripts/llrp_install.py')
         inner_j.run()
         for j_log in inner_j.read_all():
             if j_log.log_type == LogType.INFO:
                 pass
         ssh_client.close()
     except Exception, err:
         print info['name'], ' ', ip, str(err), traceback.format_exc()
示例#8
0
def get_all_terminal_ip(ssh_client):
    """
        :param ssh_client:
        :return:
            ('192.168.55.248', 3306)
        """
    j = RemoteScriptJob(ssh_client, 'static/scripts/get_all_arm_ip.py')
    j.run()

    all_terminal = []
    for log in j.read_all():
        all_terminal.append(log.str.strip())
    return all_terminal
示例#9
0
    def _do_check(self, arm_ip):
        chan = self._client.get_transport().open_channel(
            'direct-tcpip', (arm_ip, 22), ('localhost', 44444))
        c = paramiko.SSHClient()
        c.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
        c.connect(None, username='******', password='******', sock=chan)

        j = RemoteScriptJob(c, 'static/scripts/v3_health_check.py')
        jobsystem.add_job(j)
        jobsystem.run(j.job_id)
        while j.status != JobStatus.STOPPED or j.readable():
            log = j.get_new_log()
            if log.log_type != LogType.START and log.log_type != LogType.END:
                log.progress = self._p
                self._info(log)
示例#10
0
    def _get_all_arms(self):
        if self._all_arms:
            return self._all_arms

        j = RemoteScriptJob(self._client, 'static/scripts/get_all_arm_ip.py')
        jobsystem.add_job(j)
        jobsystem.run(j.job_id)
        output = []

        while j.status != JobStatus.STOPPED or j.readable():
            msg = j.get_new_log().str.strip()
            if msg != '':
                output.append(msg)

        return output
示例#11
0
def api_get_arm_ip_list():
    park_name = request.args.get("park_name")
    try:
        conn, version = frp.get_conn(park_name)
        if version == 3:
            path = os.path.join('static', 'scripts', 'get_all_arm_ip.py')
            job = RemoteScriptJob(conn, path)
            job.run()
            ip_list = []

            for out_put in job.read_all():
                if out_put.log_type == LogType.INFO:
                    ip_list.append(out_put.str.strip())
            return json.dumps({"result": ip_list})
        else:
            return json.dumps({"code": 1, "result": u'不支持v2车场'})
    except Exception as e:
        return json.dumps({"result": str(e)})
示例#12
0
def extend_auth_time():
    if "park_name" in request.form:
        park_name = request.form.get("park_name")
        ssh = frp.get_conn(conn_name=park_name)
    else:
        host = request.form.get('hostname')
        port = int(request.form.get('port'))
        ssh, _ = try_login(host=host, port=port)
    try:
        path = os.path.join(
            os.path.dirname(
                os.path.dirname(os.path.dirname(os.path.dirname(__file__)))),
            "static", "scripts", "set_more_validity_time.py")
        job = RemoteScriptJob(ssh, path)
        jobsystem.run(job)

        for out_put in job.read_all():
            if "success" in out_put.str:
                return json.dumps({"result": 0})
        return json.dumps({"result": 1})
    except Exception as e:
        return json.dumps({"result": str(e)})
示例#13
0
def get_local_ip(ssh_client):
    j = RemoteScriptJob(ssh_client, 'static/scripts/get_local_ip.py')
    j.run()
    for log in j.read_all():
        return log.str.strip()
示例#14
0
def run_script(client, script_path, args=()):
    j = RemoteScriptJob(client, script_path)
    j.run(args)
    return j.read_all()