Repository navigation
[Compute] az vm availability-set: Add new commands to support migration from availability sets to VMSS
#32180
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
Merged
Xing Zhou (zhoxing-ms)
merged 2 commits into
Azure:dev
from
Jing-song:jins-avsetmigration
Sep 28, 2025
Merged
Changes from 1 commit
Commits
Show all changes
2 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
176 changes: 176 additions & 0 deletions
176
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/_migrate_to_vmss.py
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 |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # | ||
| # Code generated by aaz-dev-tools | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| # pylint: skip-file | ||
| # flake8: noqa | ||
|
|
||
| from azure.cli.core.aaz import * | ||
|
|
||
|
|
||
| @register_command( | ||
| "vm migrate-to-vmss", | ||
| ) | ||
| class MigrateToVmss(AAZCommand): | ||
| """Migrate a virtual machine from availability set to Flexible Virtual Machine Scale Set. | ||
| """ | ||
|
|
||
| _aaz_info = { | ||
| "version": "2024-11-01", | ||
| "resources": [ | ||
| ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/virtualmachines/{}/migratetovirtualmachinescaleset", "2024-11-01"], | ||
| ] | ||
| } | ||
|
|
||
| AZ_SUPPORT_NO_WAIT = True | ||
|
|
||
| def _handler(self, command_args): | ||
| super()._handler(command_args) | ||
| return self.build_lro_poller(self._execute_operations, None) | ||
|
|
||
| _args_schema = None | ||
|
|
||
| @classmethod | ||
| def _build_arguments_schema(cls, *args, **kwargs): | ||
| if cls._args_schema is not None: | ||
| return cls._args_schema | ||
| cls._args_schema = super()._build_arguments_schema(*args, **kwargs) | ||
|
|
||
| # define Arg Group "" | ||
|
|
||
| _args_schema = cls._args_schema | ||
| _args_schema.resource_group = AAZResourceGroupNameArg( | ||
| required=True, | ||
| ) | ||
| _args_schema.vm_name = AAZStrArg( | ||
| options=["--vm-name"], | ||
| help="The name of the virtual machine.", | ||
| required=True, | ||
| id_part="name", | ||
| ) | ||
|
|
||
| # define Arg Group "Parameters" | ||
|
|
||
| _args_schema = cls._args_schema | ||
| _args_schema.target_fault_domain = AAZIntArg( | ||
| options=["--target-fault-domain"], | ||
| arg_group="Parameters", | ||
| help="The target compute fault domain of VM migration to Flexible Virtual Machine Scale Set.", | ||
| ) | ||
| _args_schema.target_vm_size = AAZStrArg( | ||
| options=["--target-vm-size"], | ||
| arg_group="Parameters", | ||
| help="The target Virtual Machine size of VM migration to Flexible Virtual Machine Scale Set.", | ||
| ) | ||
| _args_schema.target_zone = AAZStrArg( | ||
| options=["--target-zone"], | ||
| arg_group="Parameters", | ||
| help="The target zone of VM migration to Flexible Virtual Machine Scale Set.", | ||
| ) | ||
| return cls._args_schema | ||
|
|
||
| def _execute_operations(self): | ||
| self.pre_operations() | ||
| yield self.VirtualMachinesMigrateToVMScaleSet(ctx=self.ctx)() | ||
| self.post_operations() | ||
|
|
||
| @register_callback | ||
| def pre_operations(self): | ||
| pass | ||
|
|
||
| @register_callback | ||
| def post_operations(self): | ||
| pass | ||
|
|
||
| class VirtualMachinesMigrateToVMScaleSet(AAZHttpOperation): | ||
| CLIENT_TYPE = "MgmtClient" | ||
|
|
||
| def __call__(self, *args, **kwargs): | ||
| request = self.make_request() | ||
| session = self.client.send_request(request=request, stream=False, **kwargs) | ||
| if session.http_response.status_code in [202]: | ||
| return self.client.build_lro_polling( | ||
| self.ctx.args.no_wait, | ||
| session, | ||
| None, | ||
| self.on_error, | ||
| lro_options={"final-state-via": "location"}, | ||
| path_format_arguments=self.url_parameters, | ||
| ) | ||
|
|
||
| return self.on_error(session.http_response) | ||
|
|
||
| @property | ||
| def url(self): | ||
| return self.client.format_url( | ||
| "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/migrateToVirtualMachineScaleSet", | ||
| **self.url_parameters | ||
| ) | ||
|
|
||
| @property | ||
| def method(self): | ||
| return "POST" | ||
|
|
||
| @property | ||
| def error_format(self): | ||
| return "ODataV4Format" | ||
|
|
||
| @property | ||
| def url_parameters(self): | ||
| parameters = { | ||
| **self.serialize_url_param( | ||
| "resourceGroupName", self.ctx.args.resource_group, | ||
| required=True, | ||
| ), | ||
| **self.serialize_url_param( | ||
| "subscriptionId", self.ctx.subscription_id, | ||
| required=True, | ||
| ), | ||
| **self.serialize_url_param( | ||
| "vmName", self.ctx.args.vm_name, | ||
| required=True, | ||
| ), | ||
| } | ||
| return parameters | ||
|
|
||
| @property | ||
| def query_parameters(self): | ||
| parameters = { | ||
| **self.serialize_query_param( | ||
| "api-version", "2024-11-01", | ||
| required=True, | ||
| ), | ||
| } | ||
| return parameters | ||
|
|
||
| @property | ||
| def header_parameters(self): | ||
| parameters = { | ||
| **self.serialize_header_param( | ||
| "Content-Type", "application/json", | ||
| ), | ||
| } | ||
| return parameters | ||
|
|
||
| @property | ||
| def content(self): | ||
| _content_value, _builder = self.new_content_builder( | ||
| self.ctx.args, | ||
| typ=AAZObjectType, | ||
| typ_kwargs={"flags": {"client_flatten": True}} | ||
| ) | ||
| _builder.set_prop("targetFaultDomain", AAZIntType, ".target_fault_domain") | ||
| _builder.set_prop("targetVMSize", AAZStrType, ".target_vm_size") | ||
| _builder.set_prop("targetZone", AAZStrType, ".target_zone") | ||
|
|
||
| return self.serialize_content(_content_value) | ||
|
|
||
|
|
||
| class _MigrateToVmssHelper: | ||
| """Helper class for MigrateToVmss""" | ||
|
|
||
|
|
||
| __all__ = ["MigrateToVmss"] | ||
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
130 changes: 130 additions & 0 deletions
130
.../azure/cli/command_modules/vm/aaz/latest/vm/availability_set/_cancel_migration_to_vmss.py
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 |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # | ||
| # Code generated by aaz-dev-tools | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| # pylint: skip-file | ||
| # flake8: noqa | ||
|
|
||
| from azure.cli.core.aaz import * | ||
|
|
||
|
|
||
| @register_command( | ||
| "vm availability-set cancel-migration-to-vmss", | ||
| ) | ||
| class CancelMigrationToVmss(AAZCommand): | ||
| """Cancel the migration operation on an Availability Set. | ||
| """ | ||
|
Comment on lines
+14
to
+22
|
||
|
|
||
| _aaz_info = { | ||
| "version": "2024-11-01", | ||
| "resources": [ | ||
| ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/availabilitysets/{}/cancelmigrationtovirtualmachinescaleset", "2024-11-01"], | ||
| ] | ||
| } | ||
|
|
||
| def _handler(self, command_args): | ||
| super()._handler(command_args) | ||
| self._execute_operations() | ||
| return None | ||
|
|
||
| _args_schema = None | ||
|
|
||
| @classmethod | ||
| def _build_arguments_schema(cls, *args, **kwargs): | ||
| if cls._args_schema is not None: | ||
| return cls._args_schema | ||
| cls._args_schema = super()._build_arguments_schema(*args, **kwargs) | ||
|
|
||
| # define Arg Group "" | ||
|
|
||
| _args_schema = cls._args_schema | ||
| _args_schema.availability_set_name = AAZStrArg( | ||
| options=["-n", "--name", "--availability-set-name"], | ||
| help="The name of the availability set.", | ||
| required=True, | ||
| id_part="name", | ||
| ) | ||
| _args_schema.resource_group = AAZResourceGroupNameArg( | ||
| required=True, | ||
| ) | ||
| return cls._args_schema | ||
|
|
||
| def _execute_operations(self): | ||
| self.pre_operations() | ||
| self.AvailabilitySetsCancelMigrationToVirtualMachineScaleSet(ctx=self.ctx)() | ||
| self.post_operations() | ||
|
|
||
| @register_callback | ||
| def pre_operations(self): | ||
| pass | ||
|
|
||
| @register_callback | ||
| def post_operations(self): | ||
| pass | ||
|
|
||
| class AvailabilitySetsCancelMigrationToVirtualMachineScaleSet(AAZHttpOperation): | ||
| CLIENT_TYPE = "MgmtClient" | ||
|
|
||
| def __call__(self, *args, **kwargs): | ||
| request = self.make_request() | ||
| session = self.client.send_request(request=request, stream=False, **kwargs) | ||
| if session.http_response.status_code in [204]: | ||
| return self.on_204(session) | ||
|
|
||
| return self.on_error(session.http_response) | ||
|
|
||
| @property | ||
| def url(self): | ||
| return self.client.format_url( | ||
| "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/availabilitySets/{availabilitySetName}/cancelMigrationToVirtualMachineScaleSet", | ||
| **self.url_parameters | ||
| ) | ||
|
|
||
| @property | ||
| def method(self): | ||
| return "POST" | ||
|
|
||
| @property | ||
| def error_format(self): | ||
| return "ODataV4Format" | ||
|
|
||
| @property | ||
| def url_parameters(self): | ||
| parameters = { | ||
| **self.serialize_url_param( | ||
| "availabilitySetName", self.ctx.args.availability_set_name, | ||
| required=True, | ||
| ), | ||
| **self.serialize_url_param( | ||
| "resourceGroupName", self.ctx.args.resource_group, | ||
| required=True, | ||
| ), | ||
| **self.serialize_url_param( | ||
| "subscriptionId", self.ctx.subscription_id, | ||
| required=True, | ||
| ), | ||
| } | ||
| return parameters | ||
|
|
||
| @property | ||
| def query_parameters(self): | ||
| parameters = { | ||
| **self.serialize_query_param( | ||
| "api-version", "2024-11-01", | ||
| required=True, | ||
| ), | ||
| } | ||
| return parameters | ||
|
|
||
| def on_204(self, session): | ||
| pass | ||
|
|
||
|
|
||
| class _CancelMigrationToVmssHelper: | ||
| """Helper class for CancelMigrationToVmss""" | ||
|
|
||
|
|
||
| __all__ = ["CancelMigrationToVmss"] | ||
Oops, something went wrong.
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.
This command performs a dangerous operation (migrate VM) that will permanently change the VM's infrastructure setup and could potentially cause downtime. According to coding guidelines, dangerous operations should include the
confirmation=Trueflag to require user confirmation before execution.