Example #1
0
File: host.py Project: zkydrx/spug
def get_valid(host_id):
    cli = Host.query.get_or_404(host_id)
    if not Setting.has('ssh_private_key'):
        utils.generate_and_save_ssh_key()
    if ssh.ssh_ping(cli.ssh_ip, cli.ssh_port):
        try:
            sync_host_info(host_id, cli.docker_uri)
        except DockerException:
            return json_response(message='docker fail')
    else:
        return json_response(message='ssh fail')
    return json_response()
Example #2
0
File: host.py Project: zkydrx/spug
def post_valid(host_id):
    form, error = JsonParser(Argument('secret', help='请输入root用户的密码!')).parse()
    if error is None:
        cli = Host.query.get_or_404(host_id)
        ssh.add_public_key(cli.ssh_ip, cli.ssh_port, form.secret)
        if ssh.ssh_ping(cli.ssh_ip, cli.ssh_port):
            try:
                sync_host_info(host_id, cli.docker_uri)
            except DockerException:
                return json_response(message='获取扩展信息失败,请检查docker是否可以正常连接!')
        else:
            return json_response(message='验证失败!')
    return json_response(message=error)