diff --git a/apps/backend/subscription/tools.py b/apps/backend/subscription/tools.py index 00b848ac6..141a39e1c 100644 --- a/apps/backend/subscription/tools.py +++ b/apps/backend/subscription/tools.py @@ -989,53 +989,17 @@ def get_instances_by_scope(scope: Dict[str, Union[Dict, int, Any]]) -> Dict[str, conditions = [] for cond_info in res["info"]["condition"] + res["info"]["variable_condition"]: conditions += cond_info["condition"] - conditions = [ - cond - for cond_info in res["info"]["condition"] + res["info"]["variable_condition"] - for cond in cond_info["condition"] - ] if res["bk_obj_id"] == "host": host_condition.extend(conditions) elif res["bk_obj_id"] == "set": - # 使用字典映射来替换运算符 operator_mapping = {"$in": "in", "$nin": "not_in", "$regex": "contains"} for condition in conditions: condition["operator"] = operator_mapping.get(condition["operator"], condition["operator"]) set_condition.extend(conditions) - # set_infos = CCApi.search_set_v2( - # params={ - # "filter": { - # "condition": "AND", - # "rules": conditions - # } - # }, - # format_kwargs={ - # "bk_supplier_account": "0", - # "bk_biz_id": node["bk_biz_id"], - # } - # )["info"] - # - # instances.extend( - # [ - # {"host": inst} - # for inst in get_host_detail_by_template( - # bk_obj_id=models.Subscription.NodeType.DYNAMIC_GROUP, - # template_info_list=[ - # { - # "bk_set_id": set_info["bk_set_id"], - # "bk_inst_id": set_info["set_template_id"], - # } - # for set_info in set_infos - # ], - # bk_biz_id=bk_biz_id - # ) - # ] - # ) - if host_condition: res = CCApi.post_findmany_hosts_search_with_biz( { diff --git a/test.py b/test.py new file mode 100644 index 000000000..29e7497fd --- /dev/null +++ b/test.py @@ -0,0 +1,26 @@ +import os +import django + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") +django.setup() + +from apps.backend.subscription.tools import get_instances_by_scope + +scope = { + "bk_biz_id": None, + "object_type": "HOST", + "node_type": "DYNAMIC_GROUP", + "nodes": [ + { + "bk_biz_id": 5, + "bk_group_id": "544a9026-b2b4-11ef-9ead-fa9249cab81d", + } + ], + "need_register": False, + "instance_selector": None, + "with_info": { + "process": False + } +} + +get_instances_by_scope(scope=scope) diff --git a/test2.py b/test2.py new file mode 100644 index 000000000..8e79cfd85 --- /dev/null +++ b/test2.py @@ -0,0 +1,132 @@ +import os +import django + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") +django.setup() + +from apps.backend.subscription.tools import get_instances_by_scope + +scope = { + "bk_biz_id": None, + "object_type": "HOST", + "node_type": "INSTANCE", + "nodes": [ + { + "bk_biz_id": 1, + "bk_host_id": 205, + "ip": None + }, + { + "bk_biz_id": 1, + "bk_host_id": 210, + "ip": None + }, + { + "bk_biz_id": 1, + "bk_host_id": 212, + "ip": None + }, + { + "bk_biz_id": 1, + "bk_host_id": 213, + "ip": None + }, + { + "bk_biz_id": 1, + "bk_host_id": 214, + "ip": None + }, + { + "bk_biz_id": 1, + "bk_host_id": 216, + "ip": None + }, + { + "bk_biz_id": 1, + "bk_host_id": 221, + "ip": None + }, + { + "bk_biz_id": 1, + "bk_host_id": 223, + "ip": None + }, + { + "bk_biz_id": 1, + "bk_host_id": 224, + "ip": None + }, + { + "bk_biz_id": 5, + "bk_host_id": 240, + "ip": None + }, + { + "bk_biz_id": 5, + "bk_host_id": 313, + "ip": None + }, + { + "bk_biz_id": 1, + "bk_host_id": 388, + "ip": None + }, + { + "bk_biz_id": 5, + "bk_host_id": 389, + "ip": None + }, + { + "bk_biz_id": 1, + "bk_host_id": 431, + "ip": None + }, + { + "bk_biz_id": 5, + "bk_host_id": 458, + "ip": None + }, + { + "bk_biz_id": 5, + "bk_host_id": 459, + "ip": None + }, + { + "bk_biz_id": 5, + "bk_host_id": 481, + "ip": None + }, + { + "bk_biz_id": 5, + "bk_host_id": 482, + "ip": None + }, + { + "bk_biz_id": 5, + "bk_host_id": 484, + "ip": None + }, + { + "bk_biz_id": 5, + "bk_host_id": 485, + "ip": None + }, + { + "bk_biz_id": 5, + "bk_host_id": 487, + "ip": None + }, + { + "bk_biz_id": 5, + "bk_host_id": 488, + "ip": None + } + ], + "need_register": False, + "instance_selector": None, + "with_info": { + "process": False + } +} + +get_instances_by_scope(scope=scope) diff --git a/test3.py b/test3.py new file mode 100644 index 000000000..75e6ee4b1 --- /dev/null +++ b/test3.py @@ -0,0 +1,30 @@ +import os +import django + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") +django.setup() + +from apps.backend.subscription.tools import get_instances_by_scope + +scope = { + "bk_biz_id": 5, + "object_type": "HOST", + "node_type": "DYNAMIC_GROUP", + "nodes": [ + { + "bk_biz_id": 5, + "bk_group_id": "416454dc-b2db-11ef-9ead-fa9249cab81d", + }, + { + "bk_biz_id": 5, + "bk_group_id": "717017fc-b2b4-11ef-9ead-fa9249cab81d", + } + ], + "need_register": False, + "instance_selector": None, + "with_info": { + "process": False + } +} + +get_instances_by_scope(scope=scope) diff --git a/test4.py b/test4.py new file mode 100644 index 000000000..bd6b3c0f9 --- /dev/null +++ b/test4.py @@ -0,0 +1,30 @@ +import os +import django + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") +django.setup() + +from apps.backend.subscription.tools import get_instances_by_scope + +scope = { + "bk_biz_id": 5, + "object_type": "HOST", + "node_type": "DYNAMIC_GROUP", + "nodes": [ + { + "bk_biz_id": 5, + "bk_group_id": "416454dc-b2db-11ef-9ead-fa9249cab81d", + }, + { + "bk_biz_id": 5, + "bk_group_id": "544a9026-b2b4-11ef-9ead-fa9249cab81d", + } + ], + "need_register": False, + "instance_selector": None, + "with_info": { + "process": False + } +} + +get_instances_by_scope(scope=scope)