Skip to content

Commit b804a0e

Browse files
authored
[Compute] az vm availability-set: Add new commands to support migration from availability sets to VMSS (#32180)
1 parent 61c5fec commit b804a0e

File tree

9 files changed

+4457
-0
lines changed

9 files changed

+4457
-0
lines changed

src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from ._list_sizes import *
2121
from ._list_skus import *
2222
from ._list_vm_resize_options import *
23+
from ._migrate_to_vmss import *
2324
from ._patch import *
2425
from ._perform_maintenance import *
2526
from ._reapply import *
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from azure.cli.core.aaz import *
12+
13+
14+
@register_command(
15+
"vm migrate-to-vmss",
16+
)
17+
class MigrateToVmss(AAZCommand):
18+
"""Migrate a virtual machine from availability set to Flexible Virtual Machine Scale Set.
19+
20+
:example: Migrate a vm to flexible vmss
21+
az vm migrate-to-vmss --resource-group myResourceGroup --vm-name myVMName --target-fault-domain 0 --target-vm-size Standard_D1_v2
22+
"""
23+
24+
_aaz_info = {
25+
"version": "2024-11-01",
26+
"resources": [
27+
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/virtualmachines/{}/migratetovirtualmachinescaleset", "2024-11-01"],
28+
]
29+
}
30+
31+
AZ_SUPPORT_NO_WAIT = True
32+
33+
def _handler(self, command_args):
34+
super()._handler(command_args)
35+
return self.build_lro_poller(self._execute_operations, None)
36+
37+
_args_schema = None
38+
39+
@classmethod
40+
def _build_arguments_schema(cls, *args, **kwargs):
41+
if cls._args_schema is not None:
42+
return cls._args_schema
43+
cls._args_schema = super()._build_arguments_schema(*args, **kwargs)
44+
45+
# define Arg Group ""
46+
47+
_args_schema = cls._args_schema
48+
_args_schema.resource_group = AAZResourceGroupNameArg(
49+
required=True,
50+
)
51+
_args_schema.vm_name = AAZStrArg(
52+
options=["--vm-name"],
53+
help="The name of the virtual machine.",
54+
required=True,
55+
id_part="name",
56+
)
57+
58+
# define Arg Group "Parameters"
59+
60+
_args_schema = cls._args_schema
61+
_args_schema.target_fault_domain = AAZIntArg(
62+
options=["--target-fault-domain"],
63+
arg_group="Parameters",
64+
help="The target compute fault domain of VM migration to Flexible Virtual Machine Scale Set.",
65+
)
66+
_args_schema.target_vm_size = AAZStrArg(
67+
options=["--target-vm-size"],
68+
arg_group="Parameters",
69+
help="The target Virtual Machine size of VM migration to Flexible Virtual Machine Scale Set.",
70+
)
71+
_args_schema.target_zone = AAZStrArg(
72+
options=["--target-zone"],
73+
arg_group="Parameters",
74+
help="The target zone of VM migration to Flexible Virtual Machine Scale Set.",
75+
)
76+
return cls._args_schema
77+
78+
def _execute_operations(self):
79+
self.pre_operations()
80+
yield self.VirtualMachinesMigrateToVMScaleSet(ctx=self.ctx)()
81+
self.post_operations()
82+
83+
@register_callback
84+
def pre_operations(self):
85+
pass
86+
87+
@register_callback
88+
def post_operations(self):
89+
pass
90+
91+
class VirtualMachinesMigrateToVMScaleSet(AAZHttpOperation):
92+
CLIENT_TYPE = "MgmtClient"
93+
94+
def __call__(self, *args, **kwargs):
95+
request = self.make_request()
96+
session = self.client.send_request(request=request, stream=False, **kwargs)
97+
if session.http_response.status_code in [202]:
98+
return self.client.build_lro_polling(
99+
self.ctx.args.no_wait,
100+
session,
101+
None,
102+
self.on_error,
103+
lro_options={"final-state-via": "location"},
104+
path_format_arguments=self.url_parameters,
105+
)
106+
107+
return self.on_error(session.http_response)
108+
109+
@property
110+
def url(self):
111+
return self.client.format_url(
112+
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/migrateToVirtualMachineScaleSet",
113+
**self.url_parameters
114+
)
115+
116+
@property
117+
def method(self):
118+
return "POST"
119+
120+
@property
121+
def error_format(self):
122+
return "ODataV4Format"
123+
124+
@property
125+
def url_parameters(self):
126+
parameters = {
127+
**self.serialize_url_param(
128+
"resourceGroupName", self.ctx.args.resource_group,
129+
required=True,
130+
),
131+
**self.serialize_url_param(
132+
"subscriptionId", self.ctx.subscription_id,
133+
required=True,
134+
),
135+
**self.serialize_url_param(
136+
"vmName", self.ctx.args.vm_name,
137+
required=True,
138+
),
139+
}
140+
return parameters
141+
142+
@property
143+
def query_parameters(self):
144+
parameters = {
145+
**self.serialize_query_param(
146+
"api-version", "2024-11-01",
147+
required=True,
148+
),
149+
}
150+
return parameters
151+
152+
@property
153+
def header_parameters(self):
154+
parameters = {
155+
**self.serialize_header_param(
156+
"Content-Type", "application/json",
157+
),
158+
}
159+
return parameters
160+
161+
@property
162+
def content(self):
163+
_content_value, _builder = self.new_content_builder(
164+
self.ctx.args,
165+
typ=AAZObjectType,
166+
typ_kwargs={"flags": {"client_flatten": True}}
167+
)
168+
_builder.set_prop("targetFaultDomain", AAZIntType, ".target_fault_domain")
169+
_builder.set_prop("targetVMSize", AAZStrType, ".target_vm_size")
170+
_builder.set_prop("targetZone", AAZStrType, ".target_zone")
171+
172+
return self.serialize_content(_content_value)
173+
174+
175+
class _MigrateToVmssHelper:
176+
"""Helper class for MigrateToVmss"""
177+
178+
179+
__all__ = ["MigrateToVmss"]

src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/availability_set/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
# flake8: noqa
1010

1111
from .__cmd_group import *
12+
from ._cancel_migration_to_vmss import *
13+
from ._convert_to_vmss import *
1214
from ._delete import *
1315
from ._list import *
1416
from ._list_sizes import *
1517
from ._show import *
18+
from ._start_migration_to_vmss import *
1619
from ._update import *
20+
from ._validate_migration_to_vmss import *
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from azure.cli.core.aaz import *
12+
13+
14+
@register_command(
15+
"vm availability-set cancel-migration-to-vmss",
16+
)
17+
class CancelMigrationToVmss(AAZCommand):
18+
"""Cancel the migration operation on an Availability Set.
19+
20+
:example: Cancel migration to vmss
21+
az vm availability-set cancel-migration-to-vmss --resource-group rgcompute --availability-set-name myAvailabilitySet
22+
"""
23+
24+
_aaz_info = {
25+
"version": "2024-11-01",
26+
"resources": [
27+
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/availabilitysets/{}/cancelmigrationtovirtualmachinescaleset", "2024-11-01"],
28+
]
29+
}
30+
31+
def _handler(self, command_args):
32+
super()._handler(command_args)
33+
self._execute_operations()
34+
return None
35+
36+
_args_schema = None
37+
38+
@classmethod
39+
def _build_arguments_schema(cls, *args, **kwargs):
40+
if cls._args_schema is not None:
41+
return cls._args_schema
42+
cls._args_schema = super()._build_arguments_schema(*args, **kwargs)
43+
44+
# define Arg Group ""
45+
46+
_args_schema = cls._args_schema
47+
_args_schema.availability_set_name = AAZStrArg(
48+
options=["-n", "--name", "--availability-set-name"],
49+
help="The name of the availability set.",
50+
required=True,
51+
id_part="name",
52+
)
53+
_args_schema.resource_group = AAZResourceGroupNameArg(
54+
required=True,
55+
)
56+
return cls._args_schema
57+
58+
def _execute_operations(self):
59+
self.pre_operations()
60+
self.AvailabilitySetsCancelMigrationToVirtualMachineScaleSet(ctx=self.ctx)()
61+
self.post_operations()
62+
63+
@register_callback
64+
def pre_operations(self):
65+
pass
66+
67+
@register_callback
68+
def post_operations(self):
69+
pass
70+
71+
class AvailabilitySetsCancelMigrationToVirtualMachineScaleSet(AAZHttpOperation):
72+
CLIENT_TYPE = "MgmtClient"
73+
74+
def __call__(self, *args, **kwargs):
75+
request = self.make_request()
76+
session = self.client.send_request(request=request, stream=False, **kwargs)
77+
if session.http_response.status_code in [204]:
78+
return self.on_204(session)
79+
80+
return self.on_error(session.http_response)
81+
82+
@property
83+
def url(self):
84+
return self.client.format_url(
85+
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/availabilitySets/{availabilitySetName}/cancelMigrationToVirtualMachineScaleSet",
86+
**self.url_parameters
87+
)
88+
89+
@property
90+
def method(self):
91+
return "POST"
92+
93+
@property
94+
def error_format(self):
95+
return "ODataV4Format"
96+
97+
@property
98+
def url_parameters(self):
99+
parameters = {
100+
**self.serialize_url_param(
101+
"availabilitySetName", self.ctx.args.availability_set_name,
102+
required=True,
103+
),
104+
**self.serialize_url_param(
105+
"resourceGroupName", self.ctx.args.resource_group,
106+
required=True,
107+
),
108+
**self.serialize_url_param(
109+
"subscriptionId", self.ctx.subscription_id,
110+
required=True,
111+
),
112+
}
113+
return parameters
114+
115+
@property
116+
def query_parameters(self):
117+
parameters = {
118+
**self.serialize_query_param(
119+
"api-version", "2024-11-01",
120+
required=True,
121+
),
122+
}
123+
return parameters
124+
125+
def on_204(self, session):
126+
pass
127+
128+
129+
class _CancelMigrationToVmssHelper:
130+
"""Helper class for CancelMigrationToVmss"""
131+
132+
133+
__all__ = ["CancelMigrationToVmss"]

0 commit comments

Comments
 (0)