Skip to content

Commit

Permalink
fix(backend): 修复资源池列表cc接口报错 #7300
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud committed Oct 12, 2024
1 parent d3bc12c commit fa397d7
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
3 changes: 2 additions & 1 deletion dbm-ui/backend/components/mysql_priv_manager/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
class _DBPrivManagerApi(BaseApi):
MODULE = _("DB权限管理")
BASE = MYSQL_PRIV_MANAGER_APIGW_DOMAIN
# 权限相关操作的默认超时时间,暂定3h
# 权限相关操作的默认超时时间,暂定3h,请在调用接口的时候按需使用
# eg: DBPrivManagerApi.modify_admin_password(params=xxx,timeout=DBPrivManagerApi.TIMEOUT)
TIMEOUT = 3 * 60 * 60

def __init__(self):
Expand Down
1 change: 1 addition & 0 deletions dbm-ui/backend/configuration/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class SystemSettingsEnum(str, StructuredEnum):
FREE_BK_MODULE_ID = EnumField("FREE_BK_MODULE_ID", _("业务空闲模块ID"))
# 主机默认统一转移到 DBM 业务下托管,若业务 ID 属于这个列表,则转移到对应的业务下
INDEPENDENT_HOSTING_BIZS = EnumField("INDEPENDENT_HOSTING_BIZS", _("独立托管机器的业务列表"))
BF_WHITELIST_BIZS = EnumField("BF_WHITELIST_BIZS", _("BF业务白名单"))
SPEC_OFFSET = EnumField("SPEC_OFFSET", _("默认的规格参数偏移量"))
DEVICE_CLASSES = EnumField("DEVICE_CLASSES", _("机型列表"))
BKM_DUTY_NOTICE = EnumField("BKM_DUTY_NOTICE", _("轮值通知设置"))
Expand Down
4 changes: 3 additions & 1 deletion dbm-ui/backend/configuration/handlers/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ def modify_admin_password(cls, operator: str, password: str, lock_hour: int, ins
"security_rule_name": DBM_PASSWORD_SECURITY_NAME,
"async": False,
}
data = DBPrivManagerApi.modify_admin_password(params=modify_password_params, raw=True)["data"]
data = DBPrivManagerApi.modify_admin_password(
params=modify_password_params, raw=True, timeout=DBPrivManagerApi.TIMEOUT
)["data"]
return data

@classmethod
Expand Down
1 change: 1 addition & 0 deletions dbm-ui/backend/db_meta/models/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def get_app_attr(cls, bk_biz_id, attr_name="db_app_abbr", default=""):

@classmethod
def batch_get_app_attr(cls, bk_biz_ids, attr_name="db_app_abbr"):
bk_biz_ids = list(set(bk_biz_ids))
apps = cls.objects.filter(bk_biz_id__in=bk_biz_ids)
infos = apps.values("bk_biz_id", attr_name)
if set(apps.values_list("bk_biz_id", flat=True)) != set(bk_biz_ids):
Expand Down
9 changes: 2 additions & 7 deletions dbm-ui/backend/db_services/dbresource/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,17 +394,12 @@ def spec_resource_count(cls, bk_biz_id: int, bk_cloud_id: int, spec_ids: List[in
resource_type = ClusterType.cluster_type_to_db_type(spec_cluster_type[0])
# 构造申请参数
spec_count_details = [
spec.get_group_apply_params(
group_mark=str(spec.spec_id),
count=1,
group_count=1,
bk_cloud_id=bk_cloud_id,
location_spec={"city": city, "sub_zone_ids": []},
)
spec.get_group_apply_params(group_mark=str(spec.spec_id), count=1, group_count=1, bk_cloud_id=bk_cloud_id)
for spec in specs
]
spec_count_details = list(itertools.chain(*spec_count_details))
spec_count_params = {
"location_spec": {"city": "" if city == "default" else city, "sub_zone_ids": []},
"for_biz_id": bk_biz_id,
"resource_type": resource_type,
"bk_cloud_id": bk_cloud_id,
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/db_services/dbresource/views/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _format_resource_fields(data, _cloud_info, _biz_infos):

# 获取云区域信息和业务信息
cloud_info = ResourceQueryHelper.search_cc_cloud(get_cache=True)
for_biz_ids = [data["dedicated_biz"] for data in resource_data["details"]]
for_biz_ids = [data["dedicated_biz"] for data in resource_data["details"] if data["dedicated_biz"]]
for_biz_infos = AppCache.batch_get_app_attr(bk_biz_ids=for_biz_ids, attr_name="bk_biz_name")
# 格式化资源池字段信息
for data in resource_data.get("details") or []:
Expand Down
7 changes: 5 additions & 2 deletions dbm-ui/backend/db_services/plugin/bf/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from backend import env
from backend.bk_web import viewsets
from backend.bk_web.swagger import common_swagger_auto_schema
from backend.configuration.models import DBAdministrator
from backend.configuration.constants import SystemSettingsEnum
from backend.configuration.models import DBAdministrator, SystemSettings
from backend.db_meta.enums import ClusterType
from backend.db_meta.models import Machine
from backend.db_services.plugin.bf.serializers import HasBFPrivSerializer
Expand Down Expand Up @@ -58,5 +59,7 @@ def has_host_bf_access(self, request, *args, **kwargs):
@action(methods=["GET"], detail=False)
def list_bf_biz_whitelist(self, request, *args, **kwargs):
# 目前默认只认为默认DBM业务才能申请
bf_biz_whitelist = [env.DBA_APP_BK_BIZ_ID]
bf_biz_whitelist = SystemSettings.get_setting_value(
SystemSettingsEnum.BF_WHITELIST_BIZS, default=[env.DBA_APP_BK_BIZ_ID]
)
return Response(bf_biz_whitelist)

0 comments on commit fa397d7

Please sign in to comment.