Skip to content

Commit

Permalink
feat(backend): clb和北极星信息展示 #2456
Browse files Browse the repository at this point in the history
  • Loading branch information
gaohongsong authored and zhangzhw8 committed Dec 9, 2023
1 parent ac400af commit da81058
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
16 changes: 16 additions & 0 deletions dbm-ui/backend/db_meta/models/cluster_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from typing import Dict, List

from django.db import models
from django.forms import model_to_dict

from backend.bk_web.models import AuditedModel
from backend.components import DnsApi
Expand Down Expand Up @@ -79,6 +80,21 @@ def get_cluster_entry_map_by_cluster_ids(cls, cluster_ids: List[int]) -> Dict[in
cluster_entry_map[entry.cluster_id]["slave_domain"] = access_entry
return cluster_entry_map

@property
def detail(self):
"""入口详情"""

if self.cluster_entry_type == ClusterEntryType.CLB:
detail_obj = self.clbentrydetail_set.first()
elif self.cluster_entry_type == ClusterEntryType.POLARIS:
detail_obj = self.polarisentrydetail_set.first()
elif self.cluster_entry_type == ClusterEntryType.CLBDNS:
detail_obj = self.forward_to
else:
detail_obj = None

return model_to_dict(detail_obj) if detail_obj else {}

def __str__(self):
return "{}:{}".format(self.cluster_entry_type, self.entry)

Expand Down
6 changes: 5 additions & 1 deletion dbm-ui/backend/db_services/dbbase/resources/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.utils.translation import gettext_lazy as _
from rest_framework import serializers

from backend.db_meta.enums import ClusterType
from backend.db_meta.enums import ClusterEntryType, ClusterType
from backend.db_meta.models.cluster import Cluster
from backend.db_services.dbbase.constants import IP_PORT_DIVIDER

Expand Down Expand Up @@ -84,3 +84,7 @@ class RetrieveInstancesSerializer(InstanceAddressSerializer):
class ListNodesSLZ(serializers.Serializer):
role = serializers.CharField(help_text=_("角色"))
keyword = serializers.CharField(help_text=_("关键字过滤"), required=False, allow_blank=True)


class RetrieveClusterEntrySLZ(serializers.Serializer):
entry_type = serializers.ChoiceField(choices=ClusterEntryType.get_choices(), help_text=_("入口类型"))
30 changes: 30 additions & 0 deletions dbm-ui/backend/db_services/redis/resources/redis_cluster/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,40 @@
tags=[constants.RESOURCE_TAG],
),
)
@method_decorator(
name="get_cluster_entries",
decorator=common_swagger_auto_schema(
operation_summary=_("获取集群入口列表"),
query_serializer=serializers.RetrieveClusterEntrySLZ(),
tags=[constants.RESOURCE_TAG],
),
)
class RedisClusterViewSet(viewsets.ResourceViewSet):
query_class = ListRetrieveResource
query_serializer_class = serializers.ListResourceSLZ

@action(
methods=["GET"],
detail=True,
url_path="get_cluster_entries",
serializer_class=serializers.RetrieveClusterEntrySLZ,
pagination_class=None,
)
def get_cluster_entries(self, request, bk_biz_id: int, cluster_id: int):
"""获取集群入口列表"""
cluster = Cluster.objects.get(id=cluster_id, bk_biz_id=bk_biz_id)
return Response(
[
{
"cluster_entry_type": entry.cluster_entry_type,
"entry": entry.entry,
"role": entry.role,
"detail": entry.detail,
}
for entry in cluster.clusterentry_set.filter(cluster_entry_type=self.validated_data["entry_type"])
]
)

@action(methods=["GET"], detail=True, url_path="get_nodes", serializer_class=serializers.ListNodesSLZ)
def get_nodes(self, request, bk_biz_id: int, cluster_id: int):
"""获取特定角色的节点"""
Expand Down

0 comments on commit da81058

Please sign in to comment.