From 44561514de446f0c4ca42b2f3b748a4ef8f84637 Mon Sep 17 00:00:00 2001 From: guohelu <19503896967@163.com> Date: Tue, 15 Oct 2024 18:32:05 +0800 Subject: [PATCH] perf:Added paging function for IP list --- .pre-commit-config.yaml | 11 ----------- gcloud/utils/cmdb.py | 11 +++++++++-- pipeline_plugins/cmdb_ip_picker/query.py | 9 ++++++++- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 196ed9ed72..0851268fca 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,14 +24,3 @@ repos: - id: commitlint stages: [commit-msg] additional_dependencies: ['@commitlint/config-conventional'] - - repo: local - hooks: - - id: check-migrate - name: check migrate - entry: python scripts/check_migrate/check_migrate.py - language: system - types: [python] - - id: check-sensitive-info - name: Check Sensitive Info - entry: sh scripts/check_sensitive_info.sh - language: system diff --git a/gcloud/utils/cmdb.py b/gcloud/utils/cmdb.py index 4d54bb2194..4a7dd58e07 100644 --- a/gcloud/utils/cmdb.py +++ b/gcloud/utils/cmdb.py @@ -25,7 +25,9 @@ get_client_by_user = settings.ESB_GET_CLIENT_BY_USER -def get_business_host_topo(username, bk_biz_id, supplier_account, host_fields, ip_list=None, property_filters=None): +def get_business_host_topo( + username, bk_biz_id, supplier_account, host_fields, ip_list=None, property_filters=None, page=None +): """获取业务下所有主机信息 :param username: 请求用户名 :type username: str @@ -76,7 +78,12 @@ def get_business_host_topo(username, bk_biz_id, supplier_account, host_fields, i "rules": [{"field": "bk_host_innerip", "operator": "in", "value": ip_list}], } - result = batch_request(client.cc.list_biz_hosts_topo, kwargs) + if page: + kwargs["page"] = page + data = client.cc.list_biz_hosts_topo(kwargs) + result = data["data"]["info"] + else: + result = batch_request(client.cc.list_biz_hosts_topo, kwargs) host_info_list = [] for host_topo in result: diff --git a/pipeline_plugins/cmdb_ip_picker/query.py b/pipeline_plugins/cmdb_ip_picker/query.py index a09275b650..bf9d444995 100644 --- a/pipeline_plugins/cmdb_ip_picker/query.py +++ b/pipeline_plugins/cmdb_ip_picker/query.py @@ -84,6 +84,11 @@ def cmdb_search_host(request, bk_biz_id, bk_supplier_account="", bk_supplier_id= client = get_client_by_user(request.user.username) topo_modules_id = set() + page = { + "start": int(request.GET.get("start", 0)), + "limit": int(request.GET.get("limit", 10)), + } + ip_list = json.loads(request.GET.get("ip_list", "[]")) # get filter module id if request.GET.get("topo", None): @@ -109,7 +114,9 @@ def cmdb_search_host(request, bk_biz_id, bk_supplier_account="", bk_supplier_id= result = {"result": False, "code": ERROR_CODES.API_GSE_ERROR, "message": message} return JsonResponse(result) - raw_host_info_list = cmdb.get_business_host_topo(request.user.username, bk_biz_id, bk_supplier_account, fields) + raw_host_info_list = cmdb.get_business_host_topo( + request.user.username, bk_biz_id, bk_supplier_account, fields, ip_list=ip_list, page=page + ) # map cloud_area_id to cloud_area cloud_area_dict = {}