@@ -162,9 +162,8 @@ def create(cmd, vm_name, resource_group_name, repair_password=None, repair_usern
162
162
# Adding the size to the command.
163
163
create_repair_vm_command += ' --size {sku}' .format (sku = sku )
164
164
165
-
166
165
# Setting the availability zone for the repair VM.
167
- # If the source VM has availability zones, the first one is chosen for the repair VM.
166
+ # If the source VM has availability zones, the first one is chosen for the repair VM.
168
167
if source_vm .zones :
169
168
zone = source_vm .zones [0 ]
170
169
create_repair_vm_command += ' --zone {zone}' .format (zone = zone )
@@ -271,7 +270,6 @@ def create(cmd, vm_name, resource_group_name, repair_password=None, repair_usern
271
270
# Execute the command to attach the disk.
272
271
_call_az_command (attach_disk_command )
273
272
274
-
275
273
# Check if the source VM uses unmanaged disks.
276
274
# If it does, the repair VM will also be created with unmanaged disks.
277
275
else :
@@ -334,7 +332,6 @@ def create(cmd, vm_name, resource_group_name, repair_password=None, repair_usern
334
332
.format (g = repair_group_name , disk_name = copy_disk_name , vm_name = repair_vm_name , uri = copy_disk_id )
335
333
_call_az_command (attach_disk_command )
336
334
337
-
338
335
# Check if the Nested Hyper-V needs to be enabled.
339
336
# If it does, run the script to install Hyper-V and create the nested VM.
340
337
if enable_nested :
@@ -436,6 +433,10 @@ def create(cmd, vm_name, resource_group_name, repair_password=None, repair_usern
436
433
# This method is responsible for restoring the VM after repair
437
434
def restore (cmd , vm_name , resource_group_name , disk_name = None , repair_vm_id = None , yes = False ):
438
435
436
+ # Initialize repair VM variables to avoid "used before assignment" errors
437
+ repair_vm_name = None
438
+ repair_resource_group = None
439
+
439
440
# Create an instance of the command helper object to facilitate logging and status tracking.
440
441
command = command_helper (logger , cmd , 'vm repair restore' )
441
442
@@ -605,8 +606,7 @@ def run(cmd, vm_name, resource_group_name, run_id=None, repair_vm_id=None, custo
605
606
606
607
logger .info ('Running script on %s: %s' , vm_string , repair_vm_name ) # Log the VM on which the script is being run
607
608
608
-
609
- # Start the timer to measure the run-time of the script
609
+ # Start the timer to measure the run-time of the script
610
610
script_start_time = timeit .default_timer ()
611
611
612
612
# Invoke the run command on the VM and capture the standard output and error
@@ -654,7 +654,6 @@ def run(cmd, vm_name, resource_group_name, run_id=None, repair_vm_id=None, custo
654
654
# Set the overall command status to success
655
655
command .set_status_success ()
656
656
657
-
658
657
except KeyboardInterrupt :
659
658
command .error_stack_trace = traceback .format_exc ()
660
659
command .error_message = "Command interrupted by user input."
0 commit comments