-
Notifications
You must be signed in to change notification settings - Fork 55
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
feature: 订阅支持按操作系统等主机属性进行范围筛选(closed #1452) #1619
feature: 订阅支持按操作系统等主机属性进行范围筛选(closed #1452) #1619
Conversation
Codecov Report
@@ Coverage Diff @@
## v2.3.2-dev #1619 +/- ##
===============================================
- Coverage 73.42% 36.84% -36.59%
===============================================
Files 389 308 -81
Lines 26244 21452 -4792
===============================================
- Hits 19270 7904 -11366
- Misses 6974 13548 +6574
|
c280abd
to
ef894d8
Compare
apps/node_man/serializers/base.py
Outdated
@@ -45,8 +45,17 @@ def validate(self, data): | |||
return data | |||
|
|||
|
|||
# 订阅任务范围主机属性筛选 | |||
class SubscriptionScopeInstanceSelectorSerializer(serializers.Serializer): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里考虑缩写?
SubScopeInstSelectorSerializer
@@ -21,12 +21,20 @@ | |||
from apps.utils import basic | |||
|
|||
|
|||
class SubscriptionScopeInstanceSelectorSerializer(serializers.Serializer): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
与 apps/node_man/serializers/base.py
中新增的是同一个序列化器,可统一为同一个,订阅偏向后台动作,可以保留此处
apps/backend/subscription/tools.py
Outdated
instances_dict[create_node_id(data)] = instance | ||
|
||
# 对 instances 进行二次过滤 | ||
if scope.get("instance_selector") and bk_host_id_list: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scope.get("instance_selector") 执行了两次,可做一次赋值
并且这里可以准确判断下 None
if instance_selector is not None:
apps/backend/subscription/tools.py
Outdated
conditions = [ | ||
{ | ||
"key": key, "value": value | ||
} for selector_param in scope["instance_selector"] for key, value in selector_param.items() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上,做赋值
apps/backend/subscription/tools.py
Outdated
biz_scope=[bk_biz_id], | ||
return_all_node_type=True | ||
) | ||
instance_selector_host_id_set = {host.bk_host_id for host in host_queryset} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里用list
apps/backend/subscription/tools.py
Outdated
for node_id, instance in instances_dict.items(): | ||
instance_data = instance[ | ||
"host" | ||
] if data["object_type"] == models.Subscription.ObjectType.HOST else instance["service"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data["object_type"]
可以做赋值,避免取两次
apps/backend/subscription/tools.py
Outdated
|
||
selector_instances_dict = {} | ||
for node_id, instance in instances_dict.items(): | ||
instance_data = instance[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
selector_host_id: int = instance["host"]["bk_host_id"]....
if selector_host_id in instance_selector_host_id_set
apps/node_man/handlers/policy.py
Outdated
@@ -467,7 +468,7 @@ def migrate_preview(cls, query_params: Dict[str, Any]) -> List[Dict[str, Any]]: | |||
step_obj.subscription = subscription | |||
subscription.steps = step_objs | |||
preview_result = tasks.run_subscription_task_and_create_instance( | |||
subscription, subscription_task, preview_only=True | |||
subscription, subscription_task, scope, preview_only=True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么要显式传入 scope,我看这个函数里会取 subscription.scope
@@ -84,6 +84,7 @@ def create_subscription(self, request): | |||
object_type=scope["object_type"], | |||
node_type=scope["node_type"], | |||
nodes=scope["nodes"], | |||
instance_selector=scope.get("instance_selector"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update
接口也要支持更新
@@ -21,12 +21,20 @@ | |||
from apps.utils import basic | |||
|
|||
|
|||
class SubscriptionScopeInstanceSelectorSerializer(serializers.Serializer): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个文件下还有 UpdateScopeSerializer / RunScopeSerializer 等 Scope 序列化器,也要相应补充
Update 功能要注意,只有这个参数明确传入,才去做更新
303c1b4
to
25dfb30
Compare
25dfb30
to
1a5865f
Compare
1a5865f
to
8a9f209
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.