Skip to content

Commit 85adebe

Browse files
committed
vmss start migrate
1 parent c8ef40c commit 85adebe

File tree

4 files changed

+189
-13
lines changed

4 files changed

+189
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
from ._list_instance_public_ips import *
1616
from ._list_instances import *
1717
from ._list_skus import *
18-
from ._patch import *
1918
from ._perform_maintenance import *
2019
from ._simulate_eviction import *
20+
from ._start import *
2121
from ._update import *
2222
from ._update_domain_walk import *
2323
from ._wait import *
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
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+
"vmss start",
16+
)
17+
class Start(AAZCommand):
18+
"""Start VMs within a VMSS
19+
20+
:example: Start VMs within a VMSS.
21+
az vmss start --instance-ids 1 --name MyScaleSet --resource-group MyResourceGroup
22+
"""
23+
24+
_aaz_info = {
25+
"version": "2024-11-01",
26+
"resources": [
27+
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/virtualmachinescalesets/{}/start", "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+
help="Name of resource group. You can configure the default group using `az configure --defaults group=<name>`",
50+
required=True,
51+
)
52+
_args_schema.name = AAZStrArg(
53+
options=["--name"],
54+
help="Scale set name. You can configure the default using `az configure --defaults vmss=<name>`",
55+
required=True,
56+
id_part="name",
57+
)
58+
59+
# define Arg Group "VmInstanceIDs"
60+
61+
_args_schema = cls._args_schema
62+
_args_schema.instance_ids = AAZListArg(
63+
options=["--instance-ids"],
64+
arg_group="VmInstanceIDs",
65+
help="The virtual machine scale set instance ids. Omitting the virtual machine scale set instance ids will result in the operation being performed on all virtual machines in the virtual machine scale set.",
66+
)
67+
68+
instance_ids = cls._args_schema.instance_ids
69+
instance_ids.Element = AAZStrArg()
70+
return cls._args_schema
71+
72+
def _execute_operations(self):
73+
self.pre_operations()
74+
yield self.VirtualMachineScaleSetsStart(ctx=self.ctx)()
75+
self.post_operations()
76+
77+
@register_callback
78+
def pre_operations(self):
79+
pass
80+
81+
@register_callback
82+
def post_operations(self):
83+
pass
84+
85+
class VirtualMachineScaleSetsStart(AAZHttpOperation):
86+
CLIENT_TYPE = "MgmtClient"
87+
88+
def __call__(self, *args, **kwargs):
89+
request = self.make_request()
90+
session = self.client.send_request(request=request, stream=False, **kwargs)
91+
if session.http_response.status_code in [202]:
92+
return self.client.build_lro_polling(
93+
self.ctx.args.no_wait,
94+
session,
95+
self.on_200,
96+
self.on_error,
97+
lro_options={"final-state-via": "location"},
98+
path_format_arguments=self.url_parameters,
99+
)
100+
if session.http_response.status_code in [200]:
101+
return self.client.build_lro_polling(
102+
self.ctx.args.no_wait,
103+
session,
104+
self.on_200,
105+
self.on_error,
106+
lro_options={"final-state-via": "location"},
107+
path_format_arguments=self.url_parameters,
108+
)
109+
110+
return self.on_error(session.http_response)
111+
112+
@property
113+
def url(self):
114+
return self.client.format_url(
115+
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/start",
116+
**self.url_parameters
117+
)
118+
119+
@property
120+
def method(self):
121+
return "POST"
122+
123+
@property
124+
def error_format(self):
125+
return "ODataV4Format"
126+
127+
@property
128+
def url_parameters(self):
129+
parameters = {
130+
**self.serialize_url_param(
131+
"resourceGroupName", self.ctx.args.resource_group,
132+
required=True,
133+
),
134+
**self.serialize_url_param(
135+
"subscriptionId", self.ctx.subscription_id,
136+
required=True,
137+
),
138+
**self.serialize_url_param(
139+
"vmScaleSetName", self.ctx.args.name,
140+
required=True,
141+
),
142+
}
143+
return parameters
144+
145+
@property
146+
def query_parameters(self):
147+
parameters = {
148+
**self.serialize_query_param(
149+
"api-version", "2024-11-01",
150+
required=True,
151+
),
152+
}
153+
return parameters
154+
155+
@property
156+
def header_parameters(self):
157+
parameters = {
158+
**self.serialize_header_param(
159+
"Content-Type", "application/json",
160+
),
161+
}
162+
return parameters
163+
164+
@property
165+
def content(self):
166+
_content_value, _builder = self.new_content_builder(
167+
self.ctx.args,
168+
typ=AAZObjectType,
169+
typ_kwargs={"flags": {"client_flatten": True}}
170+
)
171+
_builder.set_prop("instanceIds", AAZListType, ".instance_ids")
172+
173+
instance_ids = _builder.get(".instanceIds")
174+
if instance_ids is not None:
175+
instance_ids.set_elements(AAZStrType, ".")
176+
177+
return self.serialize_content(_content_value)
178+
179+
def on_200(self, session):
180+
pass
181+
182+
183+
class _StartHelper:
184+
"""Helper class for Start"""
185+
186+
187+
__all__ = ["Start"]

src/azure-cli/azure/cli/command_modules/vm/commands.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,7 @@ def load_command_table(self, _):
429429
g.custom_command('reimage', 'reimage_vmss', supports_no_wait=True, min_api='2017-03-30')
430430
g.custom_command('restart', 'restart_vmss', supports_no_wait=True)
431431
g.custom_command('scale', 'scale_vmss', supports_no_wait=True)
432-
g.custom_show_command('show', 'get_vmss', table_transformer=get_vmss_table_output_transformer(self, False))
433-
g.custom_command('start', 'start_vmss', supports_no_wait=True)
432+
g.custom_show_command('show', 'get_vmss', table_transformer=get_vmss_table_output_transformer(self, False))
434433
g.custom_command('stop', 'stop_vmss', supports_no_wait=True, validator=process_vm_vmss_stop)
435434
g.generic_update_command('update', getter_name='get_vmss_modified', setter_name='update_vmss', supports_no_wait=True, command_type=compute_custom, validator=validate_vmss_update_namespace)
436435
g.custom_command('update-instances', 'update_vmss_instances', supports_no_wait=True)

src/azure-cli/azure/cli/command_modules/vm/custom.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4052,16 +4052,6 @@ def scale_vmss(cmd, resource_group_name, vm_scale_set_name, new_capacity, no_wai
40524052
resource_group_name, vm_scale_set_name, vmss_new)
40534053

40544054

4055-
def start_vmss(cmd, resource_group_name, vm_scale_set_name, instance_ids=None, no_wait=False):
4056-
client = _compute_client_factory(cmd.cli_ctx)
4057-
VirtualMachineScaleSetVMInstanceRequiredIDs = cmd.get_models('VirtualMachineScaleSetVMInstanceRequiredIDs')
4058-
if instance_ids is None:
4059-
instance_ids = ['*']
4060-
instance_ids = VirtualMachineScaleSetVMInstanceRequiredIDs(instance_ids=instance_ids)
4061-
return sdk_no_wait(no_wait, client.virtual_machine_scale_sets.begin_start,
4062-
resource_group_name, vm_scale_set_name, vm_instance_i_ds=instance_ids)
4063-
4064-
40654055
def stop_vmss(cmd, resource_group_name, vm_scale_set_name, instance_ids=None, no_wait=False, skip_shutdown=False):
40664056
client = _compute_client_factory(cmd.cli_ctx)
40674057
VirtualMachineScaleSetVMInstanceRequiredIDs = cmd.get_models('VirtualMachineScaleSetVMInstanceRequiredIDs')

0 commit comments

Comments
 (0)