@@ -271,7 +271,18 @@ def _secret_tag_check(resource_group_name, copy_disk_name, secreturl):
271271 _call_az_command (set_tag_command )
272272
273273
274- def _unlock_singlepass_encrypted_disk (source_vm , resource_group_name , repair_vm_name , repair_group_name , copy_disk_name , is_linux ):
274+ def _unlock_singlepass_encrypted_disk (repair_vm_name , repair_group_name , is_linux ):
275+ logger .info ('Unlocking attached copied disk...' )
276+ if is_linux :
277+ return _unlock_mount_linux_encrypted_disk (repair_vm_name , repair_group_name )
278+ return _unlock_mount_windows_encrypted_disk (repair_vm_name , repair_group_name )
279+
280+
281+ def _unlock_singlepass_encrypted_disk_fallback (source_vm , resource_group_name , repair_vm_name , repair_group_name , copy_disk_name , is_linux ):
282+ """
283+ Fallback for unlocking disk when script fails. This will install the ADE extension to unlock the Data disk.
284+ """
285+
275286 # Installs the extension on repair VM and mounts the disk after unlocking.
276287 encryption_type , key_vault , kekurl , secreturl = _fetch_encryption_settings (source_vm )
277288 if is_linux :
@@ -296,25 +307,31 @@ def _unlock_singlepass_encrypted_disk(source_vm, resource_group_name, repair_vm_
296307 # Validating secret tag and setting original tag if it got changed
297308 _secret_tag_check (resource_group_name , copy_disk_name , secreturl )
298309 logger .debug ("Manually unlocking and mounting disk for Linux VMs." )
299- _manually_unlock_mount_encrypted_disk (repair_vm_name , repair_group_name )
310+ _unlock_mount_linux_encrypted_disk (repair_vm_name , repair_group_name )
300311 except AzCommandError as azCommandError :
301312 error_message = str (azCommandError )
302313 # Linux VM encryption extension bug where it fails and then continue to mount disk manually
303314 if is_linux and "Failed to encrypt data volumes with error" in error_message :
304315 logger .debug ("Expected bug for linux VMs. Ignoring error." )
305316 # Validating secret tag and setting original tag if it got changed
306317 _secret_tag_check (resource_group_name , copy_disk_name , secreturl )
307- _manually_unlock_mount_encrypted_disk (repair_vm_name , repair_group_name )
318+ _unlock_mount_linux_encrypted_disk (repair_vm_name , repair_group_name )
308319 else :
309320 raise
310321
311322
312- def _manually_unlock_mount_encrypted_disk (repair_vm_name , repair_group_name ):
323+ def _unlock_mount_linux_encrypted_disk (repair_vm_name , repair_group_name ):
313324 # Unlocks the disk using the phasephrase and mounts it on the repair VM.
314- LINUX_RUN_SCRIPT_NAME = 'mount-encrypted-disk.sh'
325+ LINUX_RUN_SCRIPT_NAME = 'linux- mount-encrypted-disk.sh'
315326 return _invoke_run_command (LINUX_RUN_SCRIPT_NAME , repair_vm_name , repair_group_name , True )
316327
317328
329+ def _unlock_mount_windows_encrypted_disk (repair_vm_name , repair_group_name ):
330+ # Unlocks the disk using the phasephrase and mounts it on the repair VM.
331+ WINDOWS_RUN_SCRIPT_NAME = 'win-mount-encrypted-disk.ps1'
332+ return _invoke_run_command (WINDOWS_RUN_SCRIPT_NAME , repair_vm_name , repair_group_name , False )
333+
334+
318335def _fetch_compatible_windows_os_urn (source_vm ):
319336 location = source_vm .location
320337 fetch_urn_command = 'az vm image list -s "2016-Datacenter" -f WindowsServer -p MicrosoftWindowsServer -l {loc} --verbose --all --query "[?sku==\' 2016-Datacenter\' ].urn | reverse(sort(@))" -o json' .format (loc = location )
0 commit comments