Skip to content

Commit 93679b3

Browse files
atharvauAtharvamanaswita-chichili
authored
[ Workload-Orchestration ] Add Context & Solution Management Commands (#9037)
* added * commit * Made Changes * Added change * Made changes * List solution revisions and instances * Made changes rr * Made change --------- Co-authored-by: Atharva <audapure@microsoft.com> Co-authored-by: Manaswita Chichili <mchichili@microsoft.com>
1 parent 513c59f commit 93679b3

File tree

14 files changed

+1027
-11
lines changed

14 files changed

+1027
-11
lines changed

src/workload-orchestration/azext_workload_orchestration/aaz/latest/workload_orchestration/config_template/_create.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ def _build_arguments_schema(cls, *args, **kwargs):
101101

102102
_args_schema.configurations = AAZFileArg(
103103
options=["--config-template-file","--configuration-template-file"],
104-
help="Link to File containing Config expressions for this config version"
104+
help="Link to File containing Config expressions for this config version",
105+
required=True
105106
)
106107
return cls._args_schema
107108

src/workload-orchestration/azext_workload_orchestration/aaz/latest/workload_orchestration/configuration/_config_show.py

Lines changed: 160 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,25 @@ def _build_arguments_schema(cls, *args, **kwargs):
7777
# help="The resource-specific properties for this resource.",
7878
# nullable=True,
7979
# )
80+
_args_schema.version = AAZStrArg(
81+
options=["--version"],
82+
help="The version of the solution to show configuration for. Defaults to 'version1' if not specified."
83+
)
8084
return cls._args_schema
8185

8286
def _execute_operations(self):
8387
self.pre_operations()
84-
config_name = str(self.ctx.args.level_name)
85-
if len(config_name) > 18:
86-
config_name = config_name[:18] + "Config"
88+
version = self.ctx.args.version
89+
if version is not None and str(version).lower() != "undefined":
90+
self.SolutionRevisionGet(ctx=self.ctx)()
8791
else:
88-
config_name = config_name + "Config"
89-
self.ctx.args.level_name = config_name
90-
self.SolutionsGet(ctx=self.ctx)()
92+
config_name = str(self.ctx.args.level_name)
93+
if len(config_name) > 18:
94+
config_name = config_name[:18] + "Config"
95+
else:
96+
config_name = config_name + "Config"
97+
self.ctx.args.level_name = config_name
98+
self.SolutionsGet(ctx=self.ctx)()
9199
self.post_operations()
92100

93101
@register_callback
@@ -101,7 +109,6 @@ def post_operations(self):
101109
def _output(self, *args, **kwargs):
102110
result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True)
103111
print(result["properties"]["values"])
104-
pass
105112

106113
class SolutionsGet(AAZHttpOperation):
107114
CLIENT_TYPE = "MgmtClient"
@@ -259,7 +266,153 @@ def _build_schema_on_200(cls):
259266
tags.Element = AAZStrType()
260267

261268
return cls._schema_on_200
269+
270+
class SolutionRevisionGet(AAZHttpOperation):
271+
CLIENT_TYPE = "MgmtClient"
272+
273+
def __call__(self, *args, **kwargs):
274+
request = self.make_request()
275+
session = self.client.send_request(request=request, stream=False, **kwargs)
276+
if session.http_response.status_code in [200]:
277+
return self.on_200(session)
278+
config = dict()
279+
config["properties"] = dict()
280+
config["properties"]["values"] = "{}"
281+
if session.http_response.status_code in [404]:
282+
self.ctx.set_var(
283+
"instance",
284+
config,
285+
schema_builder=self._build_schema_on_404
286+
)
287+
else:
288+
return self.on_error(session.http_response)
289+
290+
@property
291+
def url(self):
292+
return self.client.format_url(
293+
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Edge/targets/{targetName}/solutions/{solutionName}/versions/{version}",
294+
**self.url_parameters
295+
)
296+
297+
@property
298+
def method(self):
299+
return "GET"
300+
301+
@property
302+
def error_format(self):
303+
return "MgmtErrorFormat"
262304

305+
@property
306+
def url_parameters(self):
307+
parameters = {
308+
**self.serialize_url_param(
309+
"resourceGroupName", self.ctx.args.resource_group,
310+
required=True,
311+
),
312+
**self.serialize_url_param(
313+
"subscriptionId", self.ctx.subscription_id,
314+
required=True,
315+
),
316+
**self.serialize_url_param(
317+
"targetName", self.ctx.args.level_name if not str(self.ctx.args.level_name).endswith('Config') else str(self.ctx.args.level_name)[:-6],
318+
required=True,
319+
),
320+
**self.serialize_url_param(
321+
"solutionName", self.ctx.args.solution_name,
322+
required=True,
323+
),
324+
**self.serialize_url_param(
325+
"version", self.ctx.args.version,
326+
required=True,
327+
),
328+
}
329+
return parameters
330+
331+
@property
332+
def query_parameters(self):
333+
parameters = {
334+
**self.serialize_query_param(
335+
"api-version", "2025-06-01",
336+
required=True,
337+
),
338+
}
339+
return parameters
340+
341+
@property
342+
def header_parameters(self):
343+
parameters = {
344+
**self.serialize_header_param(
345+
"Accept", "application/json",
346+
),
347+
}
348+
return parameters
349+
350+
def on_200(self, session):
351+
data = self.deserialize_http_content(session)
352+
config = dict()
353+
config["properties"] = dict()
354+
config["properties"]["values"] = data.get("properties", {}).get("configuration", "")
355+
self.ctx.set_var(
356+
"instance",
357+
config,
358+
schema_builder=self._build_schema_on_200
359+
)
360+
361+
@classmethod
362+
def _build_schema_on_404(cls):
363+
cls._schema_on_200 = AAZObjectType()
364+
_schema_on_200 = cls._schema_on_200
365+
_schema_on_200.properties = AAZFreeFormDictType()
366+
return cls._schema_on_200
367+
368+
@classmethod
369+
def _build_schema_on_200(cls):
370+
cls._schema_on_200 = AAZObjectType()
371+
_schema_on_200 = cls._schema_on_200
372+
_schema_on_200.id = AAZStrType(
373+
flags={"read_only": True},
374+
)
375+
_schema_on_200.location = AAZStrType(
376+
flags={"required": False},
377+
)
378+
_schema_on_200.name = AAZStrType(
379+
flags={"read_only": True},
380+
)
381+
_schema_on_200.properties = AAZObjectType()
382+
_schema_on_200.properties.values = AAZStrType()
383+
_schema_on_200.system_data = AAZObjectType(
384+
serialized_name="systemData",
385+
flags={"read_only": True},
386+
)
387+
_schema_on_200.tags = AAZDictType()
388+
_schema_on_200.type = AAZStrType(
389+
flags={"read_only": True},
390+
)
391+
392+
system_data = cls._schema_on_200.system_data
393+
system_data.created_at = AAZStrType(
394+
serialized_name="createdAt",
395+
)
396+
system_data.created_by = AAZStrType(
397+
serialized_name="createdBy",
398+
)
399+
system_data.created_by_type = AAZStrType(
400+
serialized_name="createdByType",
401+
)
402+
system_data.last_modified_at = AAZStrType(
403+
serialized_name="lastModifiedAt",
404+
)
405+
system_data.last_modified_by = AAZStrType(
406+
serialized_name="lastModifiedBy",
407+
)
408+
system_data.last_modified_by_type = AAZStrType(
409+
serialized_name="lastModifiedByType",
410+
)
411+
412+
tags = cls._schema_on_200.tags
413+
tags.Element = AAZStrType()
414+
415+
return cls._schema_on_200
263416

264417
class _ShowHelper:
265418
"""Helper class for Show"""

src/workload-orchestration/azext_workload_orchestration/aaz/latest/workload_orchestration/context/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@
2020
from ._show import *
2121
# from ._update import *
2222
from ._wait import *
23+
from ._use_context import *
24+
from ._set_context import *
25+
from ._current_context import *

src/workload-orchestration/azext_workload_orchestration/aaz/latest/workload_orchestration/context/_create.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ def _build_arguments_schema(cls, *args, **kwargs):
6565
options=["--capabilities"],
6666
arg_group="Properties",
6767
help="List of Capabilities",
68+
required=True
6869
)
6970
_args_schema.hierarchies = AAZListArg(
7071
options=["--hierarchies"],
7172
arg_group="Properties",
7273
help="List of Hierarchies",
74+
required=True
7375
)
7476

7577
capabilities = cls._args_schema.capabilities
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
6+
# pylint: skip-file
7+
# flake8: noqa
8+
9+
from azure.cli.core.aaz import *
10+
11+
@register_command(
12+
"workload-orchestration context current",
13+
)
14+
class CurrentContext(AAZCommand):
15+
"""Show current context information
16+
:example: Show current context
17+
az workload-orchestration context current
18+
"""
19+
20+
_aaz_info = {
21+
"version": "2025-06-01"
22+
}
23+
24+
def _handler(self, command_args):
25+
super()._handler(command_args)
26+
self._execute_operations()
27+
return self._output()
28+
29+
_args_schema = None
30+
31+
@classmethod
32+
def _build_arguments_schema(cls, *args, **kwargs):
33+
if cls._args_schema is not None:
34+
return cls._args_schema
35+
cls._args_schema = super()._build_arguments_schema(*args, **kwargs)
36+
return cls._args_schema
37+
38+
def _execute_operations(self):
39+
self.pre_operations()
40+
# No operations needed - just reading config
41+
self.post_operations()
42+
43+
@register_callback
44+
def pre_operations(self):
45+
pass
46+
47+
@register_callback
48+
def post_operations(self):
49+
pass
50+
51+
def _output(self, *args, **kwargs):
52+
context_id = self.ctx.cli_ctx.config.get('workload_orchestration', 'context_id', None)
53+
context_name = self.ctx.cli_ctx.config.get('workload_orchestration', 'context_name', None)
54+
resource_group = self.ctx.cli_ctx.config.get('workload_orchestration', 'resource_group', None)
55+
56+
if not context_id or not context_name or not resource_group:
57+
return "No current context is set"
58+
59+
return {
60+
"contextId": context_id,
61+
"name": context_name,
62+
"resourceGroup": resource_group
63+
}
64+
65+
class _CurrentContextHelper:
66+
"""Helper class for CurrentContext"""
67+
68+
__all__ = ["CurrentContext"]
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
6+
# pylint: skip-file
7+
# flake8: noqa
8+
9+
from azure.cli.core.aaz import *
10+
11+
@register_command(
12+
"workload-orchestration context set",
13+
)
14+
class SetContext(AAZCommand):
15+
"""Set current context using context ID
16+
:example: Set a Context using ID
17+
az workload-orchestration context set --id /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Edge/contexts/myContext
18+
"""
19+
20+
_aaz_info = {
21+
"version": "2025-06-01"
22+
}
23+
24+
def _handler(self, command_args):
25+
super()._handler(command_args)
26+
self._execute_operations()
27+
return self._output()
28+
29+
_args_schema = None
30+
31+
@classmethod
32+
def _build_arguments_schema(cls, *args, **kwargs):
33+
if cls._args_schema is not None:
34+
return cls._args_schema
35+
cls._args_schema = super()._build_arguments_schema(*args, **kwargs)
36+
37+
_args_schema = cls._args_schema
38+
_args_schema.context_id = AAZStrArg(
39+
options=["--id"],
40+
help="The full resource ID of the Context.",
41+
required=True
42+
)
43+
return cls._args_schema
44+
45+
def _execute_operations(self):
46+
self.pre_operations()
47+
# Extract context name and resource group from ID
48+
# ID format: /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Edge/contexts/{name}
49+
context_id = self.ctx.args.context_id.to_serialized_data()
50+
parts = context_id.split('/')
51+
if len(parts) != 9 or parts[6] != 'Microsoft.Edge' or parts[7] != 'contexts':
52+
raise CLIInternalError("Invalid context ID format")
53+
54+
context_name = parts[8]
55+
resource_group = parts[4]
56+
57+
self.post_operations()
58+
59+
@register_callback
60+
def pre_operations(self):
61+
pass
62+
63+
@register_callback
64+
def post_operations(self):
65+
pass
66+
67+
def _output(self, *args, **kwargs):
68+
context_id = self.ctx.args.context_id.to_serialized_data()
69+
parts = context_id.split('/')
70+
context_name = parts[8]
71+
resource_group = parts[4]
72+
73+
self.ctx.cli_ctx.config.set_value('workload_orchestration', 'context_id', context_id)
74+
self.ctx.cli_ctx.config.set_value('workload_orchestration', 'context_name', context_name)
75+
self.ctx.cli_ctx.config.set_value('workload_orchestration', 'resource_group', resource_group)
76+
77+
return f"Successfully set current context using ID '{self.ctx.args.context_id}'"
78+
79+
class _SetContextHelper:
80+
"""Helper class for SetContext"""
81+
82+
__all__ = ["SetContext"]

src/workload-orchestration/azext_workload_orchestration/aaz/latest/workload_orchestration/context/_show.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def _build_arguments_schema(cls, *args, **kwargs):
6161

6262
def _execute_operations(self):
6363
self.pre_operations()
64+
6465
self.ContextsGet(ctx=self.ctx)()
6566
self.post_operations()
6667

0 commit comments

Comments
 (0)