9191 get_sql_managed_database_restore_details_operations ,
9292 get_sql_replication_links_operations ,
9393 get_sql_elastic_pools_operations ,
94+ get_sql_databases_operations ,
9495)
9596
9697
104105###############################################
105106
106107
107- def _get_server_location (cli_ctx , server_name , resource_group_name ):
108+ def _get_server_location (cli_ctx , server_name , resource_group_name , subscription_id = None ):
108109 '''
109110 Returns the location (i.e. Azure region) that the specified server is in.
110111 '''
111112
112- server_client = get_sql_servers_operations (cli_ctx , None )
113+ server_client = get_sql_servers_operations (cli_ctx , None , subscription_id )
113114 # pylint: disable=no-member
114115 return server_client .get (
115116 server_name = server_name ,
@@ -955,19 +956,22 @@ class DatabaseIdentity: # pylint: disable=too-few-public-methods
955956 database resource id.
956957 '''
957958
958- def __init__ (self , cli_ctx , database_name , server_name , resource_group_name ):
959-
959+ def __init__ (self , cli_ctx , database_name , server_name , resource_group_name , subscription_id = None ):
960+ from azure . cli . core . commands . client_factory import get_subscription_id
960961 self .database_name = database_name
961962 self .server_name = server_name
962963 self .resource_group_name = resource_group_name
963964 self .cli_ctx = cli_ctx
965+ if subscription_id is not None :
966+ self .subscription_id = subscription_id
967+ else :
968+ self .subscription_id = get_subscription_id (self .cli_ctx )
964969
965970 def id (self ):
966971 from urllib .parse import quote
967- from azure .cli .core .commands .client_factory import get_subscription_id
968972
969973 return '/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Sql/servers/{}/databases/{}' .format (
970- quote (get_subscription_id ( self .cli_ctx ) ),
974+ quote (self .subscription_id ),
971975 quote (self .resource_group_name ),
972976 quote (self .server_name ),
973977 quote (self .database_name ))
@@ -1024,7 +1028,8 @@ def _validate_elastic_pool_id(
10241028 cli_ctx ,
10251029 elastic_pool_id ,
10261030 server_name ,
1027- resource_group_name ):
1031+ resource_group_name ,
1032+ subscription_id = None ):
10281033 '''
10291034 Validates elastic_pool_id is either None or a valid resource id.
10301035
@@ -1039,9 +1044,12 @@ def _validate_elastic_pool_id(
10391044 from azure .mgmt .core .tools import resource_id , is_valid_resource_id
10401045 from azure .cli .core .commands .client_factory import get_subscription_id
10411046
1047+ if subscription_id is None :
1048+ subscription_id = get_subscription_id (cli_ctx )
1049+
10421050 if elastic_pool_id and not is_valid_resource_id (elastic_pool_id ):
10431051 return resource_id (
1044- subscription = get_subscription_id ( cli_ctx ) ,
1052+ subscription = subscription_id ,
10451053 resource_group = resource_group_name ,
10461054 namespace = 'Microsoft.Sql' ,
10471055 type = 'servers' ,
@@ -1146,7 +1154,8 @@ def _db_dw_create(
11461154 kwargs ['location' ] = _get_server_location (
11471155 cli_ctx ,
11481156 server_name = dest_db .server_name ,
1149- resource_group_name = dest_db .resource_group_name )
1157+ resource_group_name = dest_db .resource_group_name ,
1158+ subscription_id = dest_db .subscription_id )
11501159
11511160 # Set create mode properties
11521161 if source_db :
@@ -1168,7 +1177,8 @@ def _db_dw_create(
11681177 cli_ctx ,
11691178 kwargs ['elastic_pool_id' ],
11701179 dest_db .server_name ,
1171- dest_db .resource_group_name )
1180+ dest_db .resource_group_name ,
1181+ dest_db .subscription_id )
11721182
11731183 # Expand maintenance configuration id if needed
11741184 kwargs ['maintenance_configuration_id' ] = _complete_maintenance_configuration_id (
@@ -1401,6 +1411,7 @@ def db_create_replica(
14011411 partner_server_name ,
14021412 partner_database_name = None ,
14031413 partner_resource_group_name = None ,
1414+ partner_sub_id = None ,
14041415 secondary_type = None ,
14051416 no_wait = False ,
14061417 assign_identity = False ,
@@ -1418,6 +1429,10 @@ def db_create_replica(
14181429 # Determine optional values
14191430 partner_resource_group_name = partner_resource_group_name or resource_group_name
14201431 partner_database_name = partner_database_name or database_name
1432+ if partner_sub_id is not None :
1433+ partner_client = get_sql_databases_operations (cmd .cli_ctx , None , partner_sub_id )
1434+ else :
1435+ partner_client = client
14211436
14221437 # Set create mode
14231438 kwargs ['create_mode' ] = CreateMode .SECONDARY
@@ -1435,18 +1450,26 @@ def db_create_replica(
14351450 # Check backup storage redundancy configurations
14361451 location = _get_server_location (cmd .cli_ctx ,
14371452 server_name = partner_server_name ,
1438- resource_group_name = partner_resource_group_name )
1453+ resource_group_name = partner_resource_group_name ,
1454+ subscription_id = partner_sub_id )
14391455 if _should_show_backup_storage_redundancy_warnings (location ):
14401456 if not kwargs ['requested_backup_storage_redundancy' ]:
14411457 _backup_storage_redundancy_take_source_warning ()
14421458 if kwargs ['requested_backup_storage_redundancy' ] == 'Geo' :
14431459 _backup_storage_redundancy_specify_geo_warning ()
14441460
1461+ primary_database = DatabaseIdentity (cmd .cli_ctx , database_name , server_name , resource_group_name )
1462+ secondary_database = DatabaseIdentity (cmd .cli_ctx ,
1463+ partner_database_name ,
1464+ partner_server_name ,
1465+ partner_resource_group_name ,
1466+ partner_sub_id )
1467+
14451468 return _db_dw_create (
14461469 cmd .cli_ctx ,
1447- client ,
1448- DatabaseIdentity ( cmd . cli_ctx , database_name , server_name , resource_group_name ) ,
1449- DatabaseIdentity ( cmd . cli_ctx , partner_database_name , partner_server_name , partner_resource_group_name ) ,
1470+ partner_client ,
1471+ primary_database ,
1472+ secondary_database ,
14501473 no_wait ,
14511474 secondary_type = secondary_type ,
14521475 assign_identity = assign_identity ,
0 commit comments