diff --git a/src/workload-orchestration/HISTORY.rst b/src/workload-orchestration/HISTORY.rst index f80c37473ad..17f30fdae16 100644 --- a/src/workload-orchestration/HISTORY.rst +++ b/src/workload-orchestration/HISTORY.rst @@ -2,6 +2,11 @@ Release History =============== +5.1.1 +++++++ +* Resolved solution template name to uniqueIdentifier for ``az workload-orchestration target solution-revision-list`` and ``az workload-orchestration target solution-instance-list`` +* Added shared ``_target_helper.py`` for reusable solution template resolution logic + 5.1.0 ++++++ * Added new target solution management command: diff --git a/src/workload-orchestration/azext_workload_orchestration/aaz/latest/workload_orchestration/target/_solution_instance_list.py b/src/workload-orchestration/azext_workload_orchestration/aaz/latest/workload_orchestration/target/_solution_instance_list.py index b9b3eb5ec91..c3f51badf41 100644 --- a/src/workload-orchestration/azext_workload_orchestration/aaz/latest/workload_orchestration/target/_solution_instance_list.py +++ b/src/workload-orchestration/azext_workload_orchestration/aaz/latest/workload_orchestration/target/_solution_instance_list.py @@ -9,6 +9,7 @@ # flake8: noqa from azure.cli.core.aaz import * +from ._target_helper import TargetHelper @register_command( @@ -89,6 +90,14 @@ class SolutionInstancesList(AAZHttpOperation): CLIENT_TYPE = "MgmtClient" def __call__(self, *args, **kwargs): + # Resolve solution template name to its uniqueIdentifier + self.unique_identifier = TargetHelper.get_solution_template_unique_identifier( + self.ctx.subscription_id, + self.ctx.args.resource_group, + self.ctx.args.solution_name, + self.client + ) + request = self.make_request() session = self.client.send_request(request=request, stream=False, **kwargs) if session.http_response.status_code in [200]: @@ -127,7 +136,7 @@ def url_parameters(self): required=True, ), **self.serialize_url_param( - "solutionName", self.ctx.args.solution_name, + "solutionName", self.unique_identifier, required=True, ), } diff --git a/src/workload-orchestration/azext_workload_orchestration/aaz/latest/workload_orchestration/target/_solution_revision_list.py b/src/workload-orchestration/azext_workload_orchestration/aaz/latest/workload_orchestration/target/_solution_revision_list.py index 48bcb2fdc1e..ae13ca619e7 100644 --- a/src/workload-orchestration/azext_workload_orchestration/aaz/latest/workload_orchestration/target/_solution_revision_list.py +++ b/src/workload-orchestration/azext_workload_orchestration/aaz/latest/workload_orchestration/target/_solution_revision_list.py @@ -9,6 +9,7 @@ # flake8: noqa from azure.cli.core.aaz import * +from ._target_helper import TargetHelper @register_command( @@ -92,6 +93,14 @@ class TargetSolutionRevisionsList(AAZHttpOperation): CLIENT_TYPE = "MgmtClient" def __call__(self, *args, **kwargs): + # Resolve solution template name to its uniqueIdentifier + self.unique_identifier = TargetHelper.get_solution_template_unique_identifier( + self.ctx.subscription_id, + self.ctx.args.resource_group, + self.ctx.args.solution_name, + self.client + ) + request = self.make_request() session = self.client.send_request(request=request, stream=False, **kwargs) if session.http_response.status_code in [200]: @@ -122,7 +131,7 @@ def url_parameters(self): required=True, ), **self.serialize_url_param( - "solutionName", self.ctx.args.solution_name, + "solutionName", self.unique_identifier, required=True, ), **self.serialize_url_param( diff --git a/src/workload-orchestration/azext_workload_orchestration/aaz/latest/workload_orchestration/target/_target_helper.py b/src/workload-orchestration/azext_workload_orchestration/aaz/latest/workload_orchestration/target/_target_helper.py new file mode 100644 index 00000000000..91f27810d59 --- /dev/null +++ b/src/workload-orchestration/azext_workload_orchestration/aaz/latest/workload_orchestration/target/_target_helper.py @@ -0,0 +1,71 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- +# Code generated by aaz-dev-tools. DO NOT EDIT. + +# pylint: skip-file +# flake8: noqa + + +class TargetHelper: + """Shared helper for target commands.""" + + @staticmethod + def get_solution_template_unique_identifier(subscription_id, resource_group_name, template_name, client): + """Fetch the solution template and return its uniqueIdentifier from properties. + + Args: + subscription_id: The subscription ID + resource_group_name: The resource group name + template_name: The solution template name + client: HTTP client for making the request + + Returns: + str: The uniqueIdentifier from template properties, or template_name as fallback + + Raises: + CLIInternalError: If the template does not exist or the request fails + """ + from azure.cli.core.azclierror import CLIInternalError + import json + + template_url = client.format_url( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Edge/solutionTemplates/{solutionTemplateName}", + subscriptionId=subscription_id, + resourceGroupName=resource_group_name, + solutionTemplateName=template_name + ) + request = client._request("GET", template_url, { + "api-version": "2025-08-01" + }, { + "Accept": "application/json" + }, None, {}, None) + + try: + response = client.send_request(request=request, stream=False) + + if response.http_response.status_code == 404: + raise CLIInternalError( + f"Solution template '{template_name}' not found in resource group '{resource_group_name}'." + ) + if response.http_response.status_code != 200: + raise CLIInternalError( + f"Failed to get solution template '{template_name}': HTTP {response.http_response.status_code}" + ) + + data = json.loads(response.http_response.text()) + unique_identifier = data.get("properties", {}).get("uniqueIdentifier") + + if unique_identifier and unique_identifier.strip(): + return unique_identifier + return template_name + except CLIInternalError: + # Propagate explicitly raised CLIInternalError instances unchanged. + raise + except Exception as exc: + # Wrap unexpected errors (e.g., network issues, JSON parsing failures) + # in CLIInternalError to match the documented behavior. + raise CLIInternalError( + f"Failed to get solution template '{template_name}': {exc}" + ) from exc diff --git a/src/workload-orchestration/setup.py b/src/workload-orchestration/setup.py index 32448955dc4..d0abcead415 100644 --- a/src/workload-orchestration/setup.py +++ b/src/workload-orchestration/setup.py @@ -10,7 +10,7 @@ # HISTORY.rst entry. -VERSION = '5.1.0' +VERSION = '5.1.1' # The full list of classifiers is available at # https://pypi.python.org/pypi?%3Aaction=list_classifiers