Skip to content

Commit 2c037ba

Browse files
authored
[Compute] BREAKING CHANGE: Migrate commands using Code Gen V2 (#30430)
1 parent 464a79c commit 2c037ba

File tree

76 files changed

+20737
-8532
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+20737
-8532
lines changed

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

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -77,32 +77,6 @@
7777
az disk create -g MyResourceGroup -n MyDisk --upload-size-bytes 20972032 --upload-type UploadWithSecurityData --security-type TrustedLaunch --hyper-v-generation V2
7878
"""
7979

80-
helps['disk grant-access'] = """
81-
type: command
82-
short-summary: Grant a resource access to a managed disk.
83-
examples:
84-
- name: Grant a resource read access to a managed disk. (autogenerated)
85-
text: |
86-
az disk grant-access --access-level Read --duration-in-seconds 3600 --name MyManagedDisk --resource-group MyResourceGroup
87-
crafted: true
88-
- name: Grant a resource read access to a disk to generate access SAS and security data access SAS
89-
text: |
90-
az disk grant-access --access-level Read --duration-in-seconds 3600 --name MyDisk --resource-group MyResourceGroup --secure-vm-guest-state-sas
91-
"""
92-
93-
helps['disk update'] = """
94-
type: command
95-
short-summary: Update a managed disk.
96-
examples:
97-
- name: Update a managed disk and associate it with a disk access resource.
98-
text: |
99-
az disk update --name MyManagedDisk --resource-group MyResourceGroup --network-access-policy AllowPrivate --disk-access MyDiskAccessID
100-
- name: Update a managed disk. (autogenerated)
101-
text: |
102-
az disk update --name MyManagedDisk --resource-group MyResourceGroup --size-gb 20
103-
crafted: true
104-
"""
105-
10680
helps['disk wait'] = """
10781
type: command
10882
short-summary: Place the CLI in a waiting state until a condition of a managed disk is met.
@@ -696,16 +670,6 @@
696670
az image builder show -n mytemplate -g my-group
697671
"""
698672

699-
helps['image update'] = """
700-
type: command
701-
short-summary: Update custom VM images.
702-
examples:
703-
- name: Add or update tags.
704-
text: az image update -n ImageName -g ResourceGroup --tags tag1=val1 tag2=val2
705-
- name: Remove all tags.
706-
text: az image update -n ImageName -g resourceGroup --tags
707-
"""
708-
709673
helps['ppg create'] = """
710674
type: command
711675
short-summary: Create a proximity placement group

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

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

1111
from .__cmd_group import *
12+
from ._create import *
1213
from ._delete import *
14+
from ._grant_access import *
1315
from ._list import *
1416
from ._revoke_access import *
1517
from ._show import *
18+
from ._update import *
1619
from ._wait import *

src/azure-cli/azure/cli/command_modules/vm/aaz/latest/disk/_create.py

Lines changed: 1003 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
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+
"disk grant-access",
16+
)
17+
class GrantAccess(AAZCommand):
18+
"""Grant a resource access to a managed disk.
19+
20+
:example: Grant a resource read access to a managed disk.
21+
az disk grant-access --access-level Read --duration-in-seconds 3600 --name MyManagedDisk --resource-group MyResourceGroup
22+
23+
:example: Grant a resource read access to a disk to generate access SAS and security data access SAS
24+
az disk grant-access --access-level Read --duration-in-seconds 3600 --name MyDisk --resource-group MyResourceGroup --secure-vm-guest-state-sas
25+
"""
26+
27+
_aaz_info = {
28+
"version": "2023-04-02",
29+
"resources": [
30+
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/disks/{}/begingetaccess", "2023-04-02"],
31+
]
32+
}
33+
34+
AZ_SUPPORT_NO_WAIT = True
35+
36+
def _handler(self, command_args):
37+
super()._handler(command_args)
38+
return self.build_lro_poller(self._execute_operations, self._output)
39+
40+
_args_schema = None
41+
42+
@classmethod
43+
def _build_arguments_schema(cls, *args, **kwargs):
44+
if cls._args_schema is not None:
45+
return cls._args_schema
46+
cls._args_schema = super()._build_arguments_schema(*args, **kwargs)
47+
48+
# define Arg Group ""
49+
50+
_args_schema = cls._args_schema
51+
_args_schema.disk_name = AAZStrArg(
52+
options=["-n", "--name", "--disk-name"],
53+
help="The name of the managed disk that is being created. The name can't be changed after the disk is created. Supported characters for the name are a-z, A-Z, 0-9, _ and -. The maximum name length is 80 characters.",
54+
required=True,
55+
id_part="name",
56+
)
57+
_args_schema.resource_group = AAZResourceGroupNameArg(
58+
required=True,
59+
)
60+
61+
# define Arg Group "GrantAccessData"
62+
63+
_args_schema = cls._args_schema
64+
_args_schema.access_level = AAZStrArg(
65+
options=["--access", "--access-level"],
66+
arg_group="GrantAccessData",
67+
help="Access level.",
68+
required=True,
69+
default="Read",
70+
enum={"None": "None", "Read": "Read", "Write": "Write"},
71+
)
72+
_args_schema.duration_in_seconds = AAZIntArg(
73+
options=["--duration-in-seconds"],
74+
arg_group="GrantAccessData",
75+
help="Time duration in seconds until the SAS access expires.",
76+
required=True,
77+
)
78+
_args_schema.secure_vm_guest_state_sas = AAZBoolArg(
79+
options=["-s", "--secure-vm-guest-state-sas"],
80+
arg_group="GrantAccessData",
81+
help="Get SAS on managed disk with VM guest state. It will be used by default when the create option of disk is 'secureOSUpload'",
82+
)
83+
return cls._args_schema
84+
85+
def _execute_operations(self):
86+
self.pre_operations()
87+
yield self.DisksGrantAccess(ctx=self.ctx)()
88+
self.post_operations()
89+
90+
@register_callback
91+
def pre_operations(self):
92+
pass
93+
94+
@register_callback
95+
def post_operations(self):
96+
pass
97+
98+
def _output(self, *args, **kwargs):
99+
result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True)
100+
return result
101+
102+
class DisksGrantAccess(AAZHttpOperation):
103+
CLIENT_TYPE = "MgmtClient"
104+
105+
def __call__(self, *args, **kwargs):
106+
request = self.make_request()
107+
session = self.client.send_request(request=request, stream=False, **kwargs)
108+
if session.http_response.status_code in [202]:
109+
return self.client.build_lro_polling(
110+
self.ctx.args.no_wait,
111+
session,
112+
self.on_200,
113+
self.on_error,
114+
lro_options={"final-state-via": "location"},
115+
path_format_arguments=self.url_parameters,
116+
)
117+
if session.http_response.status_code in [200]:
118+
return self.client.build_lro_polling(
119+
self.ctx.args.no_wait,
120+
session,
121+
self.on_200,
122+
self.on_error,
123+
lro_options={"final-state-via": "location"},
124+
path_format_arguments=self.url_parameters,
125+
)
126+
127+
return self.on_error(session.http_response)
128+
129+
@property
130+
def url(self):
131+
return self.client.format_url(
132+
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks/{diskName}/beginGetAccess",
133+
**self.url_parameters
134+
)
135+
136+
@property
137+
def method(self):
138+
return "POST"
139+
140+
@property
141+
def error_format(self):
142+
return "MgmtErrorFormat"
143+
144+
@property
145+
def url_parameters(self):
146+
parameters = {
147+
**self.serialize_url_param(
148+
"diskName", self.ctx.args.disk_name,
149+
required=True,
150+
),
151+
**self.serialize_url_param(
152+
"resourceGroupName", self.ctx.args.resource_group,
153+
required=True,
154+
),
155+
**self.serialize_url_param(
156+
"subscriptionId", self.ctx.subscription_id,
157+
required=True,
158+
),
159+
}
160+
return parameters
161+
162+
@property
163+
def query_parameters(self):
164+
parameters = {
165+
**self.serialize_query_param(
166+
"api-version", "2023-04-02",
167+
required=True,
168+
),
169+
}
170+
return parameters
171+
172+
@property
173+
def header_parameters(self):
174+
parameters = {
175+
**self.serialize_header_param(
176+
"Content-Type", "application/json",
177+
),
178+
**self.serialize_header_param(
179+
"Accept", "application/json",
180+
),
181+
}
182+
return parameters
183+
184+
@property
185+
def content(self):
186+
_content_value, _builder = self.new_content_builder(
187+
self.ctx.args,
188+
typ=AAZObjectType,
189+
typ_kwargs={"flags": {"required": True, "client_flatten": True}}
190+
)
191+
_builder.set_prop("access", AAZStrType, ".access_level", typ_kwargs={"flags": {"required": True}})
192+
_builder.set_prop("durationInSeconds", AAZIntType, ".duration_in_seconds", typ_kwargs={"flags": {"required": True}})
193+
_builder.set_prop("getSecureVMGuestStateSAS", AAZBoolType, ".secure_vm_guest_state_sas")
194+
195+
return self.serialize_content(_content_value)
196+
197+
def on_200(self, session):
198+
data = self.deserialize_http_content(session)
199+
self.ctx.set_var(
200+
"instance",
201+
data,
202+
schema_builder=self._build_schema_on_200
203+
)
204+
205+
_schema_on_200 = None
206+
207+
@classmethod
208+
def _build_schema_on_200(cls):
209+
if cls._schema_on_200 is not None:
210+
return cls._schema_on_200
211+
212+
cls._schema_on_200 = AAZObjectType()
213+
214+
_schema_on_200 = cls._schema_on_200
215+
_schema_on_200.access_sas = AAZStrType(
216+
serialized_name="accessSAS",
217+
flags={"read_only": True},
218+
)
219+
_schema_on_200.security_data_access_sas = AAZStrType(
220+
serialized_name="securityDataAccessSAS",
221+
flags={"read_only": True},
222+
)
223+
224+
return cls._schema_on_200
225+
226+
227+
class _GrantAccessHelper:
228+
"""Helper class for GrantAccess"""
229+
230+
231+
__all__ = ["GrantAccess"]

src/azure-cli/azure/cli/command_modules/vm/aaz/latest/disk/_show.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ def _build_schema_on_200(cls):
256256
)
257257
properties.property_updates_in_progress = AAZObjectType(
258258
serialized_name="propertyUpdatesInProgress",
259+
flags={"read_only": True},
259260
)
260261
properties.provisioning_state = AAZStrType(
261262
serialized_name="provisioningState",

0 commit comments

Comments
 (0)