18
18
from backend .bk_web .constants import LEN_MIDDLE , SMALLEST_POSITIVE_INTEGER
19
19
from backend .components import DBConfigApi
20
20
from backend .components .dbconfig import constants as dbconf_const
21
- from backend .configuration .constants import MASTER_DOMAIN_INITIAL_VALUE
21
+ from backend .configuration .constants import MASTER_DOMAIN_INITIAL_VALUE , AffinityEnum
22
22
from backend .db_meta .enums import ClusterType
23
23
from backend .db_meta .models import AppCache , DBModule
24
24
from backend .db_services .dbbase .constants import IpSource
25
+ from backend .db_services .ipchooser .query .resource import ResourceQueryHelper
25
26
from backend .db_services .mysql .constants import DEFAULT_ORIGIN_MYSQL_PORT , SERVER_PORT_LIMIT_MAX , SERVER_PORT_LIMIT_MIN
26
27
from backend .exceptions import ValidationError
27
28
from backend .flow .engine .controller .mysql import MySQLController
@@ -66,6 +67,7 @@ class MysqlSingleApplyDetailSerializer(serializers.Serializer):
66
67
db_module_name = serializers .SerializerMethodField (help_text = _ ("DB模块名" ))
67
68
city_name = serializers .SerializerMethodField (help_text = _ ("城市名" ))
68
69
spec_display = serializers .SerializerMethodField (help_text = _ ("机器规格展示名" ))
70
+ bk_cloud_name = serializers .SerializerMethodField (help_text = _ ("云区域" ), read_only = True )
69
71
70
72
start_mysql_port = serializers .IntegerField (
71
73
help_text = _ ("MySQL起始端口" ),
@@ -74,11 +76,19 @@ class MysqlSingleApplyDetailSerializer(serializers.Serializer):
74
76
max_value = SERVER_PORT_LIMIT_MAX ,
75
77
default = DEFAULT_ORIGIN_MYSQL_PORT ,
76
78
)
79
+ disaster_tolerance_level = serializers .ChoiceField (
80
+ help_text = _ ("容灾级别" ), choices = AffinityEnum .get_choices (), required = False , default = AffinityEnum .NONE .value
81
+ )
82
+
83
+ def get_bk_cloud_name (self , obj ):
84
+ clouds = ResourceQueryHelper .search_cc_cloud (get_cache = True )
85
+ return clouds [str (obj ["bk_cloud_id" ])]["bk_cloud_name" ]
77
86
78
87
def to_representation (self , instance ):
79
88
representation = super ().to_representation (instance )
80
89
self ._format_domains (representation ["domains" ], instance )
81
90
# TODO 缺少数据库版本和字符集,考虑封装 DBConfigHandler 来处理此类需求
91
+ representation ["bk_cloud_name" ] = self .get_bk_cloud_name (instance )
82
92
return representation
83
93
84
94
def validate (self , attrs ):
0 commit comments