55
66# pylint: disable=line-too-long
77# pylint: disable=possibly-used-before-assignment
8+ from knack .util import CLIError
9+ from knack .log import get_logger
810from azext_migrate .helpers ._utils import (
911 get_resource_by_id ,
1012 create_or_update_resource ,
1113 APIVersion ,
12- ProvisioningState ,
1314 SiteTypes ,
1415 VMNicSelection
1516)
16- import re
17- from knack .util import CLIError
18- from knack .log import get_logger
1917
2018logger = get_logger (__name__ )
2119
@@ -61,17 +59,17 @@ def get_ARC_resource_bridge_info(cmd, target_fabric, migrate_project):
6159 custom_location = get_resource_by_id (
6260 cmd , custom_location_id , "2021-08-15" )
6361 custom_location_region = custom_location .get ('location' )
64- logger .info (f "Retrieved custom location region: { custom_location_region } " )
65- except Exception as e :
62+ logger .info ("Retrieved custom location region: %s" , custom_location_region )
63+ except Exception : # pylint: disable=broad-exception-caught
6664 logger .warning (
67- f "Could not retrieve custom location: { str ( e ) } . "
68- f "Falling back to migrate project location." )
65+ "Could not retrieve custom location. "
66+ "Falling back to migrate project location." )
6967
7068 # Fall back to migrate project location if we couldn't get custom location region
7169 if not custom_location_region :
7270 custom_location_region = migrate_project .get ('location' , 'eastus' )
7371 logger .warning (
74- f "Using migrate project location as fallback: { custom_location_region } " )
72+ "Using migrate project location as fallback: %s" , custom_location_region )
7573
7674 return custom_location_id , custom_location_region , target_cluster_id
7775
@@ -109,16 +107,16 @@ def ensure_target_resource_group_exists(cmd, target_resource_group_id,
109107 cmd , rg_check_uri , "2021-04-01" )
110108 if existing_rg :
111109 logger .info (
112- f "Target resource group '{ target_rg_name } ' already exists "
113- f "in subscription '{ target_subscription_id } '" )
110+ "Target resource group '%s ' already exists "
111+ "in subscription '%s'" , target_rg_name , target_subscription_id )
114112 return existing_rg
115113 except CLIError as e :
116114 error_str = str (e )
117115 if "ResourceGroupNotFound" in error_str or "404" in error_str :
118116 # Resource group doesn't exist, create it
119117 logger .info (
120- f "Target resource group '{ target_rg_name } ' not found. "
121- f "Creating in subscription '{ target_subscription_id } '..." )
118+ "Target resource group '%s ' not found. "
119+ "Creating in subscription '%s '..." , target_rg_name , target_subscription_id )
122120
123121 rg_body = {
124122 "location" : custom_location_region ,
@@ -128,18 +126,17 @@ def ensure_target_resource_group_exists(cmd, target_resource_group_id,
128126 }
129127
130128 print (
131- f "Creating target resource group '{ target_rg_name } ' "
132- f "in region '{ custom_location_region } '..." )
129+ "Creating target resource group '%s ' "
130+ "in region '%s '..." % ( target_rg_name , custom_location_region ) )
133131
134132 created_rg = create_or_update_resource (
135133 cmd , rg_check_uri , "2021-04-01" , rg_body )
136134
137- print (
138- f"✓ Target resource group '{ target_rg_name } ' created successfully" )
135+ print ("Target resource group '%s' created successfully." % target_rg_name )
139136 return created_rg
140- else :
141- # Some other error, re-raise
142- raise
137+
138+ # Re-raise if it's a different error
139+ raise
143140
144141
145142def construct_disk_and_nic_mapping (is_power_user_mode ,
@@ -262,7 +259,8 @@ def _handle_configuration_validation(cmd,
262259 APIVersion .Microsoft_DataReplication .value )
263260 if existing_item :
264261 protection_state = existing_item .get ('properties' , {}).get ('protectionState' )
265- logger .warning (f"Found existing protected item: { existing_item .get ('id' , 'unknown' )} , state: { protection_state } " )
262+ logger .warning ("Found existing protected item: %s, state: %s" ,
263+ existing_item .get ('id' , 'unknown' ), protection_state )
266264
267265 # If in failed state, offer helpful guidance
268266 if protection_state in ['EnablingFailed' , 'DisablingFailed' , 'Failed' ]:
@@ -271,14 +269,13 @@ def _handle_configuration_validation(cmd,
271269 f"Please delete it first using Azure Portal or contact Azure Support. "
272270 f"Protected item ID: { protected_item_uri } "
273271 )
274- else :
275- raise CLIError (
276- f"A replication already exists for machine '{ machine_name } ' (state: { protection_state } ). "
277- "Remove it first before creating a new one." )
272+ raise CLIError (
273+ f"A replication already exists for machine '{ machine_name } ' (state: { protection_state } ). "
274+ "Remove it first before creating a new one." )
278275 except (CLIError , ValueError , KeyError , TypeError ) as e :
279276 # Check if it's a 404 Not Found error - that's expected and fine
280277 error_str = str (e )
281- logger .info (f "Exception during protected item check: { error_str } " )
278+ logger .info ("Exception during protected item check: %s" , error_str )
282279 if ("ResourceNotFound" in error_str or "404" in error_str or
283280 "Not Found" in error_str ):
284281 existing_item = None
0 commit comments