Skip to content

Commit 94725e1

Browse files
{Compute} az vmss set-orchestration-service-state: Migrate command to aaz-based implementation (#32839)
1 parent 02a280d commit 94725e1

File tree

6 files changed

+205
-8
lines changed

6 files changed

+205
-8
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929

3030
from azure.cli.command_modules.monitor.validators import validate_metric_dimension
3131
from azure.cli.command_modules.monitor.actions import get_period_type
32-
from ._vm_utils import RebootSetting, VMGuestPatchClassificationWindows, VMGuestPatchClassificationLinux
32+
from ._vm_utils import (RebootSetting, VMGuestPatchClassificationWindows, VMGuestPatchClassificationLinux,
33+
OrchestrationServiceNames, OrchestrationServiceStateAction)
3334

3435

3536
# pylint: disable=too-many-statements, too-many-branches, too-many-locals, too-many-lines
@@ -40,7 +41,6 @@ def load_arguments(self, _):
4041
UpgradeMode, CachingTypes, OperatingSystemTypes = self.get_models('UpgradeMode', 'CachingTypes', 'OperatingSystemTypes')
4142
HyperVGenerationTypes = self.get_models('HyperVGenerationTypes')
4243
DedicatedHostLicenseTypes = self.get_models('DedicatedHostLicenseTypes')
43-
OrchestrationServiceNames, OrchestrationServiceStateAction = self.get_models('OrchestrationServiceNames', 'OrchestrationServiceStateAction', operation_group='virtual_machine_scale_sets')
4444
ReplicationMode = self.get_models('ReplicationMode', operation_group='gallery_image_versions')
4545
DiskControllerTypes = self.get_models('DiskControllerTypes', operation_group='virtual_machines')
4646

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,3 +823,12 @@ class UpgradeMode(Enum):
823823
AUTOMATIC = 'Automatic'
824824
MANUAL = 'Manual'
825825
ROLLING = 'Rolling'
826+
827+
828+
class OrchestrationServiceNames(Enum):
829+
AUTOMATIC_REPAIRS = 'AutomaticRepairs'
830+
831+
832+
class OrchestrationServiceStateAction(Enum):
833+
RESUME = 'Resume'
834+
SUSPEND = 'Suspend'

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from ._restart import *
2424
from ._reimage import *
2525
from ._reimageall import *
26+
from ._set_orchestration_service_state import *
2627
from ._show import *
2728
from ._simulate_eviction import *
2829
from ._start import *
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
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+
class SetOrchestrationServiceState(AAZCommand):
15+
"""Changes ServiceState property for a given service
16+
"""
17+
18+
_aaz_info = {
19+
"version": "2024-11-01",
20+
"resources": [
21+
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/virtualmachinescalesets/{}/setorchestrationservicestate", "2024-11-01"],
22+
]
23+
}
24+
25+
AZ_SUPPORT_NO_WAIT = True
26+
27+
def _handler(self, command_args):
28+
super()._handler(command_args)
29+
return self.build_lro_poller(self._execute_operations, None)
30+
31+
_args_schema = None
32+
33+
@classmethod
34+
def _build_arguments_schema(cls, *args, **kwargs):
35+
if cls._args_schema is not None:
36+
return cls._args_schema
37+
cls._args_schema = super()._build_arguments_schema(*args, **kwargs)
38+
39+
# define Arg Group ""
40+
41+
_args_schema = cls._args_schema
42+
_args_schema.resource_group = AAZResourceGroupNameArg(
43+
required=True,
44+
)
45+
_args_schema.vm_scale_set_name = AAZStrArg(
46+
options=["--vm-scale-set-name"],
47+
help="The name of the VM scale set.",
48+
required=True,
49+
id_part="name",
50+
)
51+
52+
# define Arg Group "Parameters"
53+
54+
_args_schema = cls._args_schema
55+
_args_schema.action = AAZStrArg(
56+
options=["--action"],
57+
arg_group="Parameters",
58+
help="The action to be performed.",
59+
required=True,
60+
enum={"Resume": "Resume", "Suspend": "Suspend"},
61+
)
62+
_args_schema.service_name = AAZStrArg(
63+
options=["--service-name"],
64+
arg_group="Parameters",
65+
help="The name of the service.",
66+
required=True,
67+
enum={"AutomaticRepairs": "AutomaticRepairs"},
68+
)
69+
return cls._args_schema
70+
71+
def _execute_operations(self):
72+
self.pre_operations()
73+
yield self.VirtualMachineScaleSetsSetOrchestrationServiceState(ctx=self.ctx)()
74+
self.post_operations()
75+
76+
@register_callback
77+
def pre_operations(self):
78+
pass
79+
80+
@register_callback
81+
def post_operations(self):
82+
pass
83+
84+
class VirtualMachineScaleSetsSetOrchestrationServiceState(AAZHttpOperation):
85+
CLIENT_TYPE = "MgmtClient"
86+
87+
def __call__(self, *args, **kwargs):
88+
request = self.make_request()
89+
session = self.client.send_request(request=request, stream=False, **kwargs)
90+
if session.http_response.status_code in [202]:
91+
return self.client.build_lro_polling(
92+
self.ctx.args.no_wait,
93+
session,
94+
self.on_200,
95+
self.on_error,
96+
lro_options={"final-state-via": "location"},
97+
path_format_arguments=self.url_parameters,
98+
)
99+
if session.http_response.status_code in [200]:
100+
return self.client.build_lro_polling(
101+
self.ctx.args.no_wait,
102+
session,
103+
self.on_200,
104+
self.on_error,
105+
lro_options={"final-state-via": "location"},
106+
path_format_arguments=self.url_parameters,
107+
)
108+
109+
return self.on_error(session.http_response)
110+
111+
@property
112+
def url(self):
113+
return self.client.format_url(
114+
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/setOrchestrationServiceState",
115+
**self.url_parameters
116+
)
117+
118+
@property
119+
def method(self):
120+
return "POST"
121+
122+
@property
123+
def error_format(self):
124+
return "ODataV4Format"
125+
126+
@property
127+
def url_parameters(self):
128+
parameters = {
129+
**self.serialize_url_param(
130+
"resourceGroupName", self.ctx.args.resource_group,
131+
required=True,
132+
),
133+
**self.serialize_url_param(
134+
"subscriptionId", self.ctx.subscription_id,
135+
required=True,
136+
),
137+
**self.serialize_url_param(
138+
"vmScaleSetName", self.ctx.args.vm_scale_set_name,
139+
required=True,
140+
),
141+
}
142+
return parameters
143+
144+
@property
145+
def query_parameters(self):
146+
parameters = {
147+
**self.serialize_query_param(
148+
"api-version", "2024-11-01",
149+
required=True,
150+
),
151+
}
152+
return parameters
153+
154+
@property
155+
def header_parameters(self):
156+
parameters = {
157+
**self.serialize_header_param(
158+
"Content-Type", "application/json",
159+
),
160+
}
161+
return parameters
162+
163+
@property
164+
def content(self):
165+
_content_value, _builder = self.new_content_builder(
166+
self.ctx.args,
167+
typ=AAZObjectType,
168+
typ_kwargs={"flags": {"required": True, "client_flatten": True}}
169+
)
170+
_builder.set_prop("action", AAZStrType, ".action", typ_kwargs={"flags": {"required": True}})
171+
_builder.set_prop("serviceName", AAZStrType, ".service_name", typ_kwargs={"flags": {"required": True}})
172+
173+
return self.serialize_content(_content_value)
174+
175+
def on_200(self, session):
176+
pass
177+
178+
179+
class _SetOrchestrationServiceStateHelper:
180+
"""Helper class for SetOrchestrationServiceState"""
181+
182+
183+
__all__ = ["SetOrchestrationServiceState"]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ def load_command_table(self, _):
404404
g.custom_command('reimage', 'reimage_vmss', supports_no_wait=True)
405405
g.custom_command('restart', 'restart_vmss', supports_no_wait=True)
406406
g.custom_command('scale', 'scale_vmss', supports_no_wait=True)
407+
g.custom_command('set-orchestration-service-state', 'set_orchestration_service_state', supports_no_wait=True)
407408
g.custom_command('stop', 'stop_vmss', supports_no_wait=True, validator=process_vm_vmss_stop)
408409

409410
with self.command_group('vmss application', operation_group='virtual_machine_scale_sets') as g:
@@ -417,7 +418,6 @@ def load_command_table(self, _):
417418
g.generic_update_command('update', getter_name='get_vmss_modified_by_aaz', setter_name='update_vmss', supports_no_wait=True, command_type=compute_custom, validator=validate_vmss_update_namespace)
418419
g.custom_command('update-instances', 'update_vmss_instances', supports_no_wait=True)
419420
g.wait_command('wait', getter_name='get_vmss', getter_type=compute_custom)
420-
g.custom_command('set-orchestration-service-state', 'set_orchestration_service_state', supports_no_wait=True)
421421

422422
from .aaz.latest.vmss import List as VMSSList
423423
self.command_table['vmss list'] = VMSSList(loader=self,

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5315,11 +5315,15 @@ def set_orchestration_service_state(cmd, resource_group_name, vm_scale_set_name,
53155315
# currently service_name has only one available value "AutomaticRepairs". And SDK does not accept service_name,
53165316
# instead SDK assign it to "AutomaticRepairs" in its own logic. As there may be more service name to be supported,
53175317
# we define service_name as a required parameter here to avoid introducing a breaking change in the future.
5318-
client = _compute_client_factory(cmd.cli_ctx)
5319-
OrchestrationServiceStateInput = cmd.get_models('OrchestrationServiceStateInput')
5320-
state_input = OrchestrationServiceStateInput(service_name=service_name, action=action)
5321-
return sdk_no_wait(no_wait, client.virtual_machine_scale_sets.begin_set_orchestration_service_state,
5322-
resource_group_name, vm_scale_set_name, state_input)
5318+
from .aaz.latest.vmss import SetOrchestrationServiceState as VmssSetOrchestrationServiceState
5319+
command_args = {
5320+
'resource_group': resource_group_name,
5321+
'vm_scale_set_name': vm_scale_set_name,
5322+
'action': action,
5323+
'service_name': service_name,
5324+
'no_wait': no_wait
5325+
}
5326+
return VmssSetOrchestrationServiceState(cli_ctx=cmd.cli_ctx)(command_args=command_args)
53235327

53245328

53255329
def upgrade_vmss_extension(cmd, resource_group_name, vm_scale_set_name, no_wait=False):

0 commit comments

Comments
 (0)