Skip to content

Commit e23a739

Browse files
author
Deep Nandu
committed
Add guest-subscription commands, tests for computelimit extension
1 parent a2c85d2 commit e23a739

20 files changed

Lines changed: 1620 additions & 5 deletions

src/computelimit/HISTORY.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ Release History
55

66
1.0.0b1
77
++++++
8-
* Initial release.
8+
* Initial release.
9+
* Add shared-limit commands (add, remove, show, list).
10+
* Add guest-subscription commands (add, remove, show, list).

src/computelimit/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This is an extension to Azure CLI to manage Computelimit resources.
55
Install the Computelimit extension using the CLI command below
66

77
```
8-
az extension add --name az computelimit
8+
az extension add --name computelimit
99
```
1010

1111
### Included features ###

src/computelimit/azext_computelimit/aaz/latest/computelimit/__cmd_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
is_preview=True,
1717
)
1818
class __CMDGroup(AAZCommandGroup):
19-
"""Manage Compute Limit
19+
"""Manage compute shared limit resources
2020
"""
2121
pass
2222

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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_group(
15+
"computelimit guest-subscription",
16+
is_preview=True,
17+
)
18+
class __CMDGroup(AAZCommandGroup):
19+
"""Manage Guest Subscription
20+
"""
21+
pass
22+
23+
24+
__all__ = ["__CMDGroup"]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 .__cmd_group import *
12+
from ._add import *
13+
from ._list import *
14+
from ._remove import *
15+
from ._show import *
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
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+
"computelimit guest-subscription add",
16+
is_preview=True,
17+
)
18+
class Add(AAZCommand):
19+
"""Add a subscription as a guest to consume the compute limits shared by the host subscription.
20+
21+
:example: Add a guest subscription
22+
az computelimit guest-subscription add --location eastus --guest-subscription-id 11111111-1111-1111-1111-111111111111
23+
"""
24+
25+
_aaz_info = {
26+
"version": "2025-08-15",
27+
"resources": [
28+
["mgmt-plane", "/subscriptions/{}/providers/microsoft.computelimit/locations/{}/guestsubscriptions/{}", "2025-08-15"],
29+
]
30+
}
31+
32+
def _handler(self, command_args):
33+
super()._handler(command_args)
34+
self._execute_operations()
35+
return self._output()
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.guest_subscription_id = AAZStrArg(
49+
options=["--id", "--guest-subscription-id"],
50+
help="The guest subscription id",
51+
required=True,
52+
id_part="child_name_1",
53+
fmt=AAZStrArgFormat(
54+
pattern="^[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$",
55+
),
56+
)
57+
_args_schema.location = AAZResourceLocationArg(
58+
help="The Azure location name",
59+
required=True,
60+
id_part="name",
61+
)
62+
return cls._args_schema
63+
64+
def _execute_operations(self):
65+
self.pre_operations()
66+
self.GuestSubscriptionsCreate(ctx=self.ctx)()
67+
self.post_operations()
68+
69+
@register_callback
70+
def pre_operations(self):
71+
pass
72+
73+
@register_callback
74+
def post_operations(self):
75+
pass
76+
77+
def _output(self, *args, **kwargs):
78+
result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True)
79+
return result
80+
81+
class GuestSubscriptionsCreate(AAZHttpOperation):
82+
CLIENT_TYPE = "MgmtClient"
83+
84+
def __call__(self, *args, **kwargs):
85+
request = self.make_request()
86+
session = self.client.send_request(request=request, stream=False, **kwargs)
87+
if session.http_response.status_code in [200, 201]:
88+
return self.on_200_201(session)
89+
90+
return self.on_error(session.http_response)
91+
92+
@property
93+
def url(self):
94+
return self.client.format_url(
95+
"/subscriptions/{subscriptionId}/providers/Microsoft.ComputeLimit/locations/{location}/guestSubscriptions/{guestSubscriptionId}",
96+
**self.url_parameters
97+
)
98+
99+
@property
100+
def method(self):
101+
return "PUT"
102+
103+
@property
104+
def error_format(self):
105+
return "MgmtErrorFormat"
106+
107+
@property
108+
def url_parameters(self):
109+
parameters = {
110+
**self.serialize_url_param(
111+
"guestSubscriptionId", self.ctx.args.guest_subscription_id,
112+
required=True,
113+
),
114+
**self.serialize_url_param(
115+
"location", self.ctx.args.location,
116+
required=True,
117+
),
118+
**self.serialize_url_param(
119+
"subscriptionId", self.ctx.subscription_id,
120+
required=True,
121+
),
122+
}
123+
return parameters
124+
125+
@property
126+
def query_parameters(self):
127+
parameters = {
128+
**self.serialize_query_param(
129+
"api-version", "2025-08-15",
130+
required=True,
131+
),
132+
}
133+
return parameters
134+
135+
@property
136+
def header_parameters(self):
137+
parameters = {
138+
**self.serialize_header_param(
139+
"Content-Type", "application/json",
140+
),
141+
**self.serialize_header_param(
142+
"Accept", "application/json",
143+
),
144+
}
145+
return parameters
146+
147+
@property
148+
def content(self):
149+
_content_value, _builder = self.new_content_builder(
150+
self.ctx.args,
151+
typ=AAZObjectType,
152+
typ_kwargs={"flags": {"required": True, "client_flatten": True}}
153+
)
154+
155+
return self.serialize_content(_content_value)
156+
157+
def on_200_201(self, session):
158+
data = self.deserialize_http_content(session)
159+
self.ctx.set_var(
160+
"instance",
161+
data,
162+
schema_builder=self._build_schema_on_200_201
163+
)
164+
165+
_schema_on_200_201 = None
166+
167+
@classmethod
168+
def _build_schema_on_200_201(cls):
169+
if cls._schema_on_200_201 is not None:
170+
return cls._schema_on_200_201
171+
172+
cls._schema_on_200_201 = AAZObjectType()
173+
174+
_schema_on_200_201 = cls._schema_on_200_201
175+
_schema_on_200_201.id = AAZStrType(
176+
flags={"read_only": True},
177+
)
178+
_schema_on_200_201.name = AAZStrType(
179+
flags={"read_only": True},
180+
)
181+
_schema_on_200_201.properties = AAZObjectType(
182+
flags={"client_flatten": True},
183+
)
184+
_schema_on_200_201.system_data = AAZObjectType(
185+
serialized_name="systemData",
186+
flags={"read_only": True},
187+
)
188+
_schema_on_200_201.type = AAZStrType(
189+
flags={"read_only": True},
190+
)
191+
192+
properties = cls._schema_on_200_201.properties
193+
properties.provisioning_state = AAZStrType(
194+
serialized_name="provisioningState",
195+
flags={"read_only": True},
196+
)
197+
198+
system_data = cls._schema_on_200_201.system_data
199+
system_data.created_at = AAZStrType(
200+
serialized_name="createdAt",
201+
)
202+
system_data.created_by = AAZStrType(
203+
serialized_name="createdBy",
204+
)
205+
system_data.created_by_type = AAZStrType(
206+
serialized_name="createdByType",
207+
)
208+
system_data.last_modified_at = AAZStrType(
209+
serialized_name="lastModifiedAt",
210+
)
211+
system_data.last_modified_by = AAZStrType(
212+
serialized_name="lastModifiedBy",
213+
)
214+
system_data.last_modified_by_type = AAZStrType(
215+
serialized_name="lastModifiedByType",
216+
)
217+
218+
return cls._schema_on_200_201
219+
220+
221+
class _AddHelper:
222+
"""Helper class for Add"""
223+
224+
225+
__all__ = ["Add"]

0 commit comments

Comments
 (0)