Пример #1
0
def post():
    form, error = JsonParser(
        Argument('app_id', type=int),
        Argument('env_id', type=int),
        Argument('menu_id', type=int),
        Argument('message', default=''),
        Argument('host_ids', type=list)
    ).parse()
    if error is None:
        pro = App.query.get_or_404(form.app_id)
        env = Environment.query.get_or_404(form.env_id)
        menu = DeployMenu.query.get_or_404(form.menu_id)
        ctr_name = '%s.%s' % (pro.identify, env.identify)
        if menu.position == 2:
            cli = Host.query.get_or_404(form.host_ids[0])
            ctr = Container(cli.docker_uri, ctr_name)
            if menu.display_type == 2:
                exec_code, _ = ctr.exec_command_with_base64(menu.command, form.message, with_exit_code=True)
                return json_response(exec_code)
            elif menu.display_type == 1:
                token = uuid.uuid4().hex
                queue = QueuePool.make_queue(token, 1)
                queue.containers = [ctr]
                Thread(target=do_exec_with_stream,
                       args=(token, ctr, menu.command, form.message, 10 * 60)).start()
                return json_response(token)
        # 发布区自定义菜单只允许通知成功与否,固无需判断display_type
        elif menu.position == 1:
            token = uuid.uuid4().hex
            hosts = Host.query.filter(Host.id.in_(form.host_ids)).all()
            queue = QueuePool.make_queue(token, len(hosts))
            for cli in hosts:
                ctr = Container(cli.docker_uri, ctr_name)
                Thread(target=do_exec, args=(queue, ctr, cli.name, menu.command, form.message)).start()
            return json_response({'token': token, 'data': [{'name': x.name} for x in hosts]})
Пример #2
0
def kill_job():
    form, error = JsonParser(
        'job_schedule_name',
        'kill_user',
        'hosts_id',
        'id',
        Argument('command',
                 type=str,
                 default='bash /tensorflow/arena_stop/arena_job_kill.sh',
                 required=False),
    ).parse()
    print("hosts_id" + str(form.hosts_id) + "  command:" + form.command)
    # 这里操作是ssh后初始化环境变量
    new_command = "source /etc/profile &&. /etc/profile && " + form.command + " " + form.kill_user + " " + form.job_schedule_name + " " + str(
        form.id)
    if error is None:
        ip_list = Host.query.filter(Host.id.in_(tuple(form.hosts_id))).all()
        token = uuid.uuid4().hex
        q = QueuePool.make_queue(token, len(ip_list))
        for h in ip_list:
            print(h.ssh_ip)
            Thread(target=hosts_exec,
                   args=(q, h.ssh_ip, 'ad_user', h.ssh_port,
                         new_command)).start()
        return json_response(token)
    return json_response(message=error)
Пример #3
0
def exec_host_command():
    form, error = JsonParser('hosts_id', 'command').parse()
    if error is None:
        ip_list = Host.query.filter(Host.id.in_(tuple(form.hosts_id))).all()
        token = uuid.uuid4().hex
        q = QueuePool.make_queue(token, len(ip_list))
        for h in ip_list:
            Thread(target=hosts_exec, args=(q, h.ssh_ip, h.ssh_port, form.command)).start()
        return json_response(token)
    return json_response(message=error)
Пример #4
0
def app_update():
    form, error = JsonParser(Argument('app_id', type=int),
                             Argument('env_id', type=int),
                             Argument('deploy_message', default=''),
                             Argument('deploy_restart', type=bool),
                             Argument('host_ids', type=list)).parse()
    if error is None:
        if not g.user.check_deploy_permission(form.env_id, form.app_id):
            return json_response(message='Permission denied'), 403
        token = uuid.uuid4().hex
        q = QueuePool.make_queue(token, len(form.host_ids))
        for host_id in form.pop('host_ids'):
            Thread(target=do_update, args=(q, form, host_id)).start()
        return json_response(token)
    return json_response(message=error)
Пример #5
0
def exec_host_command():
    form, error = JsonParser('hosts_id', 'command').parse()
    print("hosts_id" + form.hosts_id + "  command:" + form.command)
    #这里操作是ssh后初始化环境变量
    new_command = "source /etc/profile &&. /etc/profile && " + form.command
    if error is None:
        ip_list = Host.query.filter(Host.id.in_(tuple(form.hosts_id))).all()
        token = uuid.uuid4().hex
        q = QueuePool.make_queue(token, len(ip_list))
        for h in ip_list:
            print(h.ssh_ip)
            Thread(target=hosts_exec,
                   args=(q, h.ssh_ip, 'ad_user', h.ssh_port,
                         new_command)).start()
        return json_response(token)
    return json_response(message=error)