9
9
specific language governing permissions and limitations under the License.
10
10
"""
11
11
12
- from typing import Dict , Optional
12
+ from typing import Dict , List , Optional , Set
13
13
14
14
from django .utils .translation import ugettext as _
15
15
26
26
)
27
27
28
28
29
+ def find_other_relation_domains (immute_domains : List [str ]) -> List [str ]:
30
+ qs_cluster = Cluster .objects .filter (immute_domain__in = immute_domains )
31
+ fetch_cluster_ids : Set [int ] = set ()
32
+ for c in qs_cluster .all ():
33
+ for s in c .storageinstance_set .all ():
34
+ fetch_cluster_ids |= set (list (s .machine .storageinstance_set .values_list ("cluster" , flat = True )))
35
+
36
+ for p in c .proxyinstance_set .all ():
37
+ fetch_cluster_ids |= set (list (p .machine .proxyinstance_set .values_list ("cluster" , flat = True )))
38
+
39
+ input_cluster_ids = list (qs_cluster .values_list ("id" , flat = True ))
40
+ if input_cluster_ids != list (fetch_cluster_ids ):
41
+ res = []
42
+ for cluster_id in list (fetch_cluster_ids .difference (set (input_cluster_ids ))):
43
+ res .append (Cluster .objects .get (id = cluster_id ).immute_domain )
44
+ return res
45
+
46
+
29
47
class TransferMySQLClusterToOtherBizFlow (object ):
30
48
"""
31
49
将MySQL集群转移到其他业务
@@ -41,7 +59,9 @@ def __init__(self, root_id: str, data: Optional[Dict]) -> None:
41
59
self .need_clone_priv_rules = data .get ("need_clone_priv_rules" )
42
60
43
61
def transfer_to_other_biz_flow (self ):
44
-
62
+ other_domains = find_other_relation_domains (self .cluster_domain_list )
63
+ if len (other_domains ) > 0 :
64
+ raise Exception (_ ("以下域名与当前业务存在关联,请先处理关联关系:{}" .format (other_domains )))
45
65
clusters = Cluster .objects .filter (bk_biz_id = self .bk_biz_id , immute_domain__in = self .cluster_domain_list ).all ()
46
66
bk_cloud_ids = []
47
67
source_bk_biz_ids = []
@@ -63,10 +83,8 @@ def transfer_to_other_biz_flow(self):
63
83
raise Exception (_ ("迁移的集群必须在同一个云区域" ))
64
84
if len (uniq_source_bk_biz_ids ) != 1 :
65
85
raise Exception (_ ("迁移的集群必须在同一个业务" ))
66
-
67
86
bk_cloud_id = uniq_bk_cloud_ids [0 ]
68
87
source_bk_biz_id = uniq_source_bk_biz_ids [0 ]
69
-
70
88
p = Builder (root_id = self .root_id , data = self .data )
71
89
72
90
if self .need_clone_priv_rules :
0 commit comments