Skip to content
Merged
4 changes: 4 additions & 0 deletions src/durabletask/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"]
Original file line number Diff line number Diff line change
@@ -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 *
Original file line number Diff line number Diff line change
@@ -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"]
Loading
Loading