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 da81058 commit 4a60ecd
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 45 deletions.
5 changes: 5 additions & 0 deletions dbm-ui/backend/db_services/cluster_entry/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ def validate(self, attrs):
if not detail["target_instances"]:
raise serializers.ValidationError(_("修改 DNS,目标实例列表不能为空"))
return attrs


class RetrieveClusterEntrySLZ(serializers.Serializer):
cluster_id = serializers.IntegerField(help_text=_("集群 ID"))
entry_type = serializers.ChoiceField(choices=ClusterEntryType.get_choices(), help_text=_("入口类型"))
30 changes: 29 additions & 1 deletion dbm-ui/backend/db_services/cluster_entry/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from backend.bk_web.swagger import common_swagger_auto_schema
from backend.db_meta.enums import ClusterEntryType
from backend.db_meta.models import Cluster
from backend.db_services.cluster_entry.serializers import ModifyClusterEntrySerializer
from backend.db_services.cluster_entry.serializers import ModifyClusterEntrySerializer, RetrieveClusterEntrySLZ
from backend.db_services.dbbase.resources.query import ListRetrieveResource
from backend.flow.utils.dns_manage import DnsManage
from backend.iam_app.handlers.drf_perm import GlobalManageIAMPermission

Expand All @@ -40,3 +41,30 @@ def refresh_cluster_domain(self, request, *args, **kwargs):
detail["domain_name"], detail["target_instances"]
)
return Response({})

@common_swagger_auto_schema(
operation_summary=_("获取集群入口列表"),
query_serializer=RetrieveClusterEntrySLZ(),
tags=[SWAGGER_TAG],
)
@action(
methods=["GET"],
detail=False,
url_path="get_cluster_entries",
serializer_class=RetrieveClusterEntrySLZ,
pagination_class=None,
)
def get_cluster_entries(self, request, *args, **kwargs):
"""获取集群入口列表"""

cluster = Cluster.objects.get(id=self.validated_data["cluster_id"])
cluster_entries = ListRetrieveResource.query_cluster_entry_details(
{
"id": cluster.id,
"bk_cloud_id": cluster.bk_cloud_id,
"bk_biz_id": cluster.bk_biz_id,
},
cluster_entry_type=self.validated_data["entry_type"],
)

return Response(cluster_entries)
8 changes: 4 additions & 4 deletions dbm-ui/backend/db_services/dbbase/resources/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ def retrieve_cluster(cls, bk_biz_id: int, cluster_id: int) -> dict:
return cluster_details

@classmethod
def query_cluster_entry_details(cls, cluster_details):
def query_cluster_entry_details(cls, cluster_details, **kwargs):
"""查询集群访问入口详情"""
entries = ClusterEntry.objects.filter(cluster_id=cluster_details["id"])
entries = ClusterEntry.objects.filter(cluster_id=cluster_details["id"], **kwargs)
entry_details = []
for entry in entries:
if entry.cluster_entry_type == ClusterEntryType.DNS:
target_details = DnsManage(
bk_biz_id=cluster_details["bk_biz_id"], bk_cloud_id=cluster_details["bk_cloud_id"]
).get_domain(entry.entry)
# TODO clb, polaris
else:
target_details = []
target_details = entry.detail

entry_details.append(
{
"cluster_entry_type": entry.cluster_entry_type,
Expand Down
4 changes: 0 additions & 4 deletions dbm-ui/backend/db_services/dbbase/resources/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,3 @@ 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=_("入口类型"))
6 changes: 0 additions & 6 deletions dbm-ui/backend/db_services/dbbase/resources/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,5 @@ def get_topo_graph(self, request, bk_biz_id: int, cluster_id: int):
"""获取拓扑图"""
return Response(self.query_class.get_topo_graph(bk_biz_id, cluster_id))

@action(methods=["POST"], detail=True, url_path="update_cluster_entry")
def update_cluster_entry(self, request, bk_biz_id: int, cluster_id: int):
"""修改集群入口"""
# TODO
return Response()

def _paginate_resource_list(self, request, bk_biz_id: int):
return self.paginator.paginate_resource_list(request, bk_biz_id, self)
30 changes: 0 additions & 30 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,40 +83,10 @@
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 4a60ecd

Please sign in to comment.