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(backend): 主机资源池流转 #7747 #7748

Open
wants to merge 4 commits into
base: feat/v1.5.0_resource_tag
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions dbm-ui/backend/components/dbresource/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ def __init__(self):
self.resource_summary = self.generate_data_api(
method="POST", url="/statistic/summary", description=_("按照条件聚合资源统计")
)
self.resource_label_count = self.generate_data_api(
method="POST", url="/resource/groupby/label/count", description=_("按照标签统计资源数量")
)
self.resource_append_labels = self.generate_data_api(
method="POST",
url="/resource/append/labels",
description=_("追加标签"),
)


DBResourceApi = _DBResourceApi()
13 changes: 10 additions & 3 deletions dbm-ui/backend/db_dirty/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@

@admin.register(models.DirtyMachine)
class DirtyMachineAdmin(admin.ModelAdmin):
list_display = ("ip", "bk_biz_id", "bk_host_id", "flow", "ticket")
list_filter = ("ip", "bk_biz_id", "bk_host_id", "flow", "ticket")
search_fields = ("ip", "bk_biz_id", "bk_host_id", "flow", "ticket")
list_display = ("ip", "bk_biz_id", "bk_host_id", "ticket", "pool")
list_filter = ("ip", "ticket", "pool")
search_fields = ("ip", "bk_biz_id", "bk_host_id")


@admin.register(models.MachineEvent)
class MachineEventAdmin(admin.ModelAdmin):
list_display = ("ip", "bk_biz_id", "bk_host_id", "event", "to", "ticket")
list_filter = ("ip", "bk_biz_id", "to")
search_fields = ("ip", "bk_biz_id", "bk_host_id")
37 changes: 36 additions & 1 deletion dbm-ui/backend/db_dirty/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,39 @@

from django.utils.translation import ugettext_lazy as _

SWAGGER_TAG = _("污点池")
from blue_krill.data_types.enum import EnumField, StructuredEnum

SWAGGER_TAG = _("主机池")


class PoolType(str, StructuredEnum):
# 池管理:污点池,故障池,待回收池
Dirty = EnumField("dirty", _("污点池"))
Fault = EnumField("fault", _("故障池"))
Recycle = EnumField("recycle", _("待回收池"))
# 资源池不由saas维护,单独由资源池服务维护
Resource = EnumField("resource", _("资源池"))
# 回收池表示已经挪到cc待回收,不在dbm流转
Recycled = EnumField("recycled", _("已回收"))


class MachineEventType(str, StructuredEnum):
ImportResource = EnumField("import_resource", _("导入资源池"))
ApplyResource = EnumField("apply_resource", _("申请资源"))
ReturnResource = EnumField("return_resource", _("退回资源"))
ToDirty = EnumField("to_dirty", _("转入污点池"))
ToRecycle = EnumField("to_recycle", _("转入待回收池"))
ToFault = EnumField("to_fault", _("转入故障池"))
UndoImport = EnumField("undo_import", _("撤销导入"))
Recycled = EnumField("recycled", _("回收"))


MACHINE_EVENT__POOL_MAP = {
MachineEventType.ToDirty: PoolType.Dirty,
MachineEventType.ToRecycle: PoolType.Recycle,
MachineEventType.ToFault: PoolType.Fault,
MachineEventType.ImportResource: PoolType.Resource,
MachineEventType.ReturnResource: PoolType.Resource,
MachineEventType.Recycled: PoolType.Recycled,
MachineEventType.UndoImport: PoolType.Recycled,
}
24 changes: 24 additions & 0 deletions dbm-ui/backend/db_dirty/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at https://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""

from django.utils.translation import ugettext_lazy as _

from backend.exceptions import AppBaseException, ErrorCode


class DBDirtyPoolBaseException(AppBaseException):
MODULE_CODE = ErrorCode.DB_DIRTY_POOL_CODE
MESSAGE = _("主机池异常")


class PoolTransferException(DBDirtyPoolBaseException):
ERROR_CODE = "001"
MESSAGE = _("主机池转移异常")
MESSAGE_TPL = _("主机池转移异常")
44 changes: 21 additions & 23 deletions dbm-ui/backend/db_dirty/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,38 @@
from django_filters import rest_framework as filters
from django_filters.filters import BaseInFilter, NumberFilter

from backend.db_dirty.models import DirtyMachine
from backend.db_dirty.models import DirtyMachine, MachineEvent


class NumberInFilter(BaseInFilter, NumberFilter):
pass


class DirtyMachineFilter(filters.FilterSet):
ticket_types = filters.CharFilter(field_name="ticket__ticket_type", method="filter_ticket_types", label=_("单据类型"))
ticket_ids = filters.CharFilter(field_name="ticket__id", method="filter_ticket_ids", label=_("单据ID"))
task_ids = filters.CharFilter(field_name="flow__flow_obj_id", method="filter_task_ids", label=_("任务ID"))
operator = filters.CharFilter(field_name="ticket__creator", lookup_expr="icontains", label=_("操作者"))
ip = filters.CharFilter(field_name="ip", method="filter_ip", label=_("过滤IP"))
bk_cloud_ids = NumberInFilter(field_name="bk_cloud_id", lookup_expr="in")
bk_biz_ids = NumberInFilter(field_name="bk_biz_id", lookup_expr="in")
class MachineEventFilter(filters.FilterSet):
operator = filters.CharFilter(field_name="creator", lookup_expr="icontains", label=_("操作者"))
bk_biz_id = filters.NumberFilter(field_name="bk_biz_id", label=_("业务"))
event = filters.CharFilter(field_name="event", lookup_expr="exact", label=_("事件类型"))
ips = filters.CharFilter(field_name="ip", method="filter_ips", label=_("过滤IP"))

def _split_int(self, value):
try:
return list(map(int, value.split(",")))
except ValueError:
return []

def filter_ip(self, queryset, name, value):
def filter_ips(self, queryset, name, value):
return queryset.filter(ip__in=value.split(","))

def filter_ticket_ids(self, queryset, name, value):
return queryset.filter(ticket__id__in=self._split_int(value))
class Meta:
model = MachineEvent
fields = ["operator", "bk_biz_id", "event", "ips"]


def filter_ticket_types(self, queryset, name, value):
return queryset.filter(ticket__ticket_type__in=value.split(","))
class DirtyMachinePoolFilter(filters.FilterSet):
ips = filters.CharFilter(field_name="ip", method="filter_ips", label=_("过滤IP"))
city = filters.CharFilter(field_name="city", lookup_expr="icontains", label=_("城市"))
sub_zone = filters.CharFilter(field_name="sub_zone", lookup_expr="icontains", label=_("园区"))
rack_id = filters.CharFilter(field_name="rack_id", lookup_expr="icontains", label=_("机架"))
device_class = filters.CharFilter(field_name="device_class", lookup_expr="icontains", label=_("机型"))
os_name = filters.CharFilter(field_name="os_name", lookup_expr="icontains", label=_("操作系统"))

def filter_task_ids(self, queryset, name, value):
return queryset.filter(flow__flow_obj_id__in=value.split(","))
def filter_ips(self, queryset, name, value):
return queryset.filter(ip__in=value.split(","))

class Meta:
model = DirtyMachine
fields = ["ticket_types", "ticket_ids", "task_ids", "operator", "ip"]
fields = {"bk_biz_id": ["exact"], "creator": ["exact"], "pool": ["exact"]}
Loading
Loading