Skip to content

Commit

Permalink
fix: 修复参数逻辑判断错误 #7550
Browse files Browse the repository at this point in the history
  • Loading branch information
guohelu committed Oct 31, 2024
1 parent c96f518 commit 364039d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions gcloud/utils/cmdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,16 @@ def get_filter_business_host_topo(
rules = []
# 根据host_id_str进行精准匹配
if host_id_str:
host_id_list = [int(host_id) for host_id in host_id_str.split(",")]
host_id_list = [int(host_id) for host_id in host_id_str.split(",") if host_id]
rules.extend([{"field": "bk_host_id", "operator": "in", "value": host_id_list}])
# 根据ip_str进行模糊匹配
elif ip_str:
rules.extend([{"field": "bk_host_innerip_v6", "operator": "contains", "value": ip} for ip in ip_str.split(",")])
rules.extend([{"field": "bk_host_innerip", "operator": "contains", "value": ip} for ip in ip_str.split(",")])
rules.extend(
[{"field": "bk_host_innerip_v6", "operator": "contains", "value": ip} for ip in ip_str.split(",") if ip]
)
rules.extend(
[{"field": "bk_host_innerip", "operator": "contains", "value": ip} for ip in ip_str.split(",") if ip]
)
if rules:
params["host_property_filter"] = {"condition": "OR", "rules": rules}

Expand Down
6 changes: 3 additions & 3 deletions pipeline_plugins/cmdb_ip_picker/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ def cmdb_search_host(request, bk_biz_id, bk_supplier_account="", bk_supplier_id=
if settings.ENABLE_IPV6 or settings.ENABLE_GSE_V2:
# IPV6环境下或者开启了GSE 2.0 版本
default_host_fields.append("bk_agent_id")
fields = set(default_host_fields + params_data.get("fields", "[]"))
fields = set(default_host_fields + params_data.get("fields", []))
client = get_client_by_user(request.user.username)

topo_modules_id = set()

start = params_data.get("start", None)
limit = params_data.get("limit", None)
ip_str = params_data.get("ip_str", "")
ip_str = params_data.get("ip_str", None)
host_id_str = params_data.get("host_id_str", None)

# get filter module id
Expand All @@ -115,7 +115,7 @@ 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)

if start and limit:
if start is not None and limit is not None:
raw_host_info_list, count = cmdb.get_filter_business_host_topo(
request.user.username, bk_biz_id, bk_supplier_account, fields, start, limit, ip_str, host_id_str
)
Expand Down

0 comments on commit 364039d

Please sign in to comment.