Skip to content

Commit

Permalink
fix(backend): 资源导入uwork检查 TencentBlueKing#7981
Browse files Browse the repository at this point in the history
# Reviewed, transaction id: 23963
  • Loading branch information
ygcyao authored and xfwduke committed Nov 20, 2024
1 parent 65e5581 commit df8e9a7
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions dbm-ui/backend/components/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
NAMESERVICE_APIGW_DOMAIN = env.NAMESERVICE_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("nameservice")
HADB_APIGW_DOMAIN = env.HADB_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("hadb")
HCM_APIGW_DOMAIN = env.HCM_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("hcm")
UWORK_APIGW_DOMAIN = env.UWORK_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("uwork")
DBRESOURCE_APIGW_DOMAIN = env.DBRESOURCE_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("dbresource")
BACKUP_APIGW_DOMAIN = env.BACKUP_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("backup")
CELERY_SERVICE_APIGW_DOMAIN = env.CELERY_SERVICE_APIGW_DOMAIN or ESB_DOMAIN_TPL.format("celery_service")
Expand Down
10 changes: 10 additions & 0 deletions dbm-ui/backend/components/uwork/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
"""
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.
"""
30 changes: 30 additions & 0 deletions dbm-ui/backend/components/uwork/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
"""
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
Copyright (C) 2017-2021 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 ..base import BaseApi
from ..domains import UWORK_APIGW_DOMAIN


class _UWORKApi(BaseApi):
MODULE = _("星象 服务")
BASE = UWORK_APIGW_DOMAIN

def __init__(self):
self.uwork_list = self.generate_data_api(
method="POST",
url="/xray-srv-process-reception/queryMergedFaultInfo",
description=_("获取故障机器列表"),
)


UWORKApi = _UWORKApi()
7 changes: 7 additions & 0 deletions dbm-ui/backend/db_services/dbresource/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,10 @@ class ListCvmDeviceClassSerializer(serializers.Serializer):
class ListCvmDeviceClassResponseSerializer(serializers.Serializer):
class Meta:
swagger_schema_fields = {"example": mock.DEVICE_CLASS_DATA}


class UworkIpsSerializer(serializers.Serializer):
ips = serializers.CharField(help_text=_("ip列表,多个ip以逗号分割"))

def validate_ip_list(self, value):
return value.split(",")
16 changes: 16 additions & 0 deletions dbm-ui/backend/db_services/dbresource/views/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from backend.components import CCApi
from backend.components.dbresource.client import DBResourceApi
from backend.components.hcm.client import HCMApi
from backend.components.uwork.client import UWORKApi
from backend.configuration.constants import SystemSettingsEnum
from backend.configuration.models import SystemSettings
from backend.db_meta.models import AppCache
Expand Down Expand Up @@ -55,6 +56,7 @@
ResourceUpdateSerializer,
SpecCountResourceResponseSerializer,
SpecCountResourceSerializer,
UworkIpsSerializer,
)
from backend.db_services.ipchooser.constants import BK_OS_CODE__TYPE, BkOsType, ModeType
from backend.db_services.ipchooser.handlers.host_handler import HostHandler
Expand Down Expand Up @@ -494,3 +496,17 @@ def query_operation_list(self, request):
def spec_resource_count(self, request):
apply_params = self.params_validate(self.get_serializer_class())
return Response(ResourceHandler.spec_resource_count(**apply_params))

@common_swagger_auto_schema(
operation_summary=_("查询故障主机信息"),
query_serializer=UworkIpsSerializer(),
tags=[SWAGGER_TAG],
)
@action(detail=False, methods=["GET"], serializer_class=UworkIpsSerializer)
def check_uwork_ips(self, request):
if not env.UWORK_APIGW_DOMAIN:
return Response({"results": []})
ip_list = self.params_validate(self.get_serializer_class())["ips"]
results = UWORKApi.uwork_list(params={"serverIpList": ip_list})
uwork_list = [result["serverIp"] for result in results]
return Response({"results": uwork_list})
1 change: 1 addition & 0 deletions dbm-ui/backend/env/apigw_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
DRS_APIGW_DOMAIN = get_type_env(key="DRS_APIGW_DOMAIN", _type=str)
NAMESERVICE_APIGW_DOMAIN = get_type_env(key="NAMESERVICE_APIGW_DOMAIN", _type=str)
HCM_APIGW_DOMAIN = get_type_env(key="HCM_APIGW_DOMAIN", _type=str)
UWORK_APIGW_DOMAIN = get_type_env(key="UWORK_APIGW_DOMAIN", _type=str)

DBCONFIG_APIGW_DOMAIN = get_type_env(key="DBCONFIG_APIGW_DOMAIN", _type=str, default="http://bk-dbm-dbconfig")
DNS_APIGW_DOMAIN = get_type_env(key="DNS_APIGW_DOMAIN", _type=str, default="http://bk-dbm-db-dns-api")
Expand Down

0 comments on commit df8e9a7

Please sign in to comment.