Ejemplo n.º 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)})
Ejemplo n.º 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)})
Ejemplo n.º 3
0
def file_upload():
    file = request.files.get("file")
    upload_path = request.form.get("path")
    version = request.form.get("version")
    file_name = file.filename

    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)

    replace_path = "/usr/local/lib/python2.7/dist-packages/irain_park-%s-py2.7.egg%s" % (
        version, upload_path)

    def work(ssh_tunnel, ip, verison):
        ssh_tunnel.exec_command("cd %s;mv %s %s_old" %
                                (replace_path, file_name, file_name))
        sftp = ssh_tunnel.open_sftp()
        sftp.putfo(file, replace_path + "/%s" % file_name, file_size=10248)

    try:
        run_all_arm(ssh, work)
    except Exception as e:
        return json.dumps("restart failuer: %s\n%s" %
                          (e, traceback.format_exc()))
    return json.dumps({"result": 0})
Ejemplo n.º 4
0
def api_disk_usage():
    if "park_name" in request.args:
        current_ip = request.args.get("current_ip")
        conn, _ = frp.get_conn(request.args.get('park_name'))
        ssh, _ = make_tunnel(conn, current_ip)
    else:
        host = request.args.get('hostname')
        port = int(request.args.get('port'))
        ssh, _ = try_login(host=host, port=port)
    usage = disk_usage(ssh)
    return jsonify({"timestamp": int(time.time()), "usage": usage})
Ejemplo n.º 5
0
def all_arm_health_check():
    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:
        j = HealthCheckJob(ssh)
        jobsystem.add_job(j)
        jobsystem.run(j.job_id)
    except Exception, e:
        return json.dumps({"code": 1, "result": str(e)})
Ejemplo n.º 6
0
def api_net_usage():
    if "park_name" in request.args:
        current_ip = request.args.get("current_ip")
        conn, _ = frp.get_conn(request.args.get('park_name'))
        ssh, _ = make_tunnel(conn, current_ip)
    else:
        host = request.args.get('hostname')
        port = int(request.args.get('port'))
        ssh, _ = try_login(host=host, port=port)
    usage = net_inout_bytes(ssh)
    return jsonify({
        "timestamp": int(time.time()),
        "inbound": usage[0],
        "outbound": usage[1]
    })
Ejemplo n.º 7
0
def db_backup():
    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", "v3_db_backup.py")
        j = jobsystem.create_rs_job(ssh, path)
        jobsystem.run(j)
        while not jobsystem.is_finished(j):
            time.sleep(1)
    except Exception, e:
        return json.dumps({"code": 1, "result": str(e)})
Ejemplo n.º 8
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)})