diff --git a/src/durabletask/HISTORY.rst b/src/durabletask/HISTORY.rst index 53d91dc1178..9249a25f71c 100644 --- a/src/durabletask/HISTORY.rst +++ b/src/durabletask/HISTORY.rst @@ -3,6 +3,10 @@ Release History =============== +1.0.0b4 ++++++ +* Adding various retention-policy commands. + 1.0.0b3 +++++ * Updating the help outputs for various taskhub and scheduler commands diff --git a/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/__cmd_group.py b/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/__cmd_group.py new file mode 100644 index 00000000000..e7ddde86c53 --- /dev/null +++ b/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/__cmd_group.py @@ -0,0 +1,23 @@ +# -------------------------------------------------------------------------------------------- +# 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 +# -------------------------------------------------------------------------------------------- + +# pylint: skip-file +# flake8: noqa + +from azure.cli.core.aaz import * + + +@register_command_group( + "durabletask retention-policy", +) +class __CMDGroup(AAZCommandGroup): + """Manage Retention Policy + """ + pass + + +__all__ = ["__CMDGroup"] diff --git a/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/__init__.py b/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/__init__.py new file mode 100644 index 00000000000..a66fcaa1a56 --- /dev/null +++ b/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/__init__.py @@ -0,0 +1,16 @@ +# -------------------------------------------------------------------------------------------- +# 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 +# -------------------------------------------------------------------------------------------- + +# pylint: skip-file +# flake8: noqa + +from .__cmd_group import * +from ._create import * +from ._delete import * +from ._show import * +from ._update import * +from ._wait import * diff --git a/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/_create.py b/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/_create.py new file mode 100644 index 00000000000..59ba9c36819 --- /dev/null +++ b/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/_create.py @@ -0,0 +1,286 @@ +# -------------------------------------------------------------------------------------------- +# 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 +# -------------------------------------------------------------------------------------------- + +# pylint: skip-file +# flake8: noqa + +from azure.cli.core.aaz import * + + +@register_command( + "durabletask retention-policy create", +) +class Create(AAZCommand): + """Create a Retention Policy on a Durabletask Scheduler. + + :example: Create a new retention policy for a scheduler with a default retention period of 30 days. + az durabletask retention-policy create -g "example-rg" --scheduler-name "example-scheduler" --retention-days 30 + """ + + _aaz_info = { + "version": "2025-04-01-preview", + "resources": [ + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.durabletask/schedulers/{}/retentionpolicies/default", "2025-04-01-preview"], + ] + } + + AZ_SUPPORT_NO_WAIT = True + + def _handler(self, command_args): + super()._handler(command_args) + return self.build_lro_poller(self._execute_operations, 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) + + # define Arg Group "" + + _args_schema = cls._args_schema + _args_schema.resource_group = AAZResourceGroupNameArg( + required=True, + ) + _args_schema.scheduler_name = AAZStrArg( + options=["--scheduler-name"], + help="The name of the Scheduler", + required=True, + fmt=AAZStrArgFormat( + pattern="^[a-zA-Z0-9-]{3,64}$", + ), + ) + + # define Arg Group "Properties" + + _args_schema = cls._args_schema + _args_schema.retention_policies = AAZListArg() + + retention_policies = cls._args_schema.retention_policies + retention_policies.Element = AAZObjectArg() + + _element = cls._args_schema.retention_policies.Element + _element.orchestration_state = AAZStrArg( + options=["orchestration-state"], + help="The orchestration state to which this policy applies. If omitted, the policy applies to all purgeable orchestration states.", + enum={"Canceled": "Canceled", "Completed": "Completed", "Failed": "Failed", "Terminated": "Terminated"}, + ) + _element.retention_period_in_days = AAZIntArg( + options=["retention-period-in-days"], + help="The retention period in days after which the orchestration will be purged automatically", + required=True, + ) + + return cls._args_schema + + def _execute_operations(self): + self.pre_operations() + yield self.RetentionPoliciesCreateOrReplace(ctx=self.ctx)() + self.post_operations() + + @register_callback + def pre_operations(self): + pass + + @register_callback + def post_operations(self): + pass + + def _output(self, *args, **kwargs): + result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True) + return result + + class RetentionPoliciesCreateOrReplace(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 [202]: + return self.client.build_lro_polling( + self.ctx.args.no_wait, + session, + self.on_200_201, + self.on_error, + lro_options={"final-state-via": "azure-async-operation"}, + path_format_arguments=self.url_parameters, + ) + if session.http_response.status_code in [200, 201]: + return self.client.build_lro_polling( + self.ctx.args.no_wait, + session, + self.on_200_201, + self.on_error, + lro_options={"final-state-via": "azure-async-operation"}, + path_format_arguments=self.url_parameters, + ) + + return self.on_error(session.http_response) + + @property + def url(self): + return self.client.format_url( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}/retentionPolicies/default", + **self.url_parameters + ) + + @property + def method(self): + return "PUT" + + @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( + "schedulerName", self.ctx.args.scheduler_name, + required=True, + ), + **self.serialize_url_param( + "subscriptionId", self.ctx.subscription_id, + required=True, + ), + } + return parameters + + @property + def query_parameters(self): + parameters = { + **self.serialize_query_param( + "api-version", "2025-04-01-preview", + required=True, + ), + } + return parameters + + @property + def header_parameters(self): + parameters = { + **self.serialize_header_param( + "Content-Type", "application/json", + ), + **self.serialize_header_param( + "Accept", "application/json", + ), + } + return parameters + + @property + def content(self): + _content_value, _builder = self.new_content_builder( + self.ctx.args, + typ=AAZObjectType, + typ_kwargs={"flags": {"required": True, "client_flatten": True}} + ) + _builder.set_prop("properties", AAZObjectType) + + properties = _builder.get(".properties") + if properties is not None: + properties.set_prop("retentionPolicies", AAZListType, ".retention_policies") + + retention_policies = _builder.get(".properties.retentionPolicies") + if retention_policies is not None: + retention_policies.set_elements(AAZObjectType, ".") + + _elements = _builder.get(".properties.retentionPolicies[]") + if _elements is not None: + _elements.set_prop("orchestrationState", AAZStrType, ".orchestration_state") + _elements.set_prop("retentionPeriodInDays", AAZIntType, ".retention_period_in_days", typ_kwargs={"flags": {"required": True}}) + + return self.serialize_content(_content_value) + + def on_200_201(self, session): + data = self.deserialize_http_content(session) + self.ctx.set_var( + "instance", + data, + schema_builder=self._build_schema_on_200_201 + ) + + _schema_on_200_201 = None + + @classmethod + def _build_schema_on_200_201(cls): + if cls._schema_on_200_201 is not None: + return cls._schema_on_200_201 + + cls._schema_on_200_201 = AAZObjectType() + + _schema_on_200_201 = cls._schema_on_200_201 + _schema_on_200_201.id = AAZStrType( + flags={"read_only": True}, + ) + _schema_on_200_201.name = AAZStrType( + flags={"read_only": True}, + ) + _schema_on_200_201.properties = AAZObjectType() + _schema_on_200_201.system_data = AAZObjectType( + serialized_name="systemData", + flags={"read_only": True}, + ) + _schema_on_200_201.type = AAZStrType( + flags={"read_only": True}, + ) + + properties = cls._schema_on_200_201.properties + properties.provisioning_state = AAZStrType( + serialized_name="provisioningState", + flags={"read_only": True}, + ) + properties.retention_policies = AAZListType( + serialized_name="retentionPolicies", + ) + + retention_policies = cls._schema_on_200_201.properties.retention_policies + retention_policies.Element = AAZObjectType() + + _element = cls._schema_on_200_201.properties.retention_policies.Element + _element.orchestration_state = AAZStrType( + serialized_name="orchestrationState", + ) + _element.retention_period_in_days = AAZIntType( + serialized_name="retentionPeriodInDays", + flags={"required": True}, + ) + + system_data = cls._schema_on_200_201.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", + ) + + return cls._schema_on_200_201 + + +class _CreateHelper: + """Helper class for Create""" + + +__all__ = ["Create"] diff --git a/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/_delete.py b/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/_delete.py new file mode 100644 index 00000000000..a9f47c7a104 --- /dev/null +++ b/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/_delete.py @@ -0,0 +1,166 @@ +# -------------------------------------------------------------------------------------------- +# 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 +# -------------------------------------------------------------------------------------------- + +# pylint: skip-file +# flake8: noqa + +from azure.cli.core.aaz import * + + +@register_command( + "durabletask retention-policy delete", + confirmation="Are you sure you want to perform this operation?", +) +class Delete(AAZCommand): + """Delete a Retention Policy on a Durabletask Scheduler. + + :example: Delete a Retention Policy on a Scheduler + az durabletask retention-policy delete -g "example-rg" --scheduler-name "example-scheduler" + """ + + _aaz_info = { + "version": "2025-04-01-preview", + "resources": [ + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.durabletask/schedulers/{}/retentionpolicies/default", "2025-04-01-preview"], + ] + } + + AZ_SUPPORT_NO_WAIT = True + + def _handler(self, command_args): + super()._handler(command_args) + return self.build_lro_poller(self._execute_operations, None) + + _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) + + # define Arg Group "" + + _args_schema = cls._args_schema + _args_schema.resource_group = AAZResourceGroupNameArg( + required=True, + ) + _args_schema.scheduler_name = AAZStrArg( + options=["--scheduler-name"], + help="The name of the Scheduler", + required=True, + id_part="name", + fmt=AAZStrArgFormat( + pattern="^[a-zA-Z0-9-]{3,64}$", + ), + ) + return cls._args_schema + + def _execute_operations(self): + self.pre_operations() + yield self.RetentionPoliciesDelete(ctx=self.ctx)() + self.post_operations() + + @register_callback + def pre_operations(self): + pass + + @register_callback + def post_operations(self): + pass + + class RetentionPoliciesDelete(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 [202]: + return self.client.build_lro_polling( + self.ctx.args.no_wait, + session, + self.on_200_201, + self.on_error, + lro_options={"final-state-via": "location"}, + path_format_arguments=self.url_parameters, + ) + if session.http_response.status_code in [204]: + return self.client.build_lro_polling( + self.ctx.args.no_wait, + session, + self.on_204, + self.on_error, + lro_options={"final-state-via": "location"}, + path_format_arguments=self.url_parameters, + ) + if session.http_response.status_code in [200, 201]: + return self.client.build_lro_polling( + self.ctx.args.no_wait, + session, + self.on_200_201, + self.on_error, + lro_options={"final-state-via": "location"}, + path_format_arguments=self.url_parameters, + ) + + return self.on_error(session.http_response) + + @property + def url(self): + return self.client.format_url( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}/retentionPolicies/default", + **self.url_parameters + ) + + @property + def method(self): + return "DELETE" + + @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( + "schedulerName", self.ctx.args.scheduler_name, + required=True, + ), + **self.serialize_url_param( + "subscriptionId", self.ctx.subscription_id, + required=True, + ), + } + return parameters + + @property + def query_parameters(self): + parameters = { + **self.serialize_query_param( + "api-version", "2025-04-01-preview", + required=True, + ), + } + return parameters + + def on_204(self, session): + pass + + def on_200_201(self, session): + pass + + +class _DeleteHelper: + """Helper class for Delete""" + + +__all__ = ["Delete"] diff --git a/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/_show.py b/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/_show.py new file mode 100644 index 00000000000..b1cc7da4e2f --- /dev/null +++ b/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/_show.py @@ -0,0 +1,222 @@ +# -------------------------------------------------------------------------------------------- +# 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 +# -------------------------------------------------------------------------------------------- + +# pylint: skip-file +# flake8: noqa + +from azure.cli.core.aaz import * + + +@register_command( + "durabletask retention-policy show", +) +class Show(AAZCommand): + """Get a Retention Policy + + :example: Show details of a specific retention policy on a Scheduler. + az durabletask retention-policy show -g "example-rg" --scheduler-name "example-scheduler" + """ + + _aaz_info = { + "version": "2025-04-01-preview", + "resources": [ + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.durabletask/schedulers/{}/retentionpolicies/default", "2025-04-01-preview"], + ] + } + + 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) + + # define Arg Group "" + + _args_schema = cls._args_schema + _args_schema.resource_group = AAZResourceGroupNameArg( + required=True, + ) + _args_schema.scheduler_name = AAZStrArg( + options=["--scheduler-name"], + help="The name of the Scheduler", + required=True, + id_part="name", + fmt=AAZStrArgFormat( + pattern="^[a-zA-Z0-9-]{3,64}$", + ), + ) + return cls._args_schema + + def _execute_operations(self): + self.pre_operations() + self.RetentionPoliciesGet(ctx=self.ctx)() + self.post_operations() + + @register_callback + def pre_operations(self): + pass + + @register_callback + def post_operations(self): + pass + + def _output(self, *args, **kwargs): + result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True) + return result + + class RetentionPoliciesGet(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) + + return self.on_error(session.http_response) + + @property + def url(self): + return self.client.format_url( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}/retentionPolicies/default", + **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( + "schedulerName", self.ctx.args.scheduler_name, + required=True, + ), + **self.serialize_url_param( + "subscriptionId", self.ctx.subscription_id, + required=True, + ), + } + return parameters + + @property + def query_parameters(self): + parameters = { + **self.serialize_query_param( + "api-version", "2025-04-01-preview", + 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) + self.ctx.set_var( + "instance", + data, + schema_builder=self._build_schema_on_200 + ) + + _schema_on_200 = None + + @classmethod + def _build_schema_on_200(cls): + if cls._schema_on_200 is not None: + return cls._schema_on_200 + + cls._schema_on_200 = AAZObjectType() + + _schema_on_200 = cls._schema_on_200 + _schema_on_200.id = AAZStrType( + flags={"read_only": True}, + ) + _schema_on_200.name = AAZStrType( + flags={"read_only": True}, + ) + _schema_on_200.properties = AAZObjectType() + _schema_on_200.system_data = AAZObjectType( + serialized_name="systemData", + flags={"read_only": True}, + ) + _schema_on_200.type = AAZStrType( + flags={"read_only": True}, + ) + + properties = cls._schema_on_200.properties + properties.provisioning_state = AAZStrType( + serialized_name="provisioningState", + flags={"read_only": True}, + ) + properties.retention_policies = AAZListType( + serialized_name="retentionPolicies", + ) + + retention_policies = cls._schema_on_200.properties.retention_policies + retention_policies.Element = AAZObjectType() + + _element = cls._schema_on_200.properties.retention_policies.Element + _element.orchestration_state = AAZStrType( + serialized_name="orchestrationState", + ) + _element.retention_period_in_days = AAZIntType( + serialized_name="retentionPeriodInDays", + flags={"required": 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", + ) + + return cls._schema_on_200 + + +class _ShowHelper: + """Helper class for Show""" + + +__all__ = ["Show"] diff --git a/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/_update.py b/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/_update.py new file mode 100644 index 00000000000..0871646b2dc --- /dev/null +++ b/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/_update.py @@ -0,0 +1,427 @@ +# -------------------------------------------------------------------------------------------- +# 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 +# -------------------------------------------------------------------------------------------- + +# pylint: skip-file +# flake8: noqa + +from azure.cli.core.aaz import * + + +class Update(AAZCommand): + """Update a Retention Policy + """ + + _aaz_info = { + "version": "2025-04-01-preview", + "resources": [ + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.durabletask/schedulers/{}/retentionpolicies/default", "2025-04-01-preview"], + ] + } + + AZ_SUPPORT_NO_WAIT = True + + AZ_SUPPORT_GENERIC_UPDATE = True + + def _handler(self, command_args): + super()._handler(command_args) + return self.build_lro_poller(self._execute_operations, 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) + + # define Arg Group "" + + _args_schema = cls._args_schema + _args_schema.resource_group = AAZResourceGroupNameArg( + required=True, + ) + _args_schema.scheduler_name = AAZStrArg( + options=["--scheduler-name"], + help="The name of the Scheduler", + required=True, + id_part="name", + fmt=AAZStrArgFormat( + pattern="^[a-zA-Z0-9-]{3,64}$", + ), + ) + + # define Arg Group "Properties" + + _args_schema = cls._args_schema + _args_schema.retention_policies = AAZListArg( + options=["--retention-policies"], + arg_group="Properties", + help="The orchestration retention policies", + nullable=True, + ) + + retention_policies = cls._args_schema.retention_policies + retention_policies.Element = AAZObjectArg( + nullable=True, + ) + + _element = cls._args_schema.retention_policies.Element + _element.orchestration_state = AAZStrArg( + options=["orchestration-state"], + help="The orchestration state to which this policy applies. If omitted, the policy applies to all purgeable orchestration states.", + nullable=True, + enum={"Canceled": "Canceled", "Completed": "Completed", "Failed": "Failed", "Terminated": "Terminated"}, + ) + _element.retention_period_in_days = AAZIntArg( + options=["retention-period-in-days"], + help="The retention period in days after which the orchestration will be purged automatically", + ) + return cls._args_schema + + def _execute_operations(self): + self.pre_operations() + self.RetentionPoliciesGet(ctx=self.ctx)() + self.pre_instance_update(self.ctx.vars.instance) + self.InstanceUpdateByJson(ctx=self.ctx)() + self.InstanceUpdateByGeneric(ctx=self.ctx)() + self.post_instance_update(self.ctx.vars.instance) + yield self.RetentionPoliciesCreateOrReplace(ctx=self.ctx)() + self.post_operations() + + @register_callback + def pre_operations(self): + pass + + @register_callback + def post_operations(self): + pass + + @register_callback + def pre_instance_update(self, instance): + pass + + @register_callback + def post_instance_update(self, instance): + pass + + def _output(self, *args, **kwargs): + result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True) + return result + + class RetentionPoliciesGet(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) + + return self.on_error(session.http_response) + + @property + def url(self): + return self.client.format_url( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}/retentionPolicies/default", + **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( + "schedulerName", self.ctx.args.scheduler_name, + required=True, + ), + **self.serialize_url_param( + "subscriptionId", self.ctx.subscription_id, + required=True, + ), + } + return parameters + + @property + def query_parameters(self): + parameters = { + **self.serialize_query_param( + "api-version", "2025-04-01-preview", + 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) + self.ctx.set_var( + "instance", + data, + schema_builder=self._build_schema_on_200 + ) + + _schema_on_200 = None + + @classmethod + def _build_schema_on_200(cls): + if cls._schema_on_200 is not None: + return cls._schema_on_200 + + cls._schema_on_200 = AAZObjectType() + _UpdateHelper._build_schema_retention_policy_read(cls._schema_on_200) + + return cls._schema_on_200 + + class RetentionPoliciesCreateOrReplace(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 [202]: + return self.client.build_lro_polling( + self.ctx.args.no_wait, + session, + self.on_200_201, + self.on_error, + lro_options={"final-state-via": "azure-async-operation"}, + path_format_arguments=self.url_parameters, + ) + if session.http_response.status_code in [200, 201]: + return self.client.build_lro_polling( + self.ctx.args.no_wait, + session, + self.on_200_201, + self.on_error, + lro_options={"final-state-via": "azure-async-operation"}, + path_format_arguments=self.url_parameters, + ) + + return self.on_error(session.http_response) + + @property + def url(self): + return self.client.format_url( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}/retentionPolicies/default", + **self.url_parameters + ) + + @property + def method(self): + return "PUT" + + @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( + "schedulerName", self.ctx.args.scheduler_name, + required=True, + ), + **self.serialize_url_param( + "subscriptionId", self.ctx.subscription_id, + required=True, + ), + } + return parameters + + @property + def query_parameters(self): + parameters = { + **self.serialize_query_param( + "api-version", "2025-04-01-preview", + required=True, + ), + } + return parameters + + @property + def header_parameters(self): + parameters = { + **self.serialize_header_param( + "Content-Type", "application/json", + ), + **self.serialize_header_param( + "Accept", "application/json", + ), + } + return parameters + + @property + def content(self): + _content_value, _builder = self.new_content_builder( + self.ctx.args, + value=self.ctx.vars.instance, + ) + + return self.serialize_content(_content_value) + + def on_200_201(self, session): + data = self.deserialize_http_content(session) + self.ctx.set_var( + "instance", + data, + schema_builder=self._build_schema_on_200_201 + ) + + _schema_on_200_201 = None + + @classmethod + def _build_schema_on_200_201(cls): + if cls._schema_on_200_201 is not None: + return cls._schema_on_200_201 + + cls._schema_on_200_201 = AAZObjectType() + _UpdateHelper._build_schema_retention_policy_read(cls._schema_on_200_201) + + return cls._schema_on_200_201 + + class InstanceUpdateByJson(AAZJsonInstanceUpdateOperation): + + def __call__(self, *args, **kwargs): + self._update_instance(self.ctx.vars.instance) + + def _update_instance(self, instance): + _instance_value, _builder = self.new_content_builder( + self.ctx.args, + value=instance, + typ=AAZObjectType + ) + _builder.set_prop("properties", AAZObjectType) + + properties = _builder.get(".properties") + if properties is not None: + properties.set_prop("retentionPolicies", AAZListType, ".retention_policies") + + retention_policies = _builder.get(".properties.retentionPolicies") + if retention_policies is not None: + retention_policies.set_elements(AAZObjectType, ".") + + _elements = _builder.get(".properties.retentionPolicies[]") + if _elements is not None: + _elements.set_prop("orchestrationState", AAZStrType, ".orchestration_state") + _elements.set_prop("retentionPeriodInDays", AAZIntType, ".retention_period_in_days", typ_kwargs={"flags": {"required": True}}) + + return _instance_value + + class InstanceUpdateByGeneric(AAZGenericInstanceUpdateOperation): + + def __call__(self, *args, **kwargs): + self._update_instance_by_generic( + self.ctx.vars.instance, + self.ctx.generic_update_args + ) + + +class _UpdateHelper: + """Helper class for Update""" + + _schema_retention_policy_read = None + + @classmethod + def _build_schema_retention_policy_read(cls, _schema): + if cls._schema_retention_policy_read is not None: + _schema.id = cls._schema_retention_policy_read.id + _schema.name = cls._schema_retention_policy_read.name + _schema.properties = cls._schema_retention_policy_read.properties + _schema.system_data = cls._schema_retention_policy_read.system_data + _schema.type = cls._schema_retention_policy_read.type + return + + cls._schema_retention_policy_read = _schema_retention_policy_read = AAZObjectType() + + retention_policy_read = _schema_retention_policy_read + retention_policy_read.id = AAZStrType( + flags={"read_only": True}, + ) + retention_policy_read.name = AAZStrType( + flags={"read_only": True}, + ) + retention_policy_read.properties = AAZObjectType() + retention_policy_read.system_data = AAZObjectType( + serialized_name="systemData", + flags={"read_only": True}, + ) + retention_policy_read.type = AAZStrType( + flags={"read_only": True}, + ) + + properties = _schema_retention_policy_read.properties + properties.provisioning_state = AAZStrType( + serialized_name="provisioningState", + flags={"read_only": True}, + ) + properties.retention_policies = AAZListType( + serialized_name="retentionPolicies", + ) + + retention_policies = _schema_retention_policy_read.properties.retention_policies + retention_policies.Element = AAZObjectType() + + _element = _schema_retention_policy_read.properties.retention_policies.Element + _element.orchestration_state = AAZStrType( + serialized_name="orchestrationState", + ) + _element.retention_period_in_days = AAZIntType( + serialized_name="retentionPeriodInDays", + flags={"required": True}, + ) + + system_data = _schema_retention_policy_read.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", + ) + + _schema.id = cls._schema_retention_policy_read.id + _schema.name = cls._schema_retention_policy_read.name + _schema.properties = cls._schema_retention_policy_read.properties + _schema.system_data = cls._schema_retention_policy_read.system_data + _schema.type = cls._schema_retention_policy_read.type + + +__all__ = ["Update"] diff --git a/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/_wait.py b/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/_wait.py new file mode 100644 index 00000000000..2938f34e293 --- /dev/null +++ b/src/durabletask/azext_durabletask/aaz/latest/durabletask/retention_policy/_wait.py @@ -0,0 +1,218 @@ +# -------------------------------------------------------------------------------------------- +# 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 +# -------------------------------------------------------------------------------------------- + +# pylint: skip-file +# flake8: noqa + +from azure.cli.core.aaz import * + + +@register_command( + "durabletask retention-policy wait", +) +class Wait(AAZWaitCommand): + """Place the CLI in a waiting state until a condition is met. + """ + + _aaz_info = { + "resources": [ + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.durabletask/schedulers/{}/retentionpolicies/default", "2025-04-01-preview"], + ] + } + + 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) + + # define Arg Group "" + + _args_schema = cls._args_schema + _args_schema.resource_group = AAZResourceGroupNameArg( + required=True, + ) + _args_schema.scheduler_name = AAZStrArg( + options=["--scheduler-name"], + help="The name of the Scheduler", + required=True, + id_part="name", + fmt=AAZStrArgFormat( + pattern="^[a-zA-Z0-9-]{3,64}$", + ), + ) + return cls._args_schema + + def _execute_operations(self): + self.pre_operations() + self.RetentionPoliciesGet(ctx=self.ctx)() + self.post_operations() + + @register_callback + def pre_operations(self): + pass + + @register_callback + def post_operations(self): + pass + + def _output(self, *args, **kwargs): + result = self.deserialize_output(self.ctx.vars.instance, client_flatten=False) + return result + + class RetentionPoliciesGet(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) + + return self.on_error(session.http_response) + + @property + def url(self): + return self.client.format_url( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DurableTask/schedulers/{schedulerName}/retentionPolicies/default", + **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( + "schedulerName", self.ctx.args.scheduler_name, + required=True, + ), + **self.serialize_url_param( + "subscriptionId", self.ctx.subscription_id, + required=True, + ), + } + return parameters + + @property + def query_parameters(self): + parameters = { + **self.serialize_query_param( + "api-version", "2025-04-01-preview", + 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) + self.ctx.set_var( + "instance", + data, + schema_builder=self._build_schema_on_200 + ) + + _schema_on_200 = None + + @classmethod + def _build_schema_on_200(cls): + if cls._schema_on_200 is not None: + return cls._schema_on_200 + + cls._schema_on_200 = AAZObjectType() + + _schema_on_200 = cls._schema_on_200 + _schema_on_200.id = AAZStrType( + flags={"read_only": True}, + ) + _schema_on_200.name = AAZStrType( + flags={"read_only": True}, + ) + _schema_on_200.properties = AAZObjectType() + _schema_on_200.system_data = AAZObjectType( + serialized_name="systemData", + flags={"read_only": True}, + ) + _schema_on_200.type = AAZStrType( + flags={"read_only": True}, + ) + + properties = cls._schema_on_200.properties + properties.provisioning_state = AAZStrType( + serialized_name="provisioningState", + flags={"read_only": True}, + ) + properties.retention_policies = AAZListType( + serialized_name="retentionPolicies", + ) + + retention_policies = cls._schema_on_200.properties.retention_policies + retention_policies.Element = AAZObjectType() + + _element = cls._schema_on_200.properties.retention_policies.Element + _element.orchestration_state = AAZStrType( + serialized_name="orchestrationState", + ) + _element.retention_period_in_days = AAZIntType( + serialized_name="retentionPeriodInDays", + flags={"required": 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", + ) + + return cls._schema_on_200 + + +class _WaitHelper: + """Helper class for Wait""" + + +__all__ = ["Wait"] diff --git a/src/durabletask/azext_durabletask/azext_metadata.json b/src/durabletask/azext_durabletask/azext_metadata.json index b2e481ecb9e..e506328978c 100644 --- a/src/durabletask/azext_durabletask/azext_metadata.json +++ b/src/durabletask/azext_durabletask/azext_metadata.json @@ -1,4 +1,4 @@ { "azext.isPreview": true, - "azext.minCliCoreVersion": "2.67.0" + "azext.minCliCoreVersion": "2.70.0" } \ No newline at end of file diff --git a/src/durabletask/azext_durabletask/commands.py b/src/durabletask/azext_durabletask/commands.py index b0d842e4993..2e65e0e527f 100644 --- a/src/durabletask/azext_durabletask/commands.py +++ b/src/durabletask/azext_durabletask/commands.py @@ -12,4 +12,6 @@ def load_command_table(self, _): # pylint: disable=unused-argument - pass + with self.command_group('durabletask retention-policy'): + from .custom import CreatePolicy + self.command_table["durabletask retention-policy create"] = CreatePolicy(loader=self) diff --git a/src/durabletask/azext_durabletask/custom.py b/src/durabletask/azext_durabletask/custom.py index 86df1e48ef5..af3563019a2 100644 --- a/src/durabletask/azext_durabletask/custom.py +++ b/src/durabletask/azext_durabletask/custom.py @@ -5,10 +5,105 @@ # Code generated by aaz-dev-tools # -------------------------------------------------------------------------------------------- -# pylint: disable=too-many-lines -# pylint: disable=too-many-statements +from .aaz.latest.durabletask.retention_policy import Create as _Create +from azure.cli.core.aaz import AAZStrArg -from knack.log import get_logger +class CreatePolicy(_Create): + """Create a retention policy for a Durabletask scheduler.""" -logger = get_logger(__name__) + @classmethod + def _build_arguments_schema(cls, *args, **kwargs): + """Define custom arguments for the command.""" + # Call the parent class method to initialize the argument schema + cls.args_schema = super()._build_arguments_schema(*args, **kwargs) + + # Remove the registration of the retention policies schema so it doesn't show up in the CLI help + if hasattr(cls._args_schema.retention_policies, '_registered'): + setattr(cls._args_schema.retention_policies, '_registered', False) + _args_schema = cls._args_schema + + # Define retention policy arguments with their CLI options and descriptions + retention_args = { + "default_days": ("--default-days", "-d", "The number of days to retain orchestrations."), + "canceled_days": ("--canceled-days", "-x", "The number of days to retain canceled orchestrations."), + "completed_days": ("--completed-days", "-c", "The number of days to retain completed orchestrations."), + "failed_days": ("--failed-days", "-f", "The number of days to retain failed orchestrations."), + "terminated_days": ("--terminated-days", "-t", "The number of days to retain terminated orchestrations."), + } + + # Add each retention argument to the schema + for arg_name, (option, short_option, help_text) in retention_args.items(): + setattr(_args_schema, arg_name, AAZStrArg( + arg_group="Properties", # Group these arguments under "Properties" + options=[option, short_option], # CLI options for the argument + help=help_text, # Description of the argument + required=False, # These arguments are optional + )) + + return _args_schema + + def pre_operations(self): + """Prepare retention policies before executing the operation.""" + + if not any([ + self.ctx.args.default_days, + self.ctx.args.canceled_days, + self.ctx.args.completed_days, + self.ctx.args.failed_days, + self.ctx.args.terminated_days + ]): + raise ValueError("At least one retention period (e.g., --default-days, --canceled-days) must be specified.") + + # Build the retention policies based on the provided arguments + self.ctx.args.retention_policies = _build_retention_policies({ + key: value for key, value in { + 'default_days': self.ctx.args.default_days, + 'canceled_days': self.ctx.args.canceled_days, + 'completed_days': self.ctx.args.completed_days, + 'failed_days': self.ctx.args.failed_days, + 'terminated_days': self.ctx.args.terminated_days + }.items() if value is not None # Only include arguments that are not None + }) + + +def _build_retention_policies(args_dict): + """Build a list of retention policies based on the provided arguments.""" + retention_policies = [] + + def to_int(value): + """Convert a value to an integer, handling serialization.""" + try: + return int(value.to_serialized_data()) # Convert serialized data to an integer + except (ValueError, TypeError): + return None # Return None if conversion fails + + # Add default retention policy if specified + default_days = args_dict.get('default_days') + if default_days is not None: + days = to_int(default_days) + if days is not None: + # Add a default retention policy with the specified number of days + retention_policies.append({"retentionPeriodInDays": days}) + + # Define a mapping of argument keys to orchestration states + state_mapping = { + 'canceled_days': 'Canceled', + 'completed_days': 'Completed', + 'failed_days': 'Failed', + 'terminated_days': 'Terminated', + } + + # Add state-specific retention policies + for arg_key, state in state_mapping.items(): + days_arg = args_dict.get(arg_key) + if days_arg is not None: + days = to_int(days_arg) + if days is not None: + # Add a retention policy for the specific orchestration state + retention_policies.append({ + "retentionPeriodInDays": days, + "orchestrationState": state + }) + + return retention_policies