-
Notifications
You must be signed in to change notification settings - Fork 3.4k
{Compute} az vmss disk: Migrate command group to aaz-based implementation
#32858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
william051200
wants to merge
4
commits into
Azure:dev
Choose a base branch
from
william051200:vmss-disk-migration
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+92
−51
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5087,68 +5087,109 @@ def attach_managed_data_disk_to_vmss(cmd, resource_group_name, vmss_name, size_g | |||||||||
| caching=None, disk=None, sku=None): | ||||||||||
|
|
||||||||||
| def _init_data_disk(storage_profile, lun, existing_disk=None): | ||||||||||
| data_disks = storage_profile.data_disks or [] | ||||||||||
| from ._vm_utils import DiskCreateOptionTypes | ||||||||||
| data_disks = storage_profile.get('dataDisks', []) | ||||||||||
| if lun is None: | ||||||||||
| lun = _get_disk_lun(data_disks) | ||||||||||
| lun = _get_disk_lun_by_aaz(data_disks) | ||||||||||
| if existing_disk is None: | ||||||||||
| data_disk = DataDisk(lun=lun, create_option=DiskCreateOptionTypes.empty, disk_size_gb=size_gb, | ||||||||||
| caching=caching, managed_disk=ManagedDiskParameters(storage_account_type=sku)) | ||||||||||
| data_disk = { | ||||||||||
| 'caching': caching, | ||||||||||
| 'create_option': DiskCreateOptionTypes.EMPTY.value, | ||||||||||
| 'disk_size_gb': size_gb, | ||||||||||
| 'lun': lun, | ||||||||||
| 'managed_disk': { | ||||||||||
| 'storage_account_type': sku | ||||||||||
| } | ||||||||||
| } | ||||||||||
| else: | ||||||||||
| data_disk = DataDisk(lun=lun, create_option=DiskCreateOptionTypes.attach, caching=caching, | ||||||||||
| managed_disk=ManagedDiskParameters(id=existing_disk, storage_account_type=sku)) | ||||||||||
| data_disk = { | ||||||||||
| 'caching': caching, | ||||||||||
| 'create_option': DiskCreateOptionTypes.ATTACH.value, | ||||||||||
| 'lun': lun, | ||||||||||
| 'managed_disk': { | ||||||||||
| 'id': existing_disk, | ||||||||||
| 'storage_account_type': sku | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| data_disks.append(data_disk) | ||||||||||
| storage_profile.data_disks = data_disks | ||||||||||
|
|
||||||||||
| DiskCreateOptionTypes, ManagedDiskParameters = cmd.get_models( | ||||||||||
| 'DiskCreateOptionTypes', 'ManagedDiskParameters') | ||||||||||
| if disk is None: | ||||||||||
| DataDisk = cmd.get_models('VirtualMachineScaleSetDataDisk') | ||||||||||
| else: | ||||||||||
| DataDisk = cmd.get_models('DataDisk') | ||||||||||
| storage_profile['dataDisks'] = data_disks | ||||||||||
|
|
||||||||||
| client = _compute_client_factory(cmd.cli_ctx) | ||||||||||
| if instance_id is None: | ||||||||||
| vmss = client.virtual_machine_scale_sets.get(resource_group_name, vmss_name) | ||||||||||
| from .operations.vmss import VMSSCreate, convert_show_result_to_snake_case | ||||||||||
| vmss = get_vmss_by_aaz(cmd, resource_group_name, vmss_name) | ||||||||||
| # Avoid unnecessary permission error | ||||||||||
| vmss.virtual_machine_profile.storage_profile.image_reference = None | ||||||||||
| if 'virtualMachineProfile' not in vmss: | ||||||||||
| vmss['virtualMachineProfile'] = {} | ||||||||||
| if 'storageProfile' not in vmss['virtualMachineProfile']: | ||||||||||
| vmss['virtualMachineProfile']['storageProfile'] = {} | ||||||||||
| vmss['virtualMachineProfile']['storageProfile']['imageReference'] = None | ||||||||||
| # pylint: disable=no-member | ||||||||||
| _init_data_disk(vmss.virtual_machine_profile.storage_profile, lun) | ||||||||||
| return client.virtual_machine_scale_sets.begin_create_or_update(resource_group_name, vmss_name, vmss) | ||||||||||
| _init_data_disk(vmss['virtualMachineProfile']['storageProfile'], lun) | ||||||||||
| vmss = convert_show_result_to_snake_case(vmss) | ||||||||||
| vmss['resource_group'] = resource_group_name | ||||||||||
| vmss['vm_scale_set_name'] = vmss_name | ||||||||||
| return VMSSCreate(cli_ctx=cmd.cli_ctx)(command_args=vmss) | ||||||||||
|
|
||||||||||
| vmss_vm = client.virtual_machine_scale_set_vms.get(resource_group_name, vmss_name, instance_id) | ||||||||||
| from .operations.vmss_vms import VMSSVMSShow, VMSSVMSCreate, convert_show_result_to_snake_case | ||||||||||
| command_args = { | ||||||||||
| 'resource_group': resource_group_name, | ||||||||||
| 'vm_scale_set_name': vmss_name, | ||||||||||
| 'instance_id': instance_id | ||||||||||
| } | ||||||||||
| vmss_vm = VMSSVMSShow(cli_ctx=cmd.cli_ctx)(command_args=command_args) | ||||||||||
| # Avoid unnecessary permission error | ||||||||||
| vmss_vm.storage_profile.image_reference = None | ||||||||||
| _init_data_disk(vmss_vm.storage_profile, lun, disk) | ||||||||||
| return client.virtual_machine_scale_set_vms.begin_update(resource_group_name, vmss_name, instance_id, vmss_vm) | ||||||||||
| if 'storageProfile' not in vmss_vm: | ||||||||||
| vmss_vm['storageProfile'] = {} | ||||||||||
| vmss_vm['storageProfile']['imageReference'] = None | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| _init_data_disk(vmss_vm['storageProfile'], lun, disk) | ||||||||||
| vmss_vm = convert_show_result_to_snake_case(vmss_vm) | ||||||||||
| vmss_vm['resource_group'] = resource_group_name | ||||||||||
| vmss_vm['vm_scale_set_name'] = vmss_name | ||||||||||
| vmss_vm['instance_id'] = instance_id | ||||||||||
| return VMSSVMSCreate(cli_ctx=cmd.cli_ctx)(command_args=vmss_vm) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def detach_disk_from_vmss(cmd, resource_group_name, vmss_name, lun, instance_id=None): | ||||||||||
| client = _compute_client_factory(cmd.cli_ctx) | ||||||||||
| from .operations.vmss import VMSSCreate, convert_show_result_to_snake_case as VMSSConvert | ||||||||||
| from .operations.vmss_vms import VMSSVMSShow, VMSSVMSCreate, convert_show_result_to_snake_case as VMSSVMSConvert | ||||||||||
| if instance_id is None: | ||||||||||
| vmss = client.virtual_machine_scale_sets.get(resource_group_name, vmss_name) | ||||||||||
| vmss = get_vmss_by_aaz(cmd, resource_group_name, vmss_name) | ||||||||||
| # Avoid unnecessary permission error | ||||||||||
| vmss.virtual_machine_profile.storage_profile.image_reference = None | ||||||||||
| vmss['virtualMachineProfile']['storageProfile']['imageReference'] = None | ||||||||||
| # pylint: disable=no-member | ||||||||||
| data_disks = vmss.virtual_machine_profile.storage_profile.data_disks | ||||||||||
| data_disks = vmss.get('virtualMachineProfile', {}).get('storageProfile', {}).get('dataDisks', []) | ||||||||||
| else: | ||||||||||
| vmss_vm = client.virtual_machine_scale_set_vms.get(resource_group_name, vmss_name, instance_id) | ||||||||||
| command_args = { | ||||||||||
| 'resource_group': resource_group_name, | ||||||||||
| 'vm_scale_set_name': vmss_name, | ||||||||||
| 'instance_id': instance_id | ||||||||||
| } | ||||||||||
| vmss_vm = VMSSVMSShow(cli_ctx=cmd.cli_ctx)(command_args=command_args) | ||||||||||
| # Avoid unnecessary permission error | ||||||||||
| vmss_vm.storage_profile.image_reference = None | ||||||||||
| data_disks = vmss_vm.storage_profile.data_disks | ||||||||||
| vmss_vm['storageProfile']['imageReference'] = None | ||||||||||
| data_disks = vmss_vm.get('storageProfile', {}).get('dataDisks', []) | ||||||||||
|
|
||||||||||
| if not data_disks: | ||||||||||
| raise CLIError("Data disk doesn't exist") | ||||||||||
|
|
||||||||||
| leftovers = [d for d in data_disks if d.lun != lun] | ||||||||||
| leftovers = [d for d in data_disks if d['lun'] != lun] | ||||||||||
| if len(data_disks) == len(leftovers): | ||||||||||
| raise CLIError("Could not find the data disk with lun '{}'".format(lun)) | ||||||||||
|
|
||||||||||
| if instance_id is None: | ||||||||||
| vmss.virtual_machine_profile.storage_profile.data_disks = leftovers | ||||||||||
| return client.virtual_machine_scale_sets.begin_create_or_update(resource_group_name, vmss_name, vmss) | ||||||||||
| vmss_vm.storage_profile.data_disks = leftovers | ||||||||||
| return client.virtual_machine_scale_set_vms.begin_update(resource_group_name, vmss_name, instance_id, vmss_vm) | ||||||||||
| vmss['virtualMachineProfile']['storageProfile']['dataDisks'] = leftovers | ||||||||||
| vmss = VMSSConvert(vmss) | ||||||||||
| vmss['resource_group'] = resource_group_name | ||||||||||
| vmss['vm_scale_set_name'] = vmss_name | ||||||||||
| return VMSSCreate(cli_ctx=cmd.cli_ctx)(command_args=vmss) | ||||||||||
|
|
||||||||||
| vmss_vm['storageProfile']['dataDisks'] = leftovers | ||||||||||
| vmss_vm = VMSSVMSConvert(vmss_vm) | ||||||||||
| vmss_vm['resource_group'] = resource_group_name | ||||||||||
| vmss_vm['vm_scale_set_name'] = vmss_name | ||||||||||
| vmss_vm['instance_id'] = instance_id | ||||||||||
| return VMSSVMSCreate(cli_ctx=cmd.cli_ctx)(command_args=vmss_vm) | ||||||||||
| # endregion | ||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please ensure the parent layer exists in the dictionaries, otherwise, it may result in an exception.