Skip to content

Commit

Permalink
feat: 插件operate接口支持主机差量同步 (closed TencentBlueKing#2510)
Browse files Browse the repository at this point in the history
  • Loading branch information
Huayeaaa committed Dec 5, 2024
1 parent 847a5d7 commit e9c2134
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/core/ipchooser/handlers/host_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down
10 changes: 10 additions & 0 deletions apps/node_man/serializers/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -25,6 +26,7 @@
from apps.node_man.models import (
GlobalSettings,
GsePluginDesc,
Host,
Packages,
ProcControl,
ProcessStatus,
Expand Down Expand Up @@ -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(_("插件管理只允许对插件进行操作."))
Expand Down

0 comments on commit e9c2134

Please sign in to comment.