From d5a632b55b18999011e7d7bf32c28a15ec08c3c4 Mon Sep 17 00:00:00 2001 From: Sandido Date: Tue, 1 Oct 2024 14:20:49 -0400 Subject: [PATCH 01/14] dev for img 2022 default update --- src/vm-repair/azext_vm_repair/custom.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/vm-repair/azext_vm_repair/custom.py b/src/vm-repair/azext_vm_repair/custom.py index b74f7c2b06d..505eca1ecf1 100644 --- a/src/vm-repair/azext_vm_repair/custom.py +++ b/src/vm-repair/azext_vm_repair/custom.py @@ -91,10 +91,7 @@ def create(cmd, vm_name, resource_group_name, repair_password=None, repair_usern else: os_image_urn = _select_distro_linux(distro) else: - if encrypt_recovery_key: - os_image_urn = _fetch_compatible_windows_os_urn_v2(source_vm) - else: - os_image_urn = _fetch_compatible_windows_os_urn(source_vm) + os_image_urn = _fetch_compatible_windows_os_urn_v2(source_vm) os_type = 'Windows' # Set up base create vm command From ebbc80b97ba68bab0dd6be88f085ccf8ebe93956 Mon Sep 17 00:00:00 2001 From: Sandido Date: Tue, 1 Oct 2024 14:40:30 -0400 Subject: [PATCH 02/14] cleanup --- src/vm-repair/azext_vm_repair/custom.py | 5 ++-- src/vm-repair/azext_vm_repair/repair_utils.py | 23 ------------------- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/src/vm-repair/azext_vm_repair/custom.py b/src/vm-repair/azext_vm_repair/custom.py index 505eca1ecf1..c532160bc4c 100644 --- a/src/vm-repair/azext_vm_repair/custom.py +++ b/src/vm-repair/azext_vm_repair/custom.py @@ -47,8 +47,7 @@ _fetch_architecture, _select_distro_linux_Arm64, _fetch_vm_security_profile_parameters, - _fetch_osdisk_security_profile_parameters, - _fetch_compatible_windows_os_urn_v2 + _fetch_osdisk_security_profile_parameters ) from .exceptions import AzCommandError, RunScriptNotFoundForIdError, SupportingResourceNotFoundError, CommandCanceledByUserError logger = get_logger(__name__) @@ -91,7 +90,7 @@ def create(cmd, vm_name, resource_group_name, repair_password=None, repair_usern else: os_image_urn = _select_distro_linux(distro) else: - os_image_urn = _fetch_compatible_windows_os_urn_v2(source_vm) + os_image_urn = _fetch_compatible_windows_os_urn(source_vm) os_type = 'Windows' # Set up base create vm command diff --git a/src/vm-repair/azext_vm_repair/repair_utils.py b/src/vm-repair/azext_vm_repair/repair_utils.py index 1721c321879..e5d056caae2 100644 --- a/src/vm-repair/azext_vm_repair/repair_utils.py +++ b/src/vm-repair/azext_vm_repair/repair_utils.py @@ -477,29 +477,6 @@ def _unlock_mount_windows_encrypted_disk(repair_vm_name, repair_group_name, encr def _fetch_compatible_windows_os_urn(source_vm): location = source_vm.location - 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) - logger.info('Fetching compatible Windows OS images from gallery...') - urns = loads(_call_az_command(fetch_urn_command)) - - # No OS images available for Windows2016 - if not urns: - raise WindowsOsNotAvailableError() - - logger.debug('Fetched Urns:\n%s', urns) - # temp fix to mitigate Windows disk signature collision error - os_image_ref = source_vm.storage_profile.image_reference - if os_image_ref and isinstance(os_image_ref.version, str) and os_image_ref.version in urns[0]: - if len(urns) < 2: - logger.debug('Avoiding Win2016 latest image due to expected disk collision. But no other image available.') - raise WindowsOsNotAvailableError() - logger.debug('Returning Urn 1 to avoid disk collision error: %s', urns[1]) - return urns[1] - logger.debug('Returning Urn 0: %s', urns[0]) - return urns[0] - - -def _fetch_compatible_windows_os_urn_v2(source_vm): - location = source_vm.location # We will prefer to fetch image using source vm sku, that we match the CVM requirements. if source_vm.storage_profile is not None and source_vm.storage_profile.image_reference is not None: From e16aca40978b7d7fd7cdbb3921e753da24c92d21 Mon Sep 17 00:00:00 2001 From: Sandido Date: Tue, 1 Oct 2024 14:47:24 -0400 Subject: [PATCH 03/14] versioning --- src/vm-repair/HISTORY.rst | 4 ++++ src/vm-repair/setup.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/vm-repair/HISTORY.rst b/src/vm-repair/HISTORY.rst index 791548465b0..f226b4acb93 100644 --- a/src/vm-repair/HISTORY.rst +++ b/src/vm-repair/HISTORY.rst @@ -2,6 +2,10 @@ Release History =============== +2.0.0 +++++++ +Changed the default image for Windows VMs when the source image cannot be found to a Windows 2022 sku as opposed to Windows 2016. + 1.0.9 ++++++ Fixed and updated several vm-repair tests for better coverage. diff --git a/src/vm-repair/setup.py b/src/vm-repair/setup.py index ef8a0baaaa6..96bd38441c5 100644 --- a/src/vm-repair/setup.py +++ b/src/vm-repair/setup.py @@ -8,7 +8,7 @@ from codecs import open from setuptools import setup, find_packages -VERSION = "1.0.9" +VERSION = "1.1.0" CLASSIFIERS = [ 'Development Status :: 4 - Beta', From 26e02b32dd0502db438fba43452f7c8dc5d32565 Mon Sep 17 00:00:00 2001 From: Sandido Date: Wed, 9 Oct 2024 13:07:36 -0400 Subject: [PATCH 04/14] testing purposes on 2022 img repair vms, this ensures 2022 is used for testing purposes --- src/vm-repair/azext_vm_repair/repair_utils.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/vm-repair/azext_vm_repair/repair_utils.py b/src/vm-repair/azext_vm_repair/repair_utils.py index e5d056caae2..f050c305f8f 100644 --- a/src/vm-repair/azext_vm_repair/repair_utils.py +++ b/src/vm-repair/azext_vm_repair/repair_utils.py @@ -479,19 +479,19 @@ def _fetch_compatible_windows_os_urn(source_vm): location = source_vm.location # We will prefer to fetch image using source vm sku, that we match the CVM requirements. - if source_vm.storage_profile is not None and source_vm.storage_profile.image_reference is not None: - sku = source_vm.storage_profile.image_reference.sku - offer = source_vm.storage_profile.image_reference.offer - publisher = source_vm.storage_profile.image_reference.publisher - fetch_urn_command = 'az vm image list -s {sku} -f {offer} -p {publisher} -l {loc} --verbose --all --query "[?sku==\'{sku}\'].urn | reverse(sort(@))" -o json'.format(loc=location, sku=sku, offer=offer, publisher=publisher) - logger.info('Fetching compatible Windows OS images from gallery...') - urns = loads(_call_az_command(fetch_urn_command)) - - if not urns or len(urns) == 0: + # if source_vm.storage_profile is not None and source_vm.storage_profile.image_reference is not None: + # sku = source_vm.storage_profile.image_reference.sku + # offer = source_vm.storage_profile.image_reference.offer + # publisher = source_vm.storage_profile.image_reference.publisher + # fetch_urn_command = 'az vm image list -s {sku} -f {offer} -p {publisher} -l {loc} --verbose --all --query "[?sku==\'{sku}\'].urn | reverse(sort(@))" -o json'.format(loc=location, sku=sku, offer=offer, publisher=publisher) + # logger.info('Fetching compatible Windows OS images from gallery...') + # urns = loads(_call_az_command(fetch_urn_command)) + + # if not urns or len(urns) == 0: # If source SKU not available then defaulting 2022 datacenter image. - fetch_urn_command = 'az vm image list -s "2022-Datacenter" -f WindowsServer -p MicrosoftWindowsServer -l {loc} --verbose --all --query "[?sku==\'2022-datacenter\'].urn | reverse(sort(@))" -o json'.format(loc=location) - logger.info('Fetching compatible Windows OS images from gallery for 2022 Datacenter...') - urns = loads(_call_az_command(fetch_urn_command)) + fetch_urn_command = 'az vm image list -s "2022-Datacenter" -f WindowsServer -p MicrosoftWindowsServer -l {loc} --verbose --all --query "[?sku==\'2022-datacenter\'].urn | reverse(sort(@))" -o json'.format(loc=location) + logger.info('Fetching compatible Windows OS images from gallery for 2022 Datacenter...') + urns = loads(_call_az_command(fetch_urn_command)) # No OS images available for Windows2016 if not urns: From 3e6a52b00cca3f9ba56bc73e0c8add6ec551bbf1 Mon Sep 17 00:00:00 2001 From: Adam Sandor Date: Mon, 14 Oct 2024 14:05:34 -0400 Subject: [PATCH 05/14] Update HISTORY.rst --- src/vm-repair/HISTORY.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/vm-repair/HISTORY.rst b/src/vm-repair/HISTORY.rst index dcb311f2471..73732e1939f 100644 --- a/src/vm-repair/HISTORY.rst +++ b/src/vm-repair/HISTORY.rst @@ -1,6 +1,10 @@ Release History =============== +2.0.0 +++++++ +Changed default VM image to 2019-datacenter-gs for better default security. + 1.1.0 ++++++ Added script for GT fixit button From 4e09de4b818d35c0661cc5869b95be2480330dbe Mon Sep 17 00:00:00 2001 From: Adam Sandor Date: Mon, 14 Oct 2024 14:09:18 -0400 Subject: [PATCH 06/14] Update HISTORY.rst --- src/vm-repair/HISTORY.rst | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/vm-repair/HISTORY.rst b/src/vm-repair/HISTORY.rst index 73732e1939f..62906dbc5f2 100644 --- a/src/vm-repair/HISTORY.rst +++ b/src/vm-repair/HISTORY.rst @@ -13,10 +13,6 @@ Added script for GT fixit button ++++++ Added breaking change warning for the default image for Windows source VMs if the source VM image is not found in `az vm repair create`. It will change from a 2016 image to 2022 in November 2024. -2.0.0 -++++++ -Changed the default image for Windows VMs when the source image cannot be found to a Windows 2022 sku as opposed to Windows 2016. - 1.0.9 ++++++ Fixed and updated several vm-repair tests for better coverage. From cc40444748b3805dd24d72ded8c5497a6632ac5f Mon Sep 17 00:00:00 2001 From: Sandido Date: Mon, 14 Oct 2024 15:14:43 -0400 Subject: [PATCH 07/14] use 2019 --- src/vm-repair/azext_vm_repair/custom.py | 8 +++- src/vm-repair/azext_vm_repair/repair_utils.py | 37 +++++++++++++++---- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/vm-repair/azext_vm_repair/custom.py b/src/vm-repair/azext_vm_repair/custom.py index c532160bc4c..e0c8753ad9d 100644 --- a/src/vm-repair/azext_vm_repair/custom.py +++ b/src/vm-repair/azext_vm_repair/custom.py @@ -25,6 +25,7 @@ _list_resource_ids_in_rg, _get_repair_resource_tag, _fetch_compatible_windows_os_urn, + _fetch_compatible_windows_os_urn_v2, _fetch_run_script_map, _fetch_run_script_path, _process_ps_parameters, @@ -90,8 +91,13 @@ def create(cmd, vm_name, resource_group_name, repair_password=None, repair_usern else: os_image_urn = _select_distro_linux(distro) else: - os_image_urn = _fetch_compatible_windows_os_urn(source_vm) os_type = 'Windows' + if encrypt_recovery_key: + # Call the new URN matching logic. + os_image_urn = _fetch_compatible_windows_os_urn_v2(source_vm) + else: + # Use the old default to 2019 logic. + os_image_urn = _fetch_compatible_windows_os_urn(source_vm) # Set up base create vm command if is_linux: diff --git a/src/vm-repair/azext_vm_repair/repair_utils.py b/src/vm-repair/azext_vm_repair/repair_utils.py index f050c305f8f..0b4565862f8 100644 --- a/src/vm-repair/azext_vm_repair/repair_utils.py +++ b/src/vm-repair/azext_vm_repair/repair_utils.py @@ -477,15 +477,38 @@ def _unlock_mount_windows_encrypted_disk(repair_vm_name, repair_group_name, encr def _fetch_compatible_windows_os_urn(source_vm): location = source_vm.location + fetch_urn_command = 'az vm image list -s "2019-Datacenter-gs" -f WindowsServer -p MicrosoftWindowsServer -l {loc} --verbose --all --query "[?sku==\'2019-Datacenter-gs\'].urn | reverse(sort(@))" -o json'.format(loc=location) + logger.info('Fetching compatible Windows OS images from gallery...') + urns = loads(_call_az_command(fetch_urn_command)) + + # No OS images available for Windows2016 + if not urns: + raise WindowsOsNotAvailableError() + + logger.debug('Fetched Urns:\n%s', urns) + # temp fix to mitigate Windows disk signature collision error + os_image_ref = source_vm.storage_profile.image_reference + if os_image_ref and isinstance(os_image_ref.version, str) and os_image_ref.version in urns[0]: + if len(urns) < 2: + logger.debug('Avoiding Win2019 latest image due to expected disk collision. But no other image available.') + raise WindowsOsNotAvailableError() + logger.debug('Returning Urn 1 to avoid disk collision error: %s', urns[1]) + return urns[1] + logger.debug('Returning Urn 0: %s', urns[0]) + return urns[0] + + +def _fetch_compatible_windows_os_urn_v2(source_vm): + location = source_vm.location # We will prefer to fetch image using source vm sku, that we match the CVM requirements. - # if source_vm.storage_profile is not None and source_vm.storage_profile.image_reference is not None: - # sku = source_vm.storage_profile.image_reference.sku - # offer = source_vm.storage_profile.image_reference.offer - # publisher = source_vm.storage_profile.image_reference.publisher - # fetch_urn_command = 'az vm image list -s {sku} -f {offer} -p {publisher} -l {loc} --verbose --all --query "[?sku==\'{sku}\'].urn | reverse(sort(@))" -o json'.format(loc=location, sku=sku, offer=offer, publisher=publisher) - # logger.info('Fetching compatible Windows OS images from gallery...') - # urns = loads(_call_az_command(fetch_urn_command)) + if source_vm.storage_profile is not None and source_vm.storage_profile.image_reference is not None: + sku = source_vm.storage_profile.image_reference.sku + offer = source_vm.storage_profile.image_reference.offer + publisher = source_vm.storage_profile.image_reference.publisher + fetch_urn_command = 'az vm image list -s {sku} -f {offer} -p {publisher} -l {loc} --verbose --all --query "[?sku==\'{sku}\'].urn | reverse(sort(@))" -o json'.format(loc=location, sku=sku, offer=offer, publisher=publisher) + logger.info('Fetching compatible Windows OS images from gallery...') + urns = loads(_call_az_command(fetch_urn_command)) # if not urns or len(urns) == 0: # If source SKU not available then defaulting 2022 datacenter image. From 1bb4a35e87db0aeb9578aea3b928a5fcd672e694 Mon Sep 17 00:00:00 2001 From: Sandido Date: Tue, 15 Oct 2024 14:00:26 -0400 Subject: [PATCH 08/14] fix bad comment out --- src/vm-repair/azext_vm_repair/repair_utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/vm-repair/azext_vm_repair/repair_utils.py b/src/vm-repair/azext_vm_repair/repair_utils.py index 0b4565862f8..bd5bf92c033 100644 --- a/src/vm-repair/azext_vm_repair/repair_utils.py +++ b/src/vm-repair/azext_vm_repair/repair_utils.py @@ -510,11 +510,11 @@ def _fetch_compatible_windows_os_urn_v2(source_vm): logger.info('Fetching compatible Windows OS images from gallery...') urns = loads(_call_az_command(fetch_urn_command)) - # if not urns or len(urns) == 0: + if not urns or len(urns) == 0: # If source SKU not available then defaulting 2022 datacenter image. - fetch_urn_command = 'az vm image list -s "2022-Datacenter" -f WindowsServer -p MicrosoftWindowsServer -l {loc} --verbose --all --query "[?sku==\'2022-datacenter\'].urn | reverse(sort(@))" -o json'.format(loc=location) - logger.info('Fetching compatible Windows OS images from gallery for 2022 Datacenter...') - urns = loads(_call_az_command(fetch_urn_command)) + fetch_urn_command = 'az vm image list -s "2022-Datacenter" -f WindowsServer -p MicrosoftWindowsServer -l {loc} --verbose --all --query "[?sku==\'2022-datacenter\'].urn | reverse(sort(@))" -o json'.format(loc=location) + logger.info('Fetching compatible Windows OS images from gallery for 2022 Datacenter...') + urns = loads(_call_az_command(fetch_urn_command)) # No OS images available for Windows2016 if not urns: From a95391c41cd4ebfcb791db0ae094cb8b309d8aaf Mon Sep 17 00:00:00 2001 From: Sandido Date: Thu, 17 Oct 2024 10:45:31 -0400 Subject: [PATCH 09/14] test and extra debug --- src/vm-repair/azext_vm_repair/repair_utils.py | 11 +++- .../tests/latest/test_repair_commands.py | 56 ++++++++++++++++++- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/vm-repair/azext_vm_repair/repair_utils.py b/src/vm-repair/azext_vm_repair/repair_utils.py index bd5bf92c033..c9e877aef6f 100644 --- a/src/vm-repair/azext_vm_repair/repair_utils.py +++ b/src/vm-repair/azext_vm_repair/repair_utils.py @@ -477,7 +477,7 @@ def _unlock_mount_windows_encrypted_disk(repair_vm_name, repair_group_name, encr def _fetch_compatible_windows_os_urn(source_vm): location = source_vm.location - fetch_urn_command = 'az vm image list -s "2019-Datacenter-gs" -f WindowsServer -p MicrosoftWindowsServer -l {loc} --verbose --all --query "[?sku==\'2019-Datacenter-gs\'].urn | reverse(sort(@))" -o json'.format(loc=location) + fetch_urn_command = 'az vm image list -s "2019-datacenter-gs" -f WindowsServer -p MicrosoftWindowsServer -l {loc} --verbose --all --query "[?sku==\'2019-datacenter-gs\'].urn | reverse(sort(@))" -o json'.format(loc=location) logger.info('Fetching compatible Windows OS images from gallery...') urns = loads(_call_az_command(fetch_urn_command)) @@ -490,7 +490,7 @@ def _fetch_compatible_windows_os_urn(source_vm): os_image_ref = source_vm.storage_profile.image_reference if os_image_ref and isinstance(os_image_ref.version, str) and os_image_ref.version in urns[0]: if len(urns) < 2: - logger.debug('Avoiding Win2019 latest image due to expected disk collision. But no other image available.') + logger.debug('Avoiding Win2019 GS latest image due to expected disk collision. But no other image available.') raise WindowsOsNotAvailableError() logger.debug('Returning Urn 1 to avoid disk collision error: %s', urns[1]) return urns[1] @@ -741,6 +741,13 @@ def _create_repair_vm(copy_disk_id, create_repair_vm_command, repair_password, r if not fix_uuid: create_repair_vm_command += ' --attach-data-disks {id}'.format(id=copy_disk_id) + + logger.debug('Creating repair VM with command: {}'.format(create_repair_vm_command)) + logger.debug('copy_disk_id: {}'.format(copy_disk_id)) + logger.debug('repair_password: {}'.format(repair_password)) + logger.debug('repair_username: {}'.format(repair_username)) + logger.debug('fix_uuid: {}'.format(fix_uuid)) + logger.info('Validating VM template before continuing...') _call_az_command(create_repair_vm_command + ' --validate', secure_params=[repair_password, repair_username]) logger.info('Creating repair VM...') diff --git a/src/vm-repair/azext_vm_repair/tests/latest/test_repair_commands.py b/src/vm-repair/azext_vm_repair/tests/latest/test_repair_commands.py index 1ed6af091c3..634887e803c 100644 --- a/src/vm-repair/azext_vm_repair/tests/latest/test_repair_commands.py +++ b/src/vm-repair/azext_vm_repair/tests/latest/test_repair_commands.py @@ -870,4 +870,58 @@ def test_vmrepair_ConfidentialVMAndUnlockDisk(self, resource_group): # Check swapped OS disk vms = self.cmd('vm list -g {rg} -o json').get_output_in_json() source_vm = vms[0] - assert source_vm['storageProfile']['osDisk']['name'] == result['copied_disk_name'] \ No newline at end of file + assert source_vm['storageProfile']['osDisk']['name'] == result['copied_disk_name'] + +@pytest.mark.winDefaultGen1Image +class WindowsDefaultGen1Image(LiveScenarioTest): + + @ResourceGroupPreparer(location='westus2') + def test_vmrepair_DefaultGen1Image(self, resource_group): + import uuid + import secrets + import string + base_password = "Passw0rd2024" + guid_suffix = str(uuid.uuid4()) + secure_password = base_password + guid_suffix + username_length = 8 + secure_username = ''.join(secrets.choice(string.ascii_letters + string.digits) for _ in range(username_length)) + self.kwargs.update({ + 'vm': 'vm1', + 'admin_password': secure_password, + 'admin_username': secure_username + }) + + # Create test VM + self.cmd('vm create -g {rg} -n {vm} --admin-username {admin_username} --admin-password {admin_password} --image MicrosoftWindowsServer:windowsserver:2019-datacenter-gs:latest') + vms = self.cmd('vm list -g {rg} -o json').get_output_in_json() + # Something wrong with vm create command if it fails here + assert len(vms) == 1 + + # Create Repair VM + repair_vm = self.cmd('vm repair create -g {rg} -n {vm} --repair-username {admin_username} --repair-password {admin_password} --yes -o json').get_output_in_json() + assert repair_vm['status'] == STATUS_SUCCESS, repair_vm['error_message'] + # Check repair VM + self.kwargs.update({ + 'vm': 'vm1', + 'admin_password': secure_password, + 'admin_username': secure_username, + 'repair_resource_group': repair_vm['repair_resource_group'] + }) + repair_vms = self.cmd('vm list -g {repair_resource_group} -o json').get_output_in_json() + assert len(repair_vms) == 1 + repair_vm = repair_vms[0] + print("dumping repair vm json!!!!!!!!!!!!!!!") + print(json.dumps(repair_vm)) + repair_vm_id = repair_vm['id'] + self.kwargs.update({ + 'vm': 'vm1', + 'admin_password': secure_password, + 'admin_username': secure_username, + 'repair_vm_id': repair_vm_id + }) + # Run a script for testing repair-vm-id + result_run = self.cmd('vm repair run -g {rg} -n {vm} --run-id win-hello-world --repair-vm-id {repair_vm_id} --run-on-repair -o json').get_output_in_json() + assert result_run['status'] == STATUS_SUCCESS, result_run['error_message'] + + # Call Restore + self.cmd('vm repair restore -g {rg} -n {vm} --yes') \ No newline at end of file From 05a250ee3bfa878ead8e8db04469ee0a4e10c162 Mon Sep 17 00:00:00 2001 From: Sandido Date: Wed, 23 Oct 2024 13:29:24 -0400 Subject: [PATCH 10/14] 2022 smalldisk image default --- src/vm-repair/azext_vm_repair/repair_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm-repair/azext_vm_repair/repair_utils.py b/src/vm-repair/azext_vm_repair/repair_utils.py index c9e877aef6f..3ac8afceece 100644 --- a/src/vm-repair/azext_vm_repair/repair_utils.py +++ b/src/vm-repair/azext_vm_repair/repair_utils.py @@ -477,7 +477,7 @@ def _unlock_mount_windows_encrypted_disk(repair_vm_name, repair_group_name, encr def _fetch_compatible_windows_os_urn(source_vm): location = source_vm.location - fetch_urn_command = 'az vm image list -s "2019-datacenter-gs" -f WindowsServer -p MicrosoftWindowsServer -l {loc} --verbose --all --query "[?sku==\'2019-datacenter-gs\'].urn | reverse(sort(@))" -o json'.format(loc=location) + fetch_urn_command = 'az vm image list -s "2022-datacenter-smalldisk" -f WindowsServer -p MicrosoftWindowsServer -l {loc} --verbose --all --query "[?sku==\'2022-datacenter-smalldisk\'].urn | reverse(sort(@))" -o json'.format(loc=location) logger.info('Fetching compatible Windows OS images from gallery...') urns = loads(_call_az_command(fetch_urn_command)) From d6c10ba0584f972ed473522d96ae5caca1c2e070 Mon Sep 17 00:00:00 2001 From: Adam Sandor Date: Wed, 23 Oct 2024 16:36:22 -0400 Subject: [PATCH 11/14] Update repair_utils.py --- src/vm-repair/azext_vm_repair/repair_utils.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/vm-repair/azext_vm_repair/repair_utils.py b/src/vm-repair/azext_vm_repair/repair_utils.py index eff75a4a265..89c2a3b3a84 100644 --- a/src/vm-repair/azext_vm_repair/repair_utils.py +++ b/src/vm-repair/azext_vm_repair/repair_utils.py @@ -743,12 +743,6 @@ def _create_repair_vm(copy_disk_id, create_repair_vm_command, repair_password, r if not fix_uuid: create_repair_vm_command += ' --attach-data-disks {id}'.format(id=copy_disk_id) - logger.debug('Creating repair VM with command: {}'.format(create_repair_vm_command)) - logger.debug('copy_disk_id: {}'.format(copy_disk_id)) - logger.debug('repair_password: {}'.format(repair_password)) - logger.debug('repair_username: {}'.format(repair_username)) - logger.debug('fix_uuid: {}'.format(fix_uuid)) - logger.info('Validating VM template before continuing...') _call_az_command(create_repair_vm_command + ' --validate', secure_params=[repair_password, repair_username]) logger.info('Creating repair VM...') From a96df8938369743c0c188a13c9a248f602baf380 Mon Sep 17 00:00:00 2001 From: Adam Sandor Date: Wed, 23 Oct 2024 16:37:43 -0400 Subject: [PATCH 12/14] Update repair_utils.py, remove secure logs --- src/vm-repair/azext_vm_repair/repair_utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/vm-repair/azext_vm_repair/repair_utils.py b/src/vm-repair/azext_vm_repair/repair_utils.py index 89c2a3b3a84..960fd2c77d2 100644 --- a/src/vm-repair/azext_vm_repair/repair_utils.py +++ b/src/vm-repair/azext_vm_repair/repair_utils.py @@ -733,11 +733,9 @@ def _unlock_encrypted_vm_run(repair_vm_name, repair_group_name, is_linux, encryp def _create_repair_vm(copy_disk_id, create_repair_vm_command, repair_password, repair_username, fix_uuid=False): - # logging all parameters of the function individually + # logging parameters of the function individually logger.info('Creating repair VM with command: {}'.format(create_repair_vm_command)) logger.info('copy_disk_id: {}'.format(copy_disk_id)) - logger.info('repair_password: {}'.format(repair_password)) - logger.info('repair_username: {}'.format(repair_username)) logger.info('fix_uuid: {}'.format(fix_uuid)) if not fix_uuid: From 5d02a28b48ebd50e98194339d16dd7876e0e5532 Mon Sep 17 00:00:00 2001 From: Adam Sandor Date: Wed, 23 Oct 2024 16:38:44 -0400 Subject: [PATCH 13/14] Update repair_utils.py --- src/vm-repair/azext_vm_repair/repair_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm-repair/azext_vm_repair/repair_utils.py b/src/vm-repair/azext_vm_repair/repair_utils.py index 960fd2c77d2..c2bfdb6fd34 100644 --- a/src/vm-repair/azext_vm_repair/repair_utils.py +++ b/src/vm-repair/azext_vm_repair/repair_utils.py @@ -491,7 +491,7 @@ def _fetch_compatible_windows_os_urn(source_vm): os_image_ref = source_vm.storage_profile.image_reference if os_image_ref and isinstance(os_image_ref.version, str) and os_image_ref.version in urns[0]: if len(urns) < 2: - logger.debug('Avoiding Win2019 GS latest image due to expected disk collision. But no other image available.') + logger.debug('Avoiding Win2022-datacenter-smalldisk latest image due to expected disk collision. But no other image available.') raise WindowsOsNotAvailableError() logger.debug('Returning Urn 1 to avoid disk collision error: %s', urns[1]) return urns[1] From 1c973ca2137f10a2558fe77dd0e0dae38197c80b Mon Sep 17 00:00:00 2001 From: Adam Sandor Date: Fri, 25 Oct 2024 10:19:36 -0400 Subject: [PATCH 14/14] Update custom.py --- src/vm-repair/azext_vm_repair/custom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vm-repair/azext_vm_repair/custom.py b/src/vm-repair/azext_vm_repair/custom.py index 62bc1269a8b..0c0a644a13a 100644 --- a/src/vm-repair/azext_vm_repair/custom.py +++ b/src/vm-repair/azext_vm_repair/custom.py @@ -97,7 +97,7 @@ def create(cmd, vm_name, resource_group_name, repair_password=None, repair_usern # Call the new URN matching logic. os_image_urn = _fetch_compatible_windows_os_urn_v2(source_vm) else: - # Use the old default to 2019 logic. + # Use the old default to 2022 image logic. os_image_urn = _fetch_compatible_windows_os_urn(source_vm) # Set up base create vm command