diff --git a/dbm-ui/backend/components/dbresource/client.py b/dbm-ui/backend/components/dbresource/client.py index dd5ae1322b..1d306e04d2 100644 --- a/dbm-ui/backend/components/dbresource/client.py +++ b/dbm-ui/backend/components/dbresource/client.py @@ -107,7 +107,7 @@ def __init__(self): method="POST", url="/statistic/summary", description=_("按照条件聚合资源统计") ) self.resource_label_count = self.generate_data_api( - method="POST", url="/groupby/label/count", description=_("按照标签统计资源数量") + method="POST", url="/resource/groupby/label/count", description=_("按照标签统计资源数量") ) diff --git a/dbm-ui/backend/db_services/dbresource/handlers.py b/dbm-ui/backend/db_services/dbresource/handlers.py index 151059ec99..607b1f6f92 100644 --- a/dbm-ui/backend/db_services/dbresource/handlers.py +++ b/dbm-ui/backend/db_services/dbresource/handlers.py @@ -438,7 +438,9 @@ def _format_resource_fields(data, _cloud_info, _biz_infos, _tag_infos): "bk_biz_id": data["dedicated_biz"], "bk_biz_name": _biz_infos.get(data["dedicated_biz"]), }, - "agent_status": int((data.pop("gse_agent_status_code") == GseApi.Constants.GSE_AGENT_RUNNING_CODE)), + "agent_status": int( + (data.pop("gse_agent_status_code") == GseApi.Constants.GSE_AGENT_RUNNING_CODE) + ), "labels": [{"id": _tag, "name": _tag_infos.get(int(_tag))} for _tag in data.pop("labels") or []], } ) @@ -467,7 +469,7 @@ def _format_resource_fields(data, _cloud_info, _biz_infos, _tag_infos): def standardized_resource_host(cls, hosts, bk_biz_id=None): """标准化主机信息,将cc字段统一成资源池字段""" host_ids = [host["bk_host_id"] for host in hosts] - hosts = ResourceQueryHelper.search_cc_hosts(role_host_ids=host_ids, bk_biz_id=bk_biz_id) + hosts = ResourceQueryHelper.search_cc_hosts(role_host_ids=host_ids) for host in hosts: host.update( bk_biz_id=bk_biz_id, diff --git a/dbm-ui/backend/db_services/dbresource/serializers.py b/dbm-ui/backend/db_services/dbresource/serializers.py index 2c91d61f20..e0086859e2 100644 --- a/dbm-ui/backend/db_services/dbresource/serializers.py +++ b/dbm-ui/backend/db_services/dbresource/serializers.py @@ -54,6 +54,8 @@ def validate(self, attrs): if exist_hosts: raise serializers.ValidationError(_("导入主机{}存在元数据,请检查后重新导入").format(exist_hosts)) + return attrs + class ResourceApplySerializer(serializers.Serializer): class HostDetailSerializer(serializers.Serializer): diff --git a/dbm-ui/backend/db_services/tag/handlers.py b/dbm-ui/backend/db_services/tag/handlers.py index afb770cd91..61e1309b9a 100644 --- a/dbm-ui/backend/db_services/tag/handlers.py +++ b/dbm-ui/backend/db_services/tag/handlers.py @@ -14,6 +14,7 @@ from django.db.models import ManyToManyRel from django.utils.translation import gettext_lazy as _ +from backend.components.dbresource.client import DBResourceApi from backend.db_meta.models import Tag from backend.db_services.tag.constants import TAG_RELATED_RESOURCE_DISPLAY_FIELD, TagResourceType from backend.exceptions import ValidationError @@ -79,7 +80,8 @@ def query_related_resources(cls, ids: List[int], resource_type: str = None): if resource_type == TagResourceType.DB_RESOURCE.value: # 资源池根据标签聚合数量 - data = [{"id": tag_id, "ip_count": 0} for tag_id in ids] + label_count_map = DBResourceApi.resource_label_count() + data = [{"id": tag_id, "ip_count": label_count_map.get(str(tag_id), 0)} for tag_id in ids] return data diff --git a/dbm-ui/backend/ticket/builders/sqlserver/sqlserver_restore_slave.py b/dbm-ui/backend/ticket/builders/sqlserver/sqlserver_restore_slave.py index f06a8044b8..815a8bf675 100644 --- a/dbm-ui/backend/ticket/builders/sqlserver/sqlserver_restore_slave.py +++ b/dbm-ui/backend/ticket/builders/sqlserver/sqlserver_restore_slave.py @@ -96,16 +96,17 @@ def format(self): bk_host_id__in=master_hosts ) } - for info in self.ticket.details["infos"]: + for info in self.ticket_data["infos"]: # 申请新的slave, 需要和当前集群中的master处于不同机房; - master_machine = id__machine[formatted_dict[info["old_slave_host"]["bk_host_id"]]] + old_slave_host = info["old_nodes"]["old_slave_host"][0] + master_machine = id__machine[formatted_dict[old_slave_host["bk_host_id"]]] # TODO: 还有补充操作系统 info["resource_spec"]["sqlserver_ha"]["location_spec"] = { "city": master_machine.bk_city.logical_city.name, "sub_zone_ids": [master_machine.bk_sub_zone_id], "include_or_exclue": False, } - self.ticket.save(update_fields=["details"]) + info.update(bk_cloud_id=master_machine.bk_cloud_id) def post_callback(self): next_flow = self.ticket.next_flow()