def ajax_delete(request): """ 删除创建的节点 :param request: :return: """ if request.method == 'POST': data = request.POST service = data.get('service', None) server = data.get('server', None) if not ZK_HARPC.get_service_acl(service): return JsonResponse({ "rc": 1, 'msg': '您没有操作%s的权限' % (service) }, safe=False) if service and len(service) > 0: if server and len(server) > 0: result = ZK_HARPC.delete_server(service=service, server=server) else: result = ZK_HARPC.delete_service(service=service) if result[0]: return JsonResponse({ "rc": 0, 'msg': '删除成功,请刷新页面查看结果' }, safe=False) else: return JsonResponse({"rc": 1, 'msg': '删除失败'}, safe=False) else: return JsonResponse({"rc": 1, 'msg': 'service不得为空'}, safe=False)
def ajax_delete(request): """ 删除创建的节点 :param request: :return: """ if request.method == 'POST': data = request.POST service = data.get('service', None) server = data.get('server', None) if not ZK_HARPC.get_service_acl(service): return JsonResponse({"rc": 1, 'msg': '您没有操作%s的权限' % (service)}, safe=False) if service and len(service) > 0: if server and len(server) > 0: result = ZK_HARPC.delete_server(service=service, server=server) else: result = ZK_HARPC.delete_service(service=service) if result[0]: return JsonResponse({"rc": 0, 'msg': '删除成功,请刷新页面查看结果'}, safe=False) else: return JsonResponse({"rc": 1, 'msg': '删除失败'}, safe=False) else: return JsonResponse({"rc": 1, 'msg': 'service不得为空'}, safe=False)
def child(request): if request.method == 'GET': data = request.GET service = data.get('service', None) isExists = False if service and len(service) > 0: isExists = ZK_HARPC.service_exist(service=service) isOperate = ZK_HARPC.get_service_acl(service=service) if not isExists: services = ZK_HARPC.get_services() else: servers_total = ZK_HARPC.get_servers_total(service) clients_total = ZK_HARPC.get_clients_total(service) return render_to_response("child.html", locals(), RequestContext(request))
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)
def servers(request): """ servers页面 :param request: :return: """ if request.method == 'GET': data = request.GET service = data.get('service', None) isExists = False if service and len(service) > 0: isExists = ZK_HARPC.service_exist(service=service) isOperate = ZK_HARPC.get_service_acl(service=service) if not isExists: services = ZK_HARPC.get_services() return render_to_response("servers.html", locals(), RequestContext(request))
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)