From b68739c74809633eb9d358034f7884a81a2158d6 Mon Sep 17 00:00:00 2001 From: Marcus Lachmanez Date: Tue, 8 Mar 2022 10:14:03 +0100 Subject: [PATCH] Fix UUID issue for data disk (#4479) * new version 0.4.2 * new version 0.4.2 * Fixed an UUID issue by getting the data disk attached to the VM after VM creation * Fixed an UUID issue by getting the data disk attached to the VM after VM creation * Fixed an UUID issue by getting the data disk attached to the VM after VM creation * Fixed an UUID issue by getting the data disk attached to the VM after VM creation * Fixed an UUID issue by getting the data disk attached to the VM after VM creation * Fixed an UUID issue by getting the data disk attached to the VM after VM creation * Update src/vm-repair/azext_vm_repair/custom.py Co-authored-by: ZelinWang Co-authored-by: ZelinWang --- src/vm-repair/HISTORY.rst | 6 +++++- src/vm-repair/azext_vm_repair/custom.py | 12 ++++++++++-- src/vm-repair/setup.py | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/vm-repair/HISTORY.rst b/src/vm-repair/HISTORY.rst index 146f55a678c..722cba76e07 100644 --- a/src/vm-repair/HISTORY.rst +++ b/src/vm-repair/HISTORY.rst @@ -2,6 +2,10 @@ Release History =============== +0.4.2 +++++++ +Linux only: Fixing duplicated UUID issue. Data disk gets attached only after VM got created. + 0.4.1 ++++++ Fixing bug in preview parameter @@ -26,4 +30,4 @@ build environment for Rust. 0.3.5 ++++++ -Add support for nested VMs \ No newline at end of file +Add support for nested VMs diff --git a/src/vm-repair/azext_vm_repair/custom.py b/src/vm-repair/azext_vm_repair/custom.py index 51c8f61b6f5..a3c5fd7138b 100644 --- a/src/vm-repair/azext_vm_repair/custom.py +++ b/src/vm-repair/azext_vm_repair/custom.py @@ -112,8 +112,10 @@ def create(cmd, vm_name, resource_group_name, repair_password=None, repair_usern # Copy OS Disk logger.info('Copying OS disk of source VM...') copy_disk_id = _call_az_command(copy_disk_command).strip('\n') - # Add copied OS Disk to VM creat command so that the VM is created with the disk attached - create_repair_vm_command += ' --attach-data-disks {id}'.format(id=copy_disk_id) + # For Linux the disk gets not attached at VM creation time. To prevent an incorrect boot state it is required to attach the disk after the VM got created. + if not is_linux: + # Add copied OS Disk to VM creat command so that the VM is created with the disk attached + create_repair_vm_command += ' --attach-data-disks {id}'.format(id=copy_disk_id) # Validate create vm create command to validate parameters before runnning copy disk command validate_create_vm_command = create_repair_vm_command + ' --validate' logger.info('Validating VM template before continuing...') @@ -122,6 +124,12 @@ def create(cmd, vm_name, resource_group_name, repair_password=None, repair_usern logger.info('Creating repair VM...') _call_az_command(create_repair_vm_command, secure_params=[repair_password, repair_username]) + if is_linux: + # Attach copied managed disk to new vm + logger.info('Attaching copied disk to repair VM as data disk...') + attach_disk_command = "az vm disk attach -g {g} --name {disk_id} --vm-name {vm_name} ".format(g=repair_group_name, disk_id=copy_disk_id, vm_name=repair_vm_name) + _call_az_command(attach_disk_command) + # Handle encrypted VM cases if unlock_encrypted_vm: stdout, stderr = _unlock_singlepass_encrypted_disk(repair_vm_name, repair_group_name, is_linux) diff --git a/src/vm-repair/setup.py b/src/vm-repair/setup.py index 3f516a87aa3..b634d98340c 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 = "0.4.1" +VERSION = "0.4.2" CLASSIFIERS = [ 'Development Status :: 4 - Beta',