Skip to content

Commit 54be25e

Browse files
committed
Addressing style issues
1 parent bc56712 commit 54be25e

File tree

11 files changed

+90
-85
lines changed

11 files changed

+90
-85
lines changed

src/migrate/HISTORY.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ Release History
1111
+++++++++++++++
1212
* Refactor codebase for improved readability and maintainability.
1313

14-
2.0.1b1
15-
+++++++++++++++
16-
* Switch to experimental version.
17-
1814
2.0.0
1915
+++++++++++++++
2016
* New version.
2117

18+
2.0.1b1
19+
+++++++++++++++
20+
* Switch to experimental version.
21+
2222
1.0.0
2323
+++++++++++++++
2424
* Initial release.

src/migrate/azext_migrate/commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ def load_command_table(self, _):
1616
g.custom_command('get', 'get_local_server_replication')
1717
g.custom_command('remove', 'remove_local_server_replication')
1818
g.custom_command('get-job', 'get_local_replication_job')
19-
19+
2020
with self.command_group('migrate local', is_preview=True) as g:
21-
g.custom_command('start-migration', 'start_local_server_migration')
21+
g.custom_command('start-migration', 'start_local_server_migration')

src/migrate/azext_migrate/custom.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,13 @@ def get_local_server_replication(cmd,
468468
# If both are provided, prefer ID
469469
if protected_item_id:
470470
return get_protected_item_by_id(cmd, protected_item_id)
471-
471+
472472
# If using name, require resource_group and project_name
473473
if not resource_group or not project_name:
474474
raise CLIError(
475475
"When using --protected-item-name, both --resource-group and "
476476
"--project-name are required.")
477-
477+
478478
return get_protected_item_by_name(
479479
cmd, subscription_id, resource_group, project_name, protected_item_name)
480480

@@ -513,6 +513,7 @@ def remove_local_server_replication(cmd,
513513
protected_item_name, force_remove
514514
)
515515

516+
516517
def start_local_server_migration(cmd,
517518
protected_item_id=None,
518519
turn_off_source_server=False,

src/migrate/azext_migrate/helpers/migration/start/_execute_migrate.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -146,30 +146,30 @@ def get_job_from_operation(cmd, subscription_id, resource_group_name,
146146
# Try to get the job name from the response headers
147147
# Azure-AsyncOperation or Location headers typically contain the operation URL
148148
headers = operation_response.headers
149-
149+
150150
# Check for Azure-AsyncOperation header
151151
async_op_url = headers.get('Azure-AsyncOperation') or headers.get('azure-asyncoperation')
152152
location_url = headers.get('Location') or headers.get('location')
153-
153+
154154
operation_url = async_op_url or location_url
155-
155+
156156
if operation_url:
157157
# Extract job name from the operation URL
158158
# URL typically ends with: .../workflows/{jobName}
159159
url_parts = operation_url.split('/')
160-
160+
161161
# Look for the job name in the URL
162162
for i, part in enumerate(url_parts):
163163
if part in ['workflows', 'operations'] and i + 1 < len(url_parts):
164164
job_name_with_params = url_parts[i + 1]
165165
# Remove query parameters and underscores
166166
job_name = job_name_with_params.split('?')[0].split('_')[0]
167-
167+
168168
logger.info(
169169
"Extracted job name '%s' from operation response",
170170
job_name
171171
)
172-
172+
173173
# Get the job details
174174
job_uri = (
175175
f"/subscriptions/{subscription_id}/"
@@ -179,20 +179,20 @@ def get_job_from_operation(cmd, subscription_id, resource_group_name,
179179
f"jobs/{job_name}?"
180180
f"api-version={APIVersion.Microsoft_DataReplication.value}"
181181
)
182-
182+
183183
full_uri = (
184184
cmd.cli_ctx.cloud.endpoints.resource_manager + job_uri
185185
)
186-
186+
187187
job_response = send_get_request(cmd, full_uri)
188188
return job_response.json()
189-
189+
190190
# If we can't extract job name, try to get it from response body
191191
if operation_response.status_code == 202:
192192
response_body = operation_response.json()
193193
if 'name' in response_body:
194194
job_name = response_body['name'].split('/')[-1].split('_')[0]
195-
195+
196196
job_uri = (
197197
f"/subscriptions/{subscription_id}/"
198198
f"resourceGroups/{resource_group_name}/"
@@ -201,11 +201,11 @@ def get_job_from_operation(cmd, subscription_id, resource_group_name,
201201
f"jobs/{job_name}?"
202202
f"api-version={APIVersion.Microsoft_DataReplication.value}"
203203
)
204-
204+
205205
full_uri = (
206206
cmd.cli_ctx.cloud.endpoints.resource_manager + job_uri
207207
)
208-
208+
209209
job_response = send_get_request(cmd, full_uri)
210210
return job_response.json()
211211

@@ -215,18 +215,17 @@ def get_job_from_operation(cmd, subscription_id, resource_group_name,
215215
)
216216
return None
217217

218-
except Exception as e:
218+
except Exception: # pylint: disable=broad-exception-caught
219219
logger.warning(
220-
"Failed to retrieve job details: %s. "
221-
"The migration may still be in progress.",
222-
str(e)
220+
"Failed to retrieve job details. "
221+
"The migration may still be in progress."
223222
)
224223
return None
225224

226225

227226
def execute_migration(cmd, subscription_id, protected_item_id,
228-
resource_group_name, vault_name, protected_item_name,
229-
turn_off_source_server):
227+
resource_group_name, vault_name, protected_item_name,
228+
turn_off_source_server):
230229
"""
231230
Execute the complete migration workflow.
232231
@@ -303,7 +302,7 @@ def execute_migration(cmd, subscription_id, protected_item_id,
303302
job_details.get('id', 'Unknown')
304303
)
305304
return job_details
306-
305+
307306
# Print success message if job details unavailable
308307
print(
309308
"Migration has been initiated successfully. "

src/migrate/azext_migrate/helpers/migration/start/_parse.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
logger = get_logger(__name__)
1414

15+
1516
def parse_protected_item_id(protected_item_id):
1617
"""
1718
Parse protected item ID to extract resource group, vault, and item name.

src/migrate/azext_migrate/helpers/migration/start/_validate.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,22 @@ def validate_arc_resource_bridge(cmd, target_cluster_id, target_subscription):
150150

151151
if not data or len(data) == 0:
152152
logger.warning(
153-
"Could not verify Arc Resource Bridge status via Resource Graph query. "
154-
f"Target cluster ID: '{target_cluster_id}'. "
155-
"Continuing with migration - the cluster and Arc Resource Bridge will be validated during the migration process."
153+
"Could not verify Arc Resource Bridge status via "
154+
"Resource Graph query. Target cluster ID: '%s'. "
155+
"Continuing with migration - the cluster and Arc Resource "
156+
"Bridge will be validated during the migration process.",
157+
target_cluster_id
156158
)
157159
# Don't fail the operation, just warn
158160
return
159161

160162
bridge_status = data[0].get('statusOfTheBridge', '')
161163
if bridge_status.lower() not in ['running', 'online']:
162164
logger.warning(
163-
f"Arc Resource Bridge status is '{bridge_status}'. "
164-
"Continuing with migration - the status will be validated during the migration process."
165+
"Arc Resource Bridge status is '%s'. "
166+
"Continuing with migration - the status will be validated "
167+
"during the migration process.",
168+
bridge_status
165169
)
166170
# Don't fail the operation, just warn
167171
return
@@ -171,9 +175,9 @@ def validate_arc_resource_bridge(cmd, target_cluster_id, target_subscription):
171175
bridge_status
172176
)
173177

174-
except Exception as e:
178+
except Exception: # pylint: disable=broad-exception-caught
175179
logger.warning(
176-
"Failed to validate Arc Resource Bridge: %s. Continuing with migration...",
177-
str(e)
180+
"Failed to validate Arc Resource Bridge. "
181+
"Continuing with migration..."
178182
)
179183
# Don't fail the operation if Arc validation fails

src/migrate/azext_migrate/helpers/replication/get/_execute_get.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def get_protected_item_by_id(cmd, protected_item_id):
5454
# Format and display the protected item
5555
formatted_item = _format_protected_item(protected_item)
5656
_print_protected_item_details(formatted_item)
57-
57+
5858
return formatted_item
5959

6060
except CLIError:
@@ -128,7 +128,7 @@ def get_protected_item_by_name(cmd, subscription_id, resource_group_name,
128128
# Format and display the protected item
129129
formatted_item = _format_protected_item(protected_item)
130130
_print_protected_item_details(formatted_item)
131-
131+
132132
return formatted_item
133133

134134
except CLIError:
@@ -152,7 +152,7 @@ def _format_protected_item(item):
152152
"""
153153
properties = item.get('properties', {})
154154
custom_properties = properties.get('customProperties', {})
155-
155+
156156
# Extract all properties
157157
formatted_item = {
158158
'id': item.get('id', 'N/A'),
@@ -189,33 +189,33 @@ def _print_protected_item_details(item):
189189
print("\n" + "=" * 120)
190190
print(f"Protected Item: {item.get('name', 'Unknown')}")
191191
print("=" * 120)
192-
192+
193193
# Basic Information
194194
print("\n[ BASIC INFORMATION ]")
195195
print(f" Name: {item.get('name', 'N/A')}")
196196
print(f" Resource ID: {item.get('id', 'N/A')}")
197197
print(f" Type: {item.get('type', 'N/A')}")
198198
print(f" Correlation ID: {item.get('correlationId', 'N/A')}")
199-
199+
200200
# Protection Status
201201
print("\n[ PROTECTION STATUS ]")
202202
print(f" Protection State: {item.get('protectionState', 'Unknown')}")
203203
print(f" Description: {item.get('protectionStateDescription', 'N/A')}")
204204
print(f" Replication Health: {item.get('replicationHealth', 'Unknown')}")
205205
print(f" Resync Required: {item.get('resynchronizationRequired', False)}")
206-
206+
207207
# Policy and Extension
208208
print("\n[ CONFIGURATION ]")
209209
print(f" Policy Name: {item.get('policyName', 'N/A')}")
210210
print(f" Replication Extension: {item.get('replicationExtensionName', 'N/A')}")
211-
211+
212212
# Failover Information
213213
print("\n[ FAILOVER HISTORY ]")
214214
print(f" Last Test Failover: {item.get('lastSuccessfulTestFailoverTime', 'N/A')}")
215215
print(f" Last Test Failover Status: {item.get('lastTestFailoverStatus', 'N/A')}")
216216
print(f" Last Planned Failover: {item.get('lastSuccessfulPlannedFailoverTime', 'N/A')}")
217217
print(f" Last Unplanned Failover: {item.get('lastSuccessfulUnplannedFailoverTime', 'N/A')}")
218-
218+
219219
# Allowed Operations
220220
allowed_jobs = item.get('allowedJobs', [])
221221
print("\n[ ALLOWED OPERATIONS ]")
@@ -224,24 +224,24 @@ def _print_protected_item_details(item):
224224
print(f" - {job}")
225225
else:
226226
print(" No operations currently allowed")
227-
227+
228228
# Custom Properties (Machine Details)
229229
custom_props = item.get('customProperties', {})
230230
if custom_props:
231231
print("\n[ MACHINE DETAILS ]")
232232
instance_type = custom_props.get('instanceType', 'N/A')
233233
print(f" Instance Type: {instance_type}")
234-
234+
235235
if instance_type != 'N/A':
236236
print(f" Source Machine Name: {custom_props.get('sourceMachineName', 'N/A')}")
237237
print(f" Target VM Name: {custom_props.get('targetVmName', 'N/A')}")
238238
print(f" Target Resource Group: {custom_props.get('targetResourceGroupId', 'N/A')}")
239239
print(f" Custom Location Region: {custom_props.get('customLocationRegion', 'N/A')}")
240-
240+
241241
# Fabric specific properties
242242
fabric_specific = custom_props.get('fabricSpecificDetails', {})
243243
if fabric_specific:
244-
print(f"\n [ Fabric Specific Details ]")
244+
print("\n [ Fabric Specific Details ]")
245245
for key, value in fabric_specific.items():
246246
# Format key name for display
247247
display_key = key.replace('_', ' ').title()
@@ -253,7 +253,7 @@ def _print_protected_item_details(item):
253253
print(f" {display_key}: {len(value)} item(s)")
254254
else:
255255
print(f" {display_key}: {value}")
256-
256+
257257
# Health Errors
258258
health_errors = item.get('healthErrors', [])
259259
if health_errors:
@@ -264,13 +264,13 @@ def _print_protected_item_details(item):
264264
severity = error.get('severity', 'Unknown')
265265
print(f" {idx}. [{severity}] {error_code}")
266266
print(f" {error_message}")
267-
267+
268268
possible_causes = error.get('possibleCauses', 'N/A')
269269
if possible_causes and possible_causes != 'N/A':
270270
print(f" Possible Causes: {possible_causes}")
271-
271+
272272
recommended_action = error.get('recommendedAction', 'N/A')
273273
if recommended_action and recommended_action != 'N/A':
274274
print(f" Recommended Action: {recommended_action}")
275-
275+
276276
print("\n" + "=" * 120 + "\n")

src/migrate/azext_migrate/helpers/replication/init/_setup_extension.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ def get_or_check_existing_extension(cmd, extension_uri,
5050
.get('provisioningState')
5151
)
5252
custom_props = (replication_extension
53-
.get('properties', {})
54-
.get('customProperties', {}))
53+
.get('properties', {})
54+
.get('customProperties', {}))
5555
existing_storage_id = custom_props.get('storageAccountId')
5656
existing_instance_type = custom_props.get('instanceType')
57-
57+
5858
# Get fabric IDs based on instance type
5959
if instance_type == AzLocalInstanceTypes.VMwareToAzLocal.value:
6060
existing_source_fabric = custom_props.get('vmwareFabricArmId')
@@ -88,17 +88,17 @@ def get_or_check_existing_extension(cmd, extension_uri,
8888
# If configuration doesn't match, we need to update it
8989
if existing_state == ProvisioningState.Succeeded.value and not config_matches:
9090
print(
91-
f"Extension exists but configuration doesn't match. "
92-
f"Will update it."
91+
"Extension exists but configuration doesn't match. "
92+
"Will update it."
9393
)
9494
if existing_storage_id != storage_account_id:
95-
print(f" - Storage account mismatch")
95+
print(" - Storage account mismatch")
9696
if existing_instance_type != instance_type:
97-
print(f" - Instance type mismatch")
97+
print(" - Instance type mismatch")
9898
if existing_source_fabric != source_fabric_id:
99-
print(f" - Source fabric mismatch")
99+
print(" - Source fabric mismatch")
100100
if existing_target_fabric != target_fabric_id:
101-
print(f" - Target fabric mismatch")
101+
print(" - Target fabric mismatch")
102102
return replication_extension, False, True # Signal to update
103103

104104
# If it's in a bad state, delete it
@@ -341,7 +341,7 @@ def setup_replication_extension(cmd, rg_uri, replication_vault_name,
341341
)
342342

343343
# Get or check existing extension
344-
(replication_extension, is_complete,
344+
(replication_extension, is_complete,
345345
needs_update) = get_or_check_existing_extension(
346346
cmd, extension_uri, replication_extension_name,
347347
storage_account_id, instance_type, source_fabric_id,

0 commit comments

Comments
 (0)