Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复参数逻辑判断错误 #7550 #7597

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
guohelu marked this conversation as resolved.
Show resolved Hide resolved
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
Loading