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

feat: 插件operate接口支持主机差量同步 (closed #2510) #2511

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 = list(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