From e9c2134175922c22e7021c08300bf1261fc6044f Mon Sep 17 00:00:00 2001 From: dcd <1151627903@qq.com> Date: Thu, 5 Dec 2024 20:14:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8F=92=E4=BB=B6operate=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=94=AF=E6=8C=81=E4=B8=BB=E6=9C=BA=E5=B7=AE=E9=87=8F?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=20(closed=20#2510)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/core/ipchooser/handlers/host_handler.py | 2 +- apps/node_man/serializers/plugin.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/core/ipchooser/handlers/host_handler.py b/apps/core/ipchooser/handlers/host_handler.py index 00c7b5e98..a371a569f 100644 --- a/apps/core/ipchooser/handlers/host_handler.py +++ b/apps/core/ipchooser/handlers/host_handler.py @@ -126,7 +126,7 @@ def bulk_differential_sync_hosts(cls, need_differential_sync_bk_host_ids): bk_host_ids=need_differential_sync_bk_host_ids ) - expected_bk_host_ids_gby_bk_biz_id: typing.Dict[str, typing.List[int]] = defaultdict(list) + expected_bk_host_ids_gby_bk_biz_id: typing.Dict[int, typing.List[int]] = defaultdict(list) for host_biz_realtion in host_biz_relations: expected_bk_host_ids_gby_bk_biz_id[host_biz_realtion["bk_biz_id"]].append(host_biz_realtion["bk_host_id"]) diff --git a/apps/node_man/serializers/plugin.py b/apps/node_man/serializers/plugin.py index f1ebbc2d6..8ed52020c 100644 --- a/apps/node_man/serializers/plugin.py +++ b/apps/node_man/serializers/plugin.py @@ -12,6 +12,7 @@ from django.utils.translation import ugettext_lazy as _ from rest_framework import serializers +from apps.core.ipchooser.handlers.host_handler import HostHandler from apps.exceptions import ValidationError from apps.node_man.constants import ( CATEGORY_CHOICES, @@ -25,6 +26,7 @@ from apps.node_man.models import ( GlobalSettings, GsePluginDesc, + Host, Packages, ProcControl, ProcessStatus, @@ -265,6 +267,14 @@ def validate(self, attrs): raise ValidationError(_("跨页全选模式下不允许传bk_host_id参数.")) if attrs.get("exclude_hosts") is None and attrs.get("bk_host_id") is None: raise ValidationError(_("必须选择一种模式(【是否跨页全选】)")) + if attrs.get("bk_host_id") and not attrs.get("exclude_hosts"): + exist_host_ids = set( + Host.objects.filter(bk_host_id__in=attrs["bk_host_id"]).values_list("bk_host_id", flat=True) + ) + # 需要去同步的主机ID + need_differential_sync_bk_host_ids = set(attrs["bk_host_id"]) - exist_host_ids + if need_differential_sync_bk_host_ids: + HostHandler.bulk_differential_sync_hosts(need_differential_sync_bk_host_ids) if attrs["node_type"] != ProcType.PLUGIN: raise ValidationError(_("插件管理只允许对插件进行操作."))