Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def _build_arguments_schema(cls, *args, **kwargs):

_args_schema.configurations = AAZFileArg(
options=["--config-template-file","--configuration-template-file"],
help="Link to File containing Config expressions for this config version"
help="Link to File containing Config expressions for this config version",
required=True
)
return cls._args_schema

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,25 @@ def _build_arguments_schema(cls, *args, **kwargs):
# help="The resource-specific properties for this resource.",
# nullable=True,
# )
_args_schema.version = AAZStrArg(
options=["--version"],
help="The version of the solution to show configuration for. Defaults to 'version1' if not specified."
)
return cls._args_schema

def _execute_operations(self):
self.pre_operations()
config_name = str(self.ctx.args.level_name)
if len(config_name) > 18:
config_name = config_name[:18] + "Config"
version = self.ctx.args.version
if version is not None and str(version).lower() != "undefined":
self.SolutionRevisionGet(ctx=self.ctx)()
else:
config_name = config_name + "Config"
self.ctx.args.level_name = config_name
self.SolutionsGet(ctx=self.ctx)()
config_name = str(self.ctx.args.level_name)
if len(config_name) > 18:
config_name = config_name[:18] + "Config"
else:
config_name = config_name + "Config"
self.ctx.args.level_name = config_name
self.SolutionsGet(ctx=self.ctx)()
self.post_operations()

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

class SolutionsGet(AAZHttpOperation):
CLIENT_TYPE = "MgmtClient"
Expand Down Expand Up @@ -259,7 +266,153 @@ def _build_schema_on_200(cls):
tags.Element = AAZStrType()

return cls._schema_on_200

class SolutionRevisionGet(AAZHttpOperation):
CLIENT_TYPE = "MgmtClient"

def __call__(self, *args, **kwargs):
request = self.make_request()
session = self.client.send_request(request=request, stream=False, **kwargs)
if session.http_response.status_code in [200]:
return self.on_200(session)
config = dict()
config["properties"] = dict()
config["properties"]["values"] = "{}"
if session.http_response.status_code in [404]:
self.ctx.set_var(
"instance",
config,
schema_builder=self._build_schema_on_404
)
else:
return self.on_error(session.http_response)

@property
def url(self):
return self.client.format_url(
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Edge/targets/{targetName}/solutions/{solutionName}/versions/{version}",
**self.url_parameters
)

@property
def method(self):
return "GET"

@property
def error_format(self):
return "MgmtErrorFormat"

@property
def url_parameters(self):
parameters = {
**self.serialize_url_param(
"resourceGroupName", self.ctx.args.resource_group,
required=True,
),
**self.serialize_url_param(
"subscriptionId", self.ctx.subscription_id,
required=True,
),
**self.serialize_url_param(
"targetName", self.ctx.args.level_name if not str(self.ctx.args.level_name).endswith('Config') else str(self.ctx.args.level_name)[:-6],
required=True,
),
**self.serialize_url_param(
"solutionName", self.ctx.args.solution_name,
required=True,
),
**self.serialize_url_param(
"version", self.ctx.args.version,
required=True,
),
}
return parameters

@property
def query_parameters(self):
parameters = {
**self.serialize_query_param(
"api-version", "2025-06-01",
required=True,
),
}
return parameters

@property
def header_parameters(self):
parameters = {
**self.serialize_header_param(
"Accept", "application/json",
),
}
return parameters

def on_200(self, session):
data = self.deserialize_http_content(session)
config = dict()
config["properties"] = dict()
config["properties"]["values"] = data.get("properties", {}).get("configuration", "")
self.ctx.set_var(
"instance",
config,
schema_builder=self._build_schema_on_200
)

@classmethod
def _build_schema_on_404(cls):
cls._schema_on_200 = AAZObjectType()
_schema_on_200 = cls._schema_on_200
_schema_on_200.properties = AAZFreeFormDictType()
return cls._schema_on_200

@classmethod
def _build_schema_on_200(cls):
cls._schema_on_200 = AAZObjectType()
_schema_on_200 = cls._schema_on_200
_schema_on_200.id = AAZStrType(
flags={"read_only": True},
)
_schema_on_200.location = AAZStrType(
flags={"required": False},
)
_schema_on_200.name = AAZStrType(
flags={"read_only": True},
)
_schema_on_200.properties = AAZObjectType()
_schema_on_200.properties.values = AAZStrType()
_schema_on_200.system_data = AAZObjectType(
serialized_name="systemData",
flags={"read_only": True},
)
_schema_on_200.tags = AAZDictType()
_schema_on_200.type = AAZStrType(
flags={"read_only": True},
)

system_data = cls._schema_on_200.system_data
system_data.created_at = AAZStrType(
serialized_name="createdAt",
)
system_data.created_by = AAZStrType(
serialized_name="createdBy",
)
system_data.created_by_type = AAZStrType(
serialized_name="createdByType",
)
system_data.last_modified_at = AAZStrType(
serialized_name="lastModifiedAt",
)
system_data.last_modified_by = AAZStrType(
serialized_name="lastModifiedBy",
)
system_data.last_modified_by_type = AAZStrType(
serialized_name="lastModifiedByType",
)

tags = cls._schema_on_200.tags
tags.Element = AAZStrType()

return cls._schema_on_200

class _ShowHelper:
"""Helper class for Show"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@
from ._show import *
# from ._update import *
from ._wait import *
from ._use_context import *
from ._set_context import *
from ._current_context import *
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ def _build_arguments_schema(cls, *args, **kwargs):
options=["--capabilities"],
arg_group="Properties",
help="List of Capabilities",
required=True
)
_args_schema.hierarchies = AAZListArg(
options=["--hierarchies"],
arg_group="Properties",
help="List of Hierarchies",
required=True
)

capabilities = cls._args_schema.capabilities
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *

@register_command(
"workload-orchestration context current",
)
class CurrentContext(AAZCommand):
"""Show current context information
:example: Show current context
az workload-orchestration context current
"""

_aaz_info = {
"version": "2025-06-01"
}

def _handler(self, command_args):
super()._handler(command_args)
self._execute_operations()
return self._output()

_args_schema = None

@classmethod
def _build_arguments_schema(cls, *args, **kwargs):
if cls._args_schema is not None:
return cls._args_schema
cls._args_schema = super()._build_arguments_schema(*args, **kwargs)
return cls._args_schema

def _execute_operations(self):
self.pre_operations()
# No operations needed - just reading config
self.post_operations()

@register_callback
def pre_operations(self):
pass

@register_callback
def post_operations(self):
pass

def _output(self, *args, **kwargs):
context_id = self.ctx.cli_ctx.config.get('workload_orchestration', 'context_id', None)
context_name = self.ctx.cli_ctx.config.get('workload_orchestration', 'context_name', None)
resource_group = self.ctx.cli_ctx.config.get('workload_orchestration', 'resource_group', None)

if not context_id or not context_name or not resource_group:
return "No current context is set"

return {
"contextId": context_id,
"name": context_name,
"resourceGroup": resource_group
}

class _CurrentContextHelper:
"""Helper class for CurrentContext"""

__all__ = ["CurrentContext"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *

@register_command(
"workload-orchestration context set",
)
class SetContext(AAZCommand):
"""Set current context using context ID
:example: Set a Context using ID
az workload-orchestration context set --id /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Edge/contexts/myContext
"""

_aaz_info = {
"version": "2025-06-01"
}

def _handler(self, command_args):
super()._handler(command_args)
self._execute_operations()
return self._output()

_args_schema = None

@classmethod
def _build_arguments_schema(cls, *args, **kwargs):
if cls._args_schema is not None:
return cls._args_schema
cls._args_schema = super()._build_arguments_schema(*args, **kwargs)

_args_schema = cls._args_schema
_args_schema.context_id = AAZStrArg(
options=["--id"],
help="The full resource ID of the Context.",
required=True
)
return cls._args_schema

def _execute_operations(self):
self.pre_operations()
# Extract context name and resource group from ID
# ID format: /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Edge/contexts/{name}
context_id = self.ctx.args.context_id.to_serialized_data()
parts = context_id.split('/')
if len(parts) != 9 or parts[6] != 'Microsoft.Edge' or parts[7] != 'contexts':
raise CLIInternalError("Invalid context ID format")

context_name = parts[8]
resource_group = parts[4]

self.post_operations()

@register_callback
def pre_operations(self):
pass

@register_callback
def post_operations(self):
pass

def _output(self, *args, **kwargs):
context_id = self.ctx.args.context_id.to_serialized_data()
parts = context_id.split('/')
context_name = parts[8]
resource_group = parts[4]

self.ctx.cli_ctx.config.set_value('workload_orchestration', 'context_id', context_id)
self.ctx.cli_ctx.config.set_value('workload_orchestration', 'context_name', context_name)
self.ctx.cli_ctx.config.set_value('workload_orchestration', 'resource_group', resource_group)

return f"Successfully set current context using ID '{self.ctx.args.context_id}'"

class _SetContextHelper:
"""Helper class for SetContext"""

__all__ = ["SetContext"]
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def _build_arguments_schema(cls, *args, **kwargs):

def _execute_operations(self):
self.pre_operations()

self.ContextsGet(ctx=self.ctx)()
self.post_operations()

Expand Down
Loading
Loading