Beispiel #1
0
def ajax_servers(request):
    """
    获取server数据
    :param request:
    :return:
    """
    if request.method == 'POST':
        data = request.POST
        service = data.get('service', None)
        results = []
        if service and len(service) > 0:
            servers = ZK_HARPC.get_servers(service=service)
            for server in servers:
                server_name = safe_list_get(server, 0, None)
                isOperate = safe_list_get(server, 1, False)

                server_info_dict = ZK_HARPC.get_service_child_info(
                    service=service,
                    type=settings.ZK_SERVERS,
                    child=server_name)

                results.append([
                    server_name,
                    server_info_dict.get('name', None),
                    server_info_dict.get('owner', None),
                    server_info_dict.get('protocol', None),
                    server_info_dict.get('ctime', None), isOperate
                ])

        return JsonResponse({'data': results}, safe=False)
Beispiel #2
0
def ajax_service(request):
    """
    ajax获取serivce数据
    :param request:
    :return:
    """
    if request.method == "POST":
        results = []
        services = ZK_HARPC.get_services()
        for service in services:
            service_name = safe_list_get(service, 0, None)
            isOperate = safe_list_get(service, 1, False)

            servers = ZK_HARPC.get_servers(service_name)
            clients = ZK_HARPC.get_clients(service_name)

            server_list = []
            client_list = []

            for server in servers:
                server_list.append(safe_list_get(server, 0, None))

            for client in clients:
                client_list.append(safe_list_get(client, 0, None))

            results.append([
                service_name, ",".join(server_list), ",".join(client_list),
                isOperate
            ])

    return JsonResponse({'data': results}, safe=False)
Beispiel #3
0
def ajax_service(request):
    """
    ajax获取serivce数据
    :param request:
    :return:
    """
    if request.method == "POST":
        results = []
        services = ZK_HARPC.get_services()
        for service in services:
            service_name = safe_list_get(service, 0, None)
            isOperate = safe_list_get(service, 1, False)

            servers = ZK_HARPC.get_servers(service_name)
            clients = ZK_HARPC.get_clients(service_name)

            server_list = []
            client_list = []

            for server in servers:
                server_list.append(safe_list_get(server, 0, None))

            for client in clients:
                client_list.append(safe_list_get(client, 0, None))

            results.append([service_name, ",".join(server_list), ",".join(client_list), isOperate])

    return JsonResponse({'data': results}, safe=False)
Beispiel #4
0
def ajax_update_server(request):
    """
    跟新一个节点(废弃的方法)
    :param request:
    :return:
    """
    if request.method == 'POST':
        data = request.POST
        service = data.get('service', None)
        servers = data.get('servers', None)

        if (not service
                or not servers) or not (len(service) > 0 and len(servers) > 0):
            return JsonResponse({
                "rc": 0,
                'msg': 'service/servers不得为空'
            },
                                safe=False)

        if not ZK_HARPC.get_service_acl(service):
            return JsonResponse({"rc": 0, 'msg': '您没有操作的权限'}, safe=False)

        server_old_list = []
        server_new_list = servers.split(",")

        servers_olds = ZK_HARPC.get_servers(service)
        for servers_old in servers_olds:
            server_old_name = safe_list_get(servers_old, 0, None)
            if server_old_name:
                server_old_list.append(server_old_name)

        add_servers = [i for i in server_new_list if i not in server_old_list]
        del_servers = [i for i in server_old_list if i not in server_new_list]

        create_result = ZK_HARPC.create_servers(service=service,
                                                servers=add_servers)
        delete_result = ZK_HARPC.delete_servers(service=service,
                                                servers=del_servers)

        if create_result[0] and delete_result[0]:
            return JsonResponse({"rc": 0, 'msg': '更新成功'}, safe=False)
        else:
            return JsonResponse({"rc": 1, 'msg': '跟新失败'}, safe=False)
Beispiel #5
0
def ajax_servers(request):
    """
    获取server数据
    :param request:
    :return:
    """
    if request.method == 'POST':
        data = request.POST
        service = data.get('service', None)
        results = []
        if service and len(service) > 0:
            servers = ZK_HARPC.get_servers(service=service)
            for server in servers:
                server_name = safe_list_get(server, 0, None)
                isOperate = safe_list_get(server, 1, False)

                server_info_dict = ZK_HARPC.get_service_child_info(service=service, type=settings.ZK_SERVERS,
                                                            child=server_name)

                results.append([server_name, server_info_dict.get('name', None), server_info_dict.get('owner', None),
                                server_info_dict.get('protocol', None), server_info_dict.get('ctime', None), isOperate])

        return JsonResponse({'data': results}, safe=False)
Beispiel #6
0
def ajax_update_server(request):
    """
    跟新一个节点(废弃的方法)
    :param request:
    :return:
    """
    if request.method == 'POST':
        data = request.POST
        service = data.get('service', None)
        servers = data.get('servers', None)

        if (not service or not servers) or not (len(service) > 0 and len(servers) > 0):
            return JsonResponse({"rc": 0, 'msg': 'service/servers不得为空'}, safe=False)

        if not ZK_HARPC.get_service_acl(service):
            return JsonResponse({"rc": 0, 'msg': '您没有操作的权限'}, safe=False)

        server_old_list = []
        server_new_list = servers.split(",")

        servers_olds = ZK_HARPC.get_servers(service)
        for servers_old in servers_olds:
            server_old_name = safe_list_get(servers_old, 0, None)
            if server_old_name:
                server_old_list.append(server_old_name)

        add_servers = [i for i in server_new_list if i not in server_old_list]
        del_servers = [i for i in server_old_list if i not in server_new_list]

        create_result = ZK_HARPC.create_servers(service=service, servers=add_servers)
        delete_result = ZK_HARPC.delete_servers(service=service, servers=del_servers)

        if create_result[0] and delete_result[0]:
            return JsonResponse({"rc": 0, 'msg': '更新成功'}, safe=False)
        else:
            return JsonResponse({"rc": 1, 'msg': '跟新失败'}, safe=False)