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
162 changes: 138 additions & 24 deletions .generator/schemas/v2/openapi.yaml

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions examples/v2/usage-metering/CreateQuotas.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from datadog_api_client.v2.api.usage_metering_api import UsageMeteringApi
from datadog_api_client.v2.model.usage_quota_create_attributes import UsageQuotaCreateAttributes
from datadog_api_client.v2.model.usage_quota_create_data import UsageQuotaCreateData
from datadog_api_client.v2.model.usage_quota_request_scope import UsageQuotaRequestScope
from datadog_api_client.v2.model.usage_quota_type import UsageQuotaType
from datadog_api_client.v2.model.usage_quotas_create_request import UsageQuotasCreateRequest

Expand All @@ -17,10 +16,8 @@
UsageQuotaCreateData(
attributes=UsageQuotaCreateAttributes(
enforced=True,
scope=UsageQuotaRequestScope(
user_handle="jane@example.com",
),
usage_limit=100000,
pending_usage_limit=100000,
usage_limit=600000,
),
type=UsageQuotaType.QUOTAS,
),
Expand Down
17 changes: 17 additions & 0 deletions examples/v2/usage-metering/DeletePendingQuota.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Cancel a scheduled usage quota limit returns "No Content" response
"""

from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.usage_metering_api import UsageMeteringApi

configuration = Configuration()
configuration.access_token = environ["DD_BEARER_TOKEN"]
configuration.unstable_operations["delete_pending_quota"] = True
with ApiClient(configuration) as api_client:
api_instance = UsageMeteringApi(api_client)
api_instance.delete_pending_quota(
quota_namespace="ai_credits",
id="MTIzNB9haV9jcmVkaXRzH3VzZXJfaGFuZGxlOl9fQUxMX18",
)
2 changes: 1 addition & 1 deletion examples/v2/usage-metering/DeleteQuota.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
api_instance = UsageMeteringApi(api_client)
api_instance.delete_quota(
quota_namespace="ai_credits",
id="MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f",
id="MTIzNB9haV9jcmVkaXRzH3VzZXJfaGFuZGxlOl9fQUxMX18",
)
5 changes: 3 additions & 2 deletions examples/v2/usage-metering/UpdateQuota.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
data=UsageQuotaUpdateData(
attributes=UsageQuotaUpdateAttributes(
enforced=False,
pending_usage_limit=50000,
usage_limit=120000,
),
id="MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f",
id="MTIzNB9haV9jcmVkaXRzH3VzZXJfaGFuZGxlOl9fQUxMX18",
type=UsageQuotaType.QUOTAS,
),
)
Expand All @@ -27,7 +28,7 @@
with ApiClient(configuration) as api_client:
api_instance = UsageMeteringApi(api_client)
response = api_instance.update_quota(
quota_namespace="ai_credits", id="MjAfYWlfY3JlZGl0c1911c2VyX2hhbmRsZTpfX0FMTF9f", body=body
quota_namespace="ai_credits", id="MTIzNB9haV9jcmVkaXRzH3VzZXJfaGFuZGxlOl9fQUxMX18", body=body
)

print(response)
1 change: 1 addition & 0 deletions src/datadog_api_client/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ def __init__(
"v2.search_cost_recommendations": False,
"v2.update_unit_cost": False,
"v2.create_quotas": False,
"v2.delete_pending_quota": False,
"v2.delete_quota": False,
"v2.list_quotas": False,
"v2.update_quota": False,
Expand Down
59 changes: 57 additions & 2 deletions src/datadog_api_client/v2/api/usage_metering_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,35 @@ def __init__(self, api_client=None):
api_client=api_client,
)

self._delete_pending_quota_endpoint = _Endpoint(
settings={
"response_type": None,
"auth": ["apiKeyAuth", "appKeyAuth", "AuthZ"],
"endpoint_path": "/api/v2/usage/quotas/{quota_namespace}/{id}/pending",
"operation_id": "delete_pending_quota",
"http_method": "DELETE",
"version": "v2",
},
params_map={
"quota_namespace": {
"required": True,
"openapi_types": (str,),
"attribute": "quota_namespace",
"location": "path",
},
"id": {
"required": True,
"openapi_types": (str,),
"attribute": "id",
"location": "path",
},
},
headers_map={
"accept": ["*/*"],
},
api_client=api_client,
)

self._delete_quota_endpoint = _Endpoint(
settings={
"response_type": None,
Expand Down Expand Up @@ -632,7 +661,11 @@ def create_quotas(
) -> UsageQuotasBulkResponse:
"""Create or update usage quotas.

Creates or updates one or more usage quotas by scope. If a quota already exists for a supplied scope, it is updated; otherwise, a new quota is created. Requires the ``billing_edit`` permission.
Creates or updates one or more usage quotas by scope. If a quota already exists for a supplied scope, it is updated.
Otherwise, a quota is created only when ``usage_limit`` and ``enforced`` are provided.
For the organization-wide quota, ``pending_usage_limit`` schedules a limit for the next usage period and can
accompany an immediate limit or update an existing quota by itself.
Scheduled changes follow ``include_descendants`` like the other fields. Requires the ``billing_edit`` permission.

:param quota_namespace: The product-specific namespace whose usage quotas are being managed.
:type quota_namespace: str
Expand All @@ -652,6 +685,28 @@ def create_quotas(

return self._create_quotas_endpoint.call_with_http_info(**kwargs)

def delete_pending_quota(
self,
quota_namespace: str,
id: str,
) -> None:
"""Cancel a scheduled usage quota limit.

Cancels the limit change scheduled to take effect at the start of the next usage period, leaving the usage quota and its current limit unchanged. Returns ``404`` when the quota does not exist, has no scheduled change, or its scheduled change has already taken effect; in every case the quota is left unchanged. The quota must belong to the caller's organization or one of its descendants, and its opaque identifier must belong to the requested quota namespace. Requires the ``billing_edit`` permission.

:param quota_namespace: The product-specific namespace whose usage quotas are being managed.
:type quota_namespace: str
:param id: The opaque quota identifier returned by a previous list or create request. Clients must pass this value verbatim.
:type id: str
:rtype: None
"""
kwargs: Dict[str, Any] = {}
kwargs["quota_namespace"] = quota_namespace

kwargs["id"] = id

return self._delete_pending_quota_endpoint.call_with_http_info(**kwargs)

def delete_quota(
self,
quota_namespace: str,
Expand Down Expand Up @@ -1266,7 +1321,7 @@ def update_quota(
) -> UsageQuotaResponse:
"""Update a usage quota.

Updates the supplied fields on a usage quota and leaves omitted fields unchanged. The quota must belong to the caller's organization or one of its descendants, and its opaque identifier must belong to the requested quota namespace. Requires the ``billing_edit`` permission.
Updates the supplied fields on a usage quota and leaves omitted fields unchanged. For an organization-wide quota, ``pending_usage_limit`` schedules a limit for the next usage period. The quota must belong to the caller's organization or one of its descendants, and its opaque identifier must belong to the requested quota namespace. Requires the ``billing_edit`` permission.

:param quota_namespace: The product-specific namespace whose usage quotas are being managed.
:type quota_namespace: str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@


class UsageQuotaBulkResultAttributes(ModelNormal):
validations = {
"pending_effective_from": {},
}

@cached_property
def openapi_types(_):
from datadog_api_client.v2.model.usage_quota_response_scope import UsageQuotaResponseScope
Expand All @@ -26,6 +30,8 @@ def openapi_types(_):
"enforced": (bool,),
"error": (str,),
"org_public_id": (str,),
"pending_effective_from": (str,),
"pending_usage_limit": (float,),
"scope": (UsageQuotaResponseScope,),
"usage_limit": (float,),
}
Expand All @@ -34,6 +40,8 @@ def openapi_types(_):
"enforced": "enforced",
"error": "error",
"org_public_id": "org_public_id",
"pending_effective_from": "pending_effective_from",
"pending_usage_limit": "pending_usage_limit",
"scope": "scope",
"usage_limit": "usage_limit",
}
Expand All @@ -43,12 +51,14 @@ def __init__(
enforced: Union[bool, UnsetType] = unset,
error: Union[str, UnsetType] = unset,
org_public_id: Union[str, UnsetType] = unset,
pending_effective_from: Union[str, UnsetType] = unset,
pending_usage_limit: Union[float, UnsetType] = unset,
scope: Union[UsageQuotaResponseScope, UnsetType] = unset,
usage_limit: Union[float, UnsetType] = unset,
**kwargs,
):
"""
Attributes of a usage quota bulk write result. On success, all fields except ``error`` are present. On failure, only ``error`` is present and the other fields are omitted.
Attributes of a usage quota bulk write result. On success, quota fields are present as applicable, and pending fields are present only when a change is scheduled. On failure, only ``error`` is present and the other fields are omitted.

:param enforced: Whether usage above the limit is actively blocked instead of only tracked or alerted on. Omitted if this item failed to write.
:type enforced: bool, optional
Expand All @@ -59,6 +69,12 @@ def __init__(
:param org_public_id: The public ID of the organization that owns the quota. Omitted if this item failed to write.
:type org_public_id: str, optional

:param pending_effective_from: The future UTC month when the scheduled limit takes effect, formatted as ``YYYY-MM`` , starting at 00:00 UTC on its first day. Present only together with ``pending_usage_limit`` and omitted when no change is scheduled or this item failed to write.
:type pending_effective_from: str, optional

:param pending_usage_limit: The usage limit scheduled for the organization-wide quota in the usage units defined by the quota namespace. A value of ``0`` is valid. At the start of the effective month, this value becomes ``usage_limit`` and both pending fields are omitted. Omitted when no change is scheduled or this item failed to write.
:type pending_usage_limit: float, optional

:param scope: A namespace-specific key and value identifying what the quota applies to within an organization. The object contains exactly one entry. A value of ``"*"`` identifies the default quota applied to entities without a specific quota. This field is omitted for an organization-wide quota.
:type scope: UsageQuotaResponseScope, optional

Expand All @@ -71,6 +87,10 @@ def __init__(
kwargs["error"] = error
if org_public_id is not unset:
kwargs["org_public_id"] = org_public_id
if pending_effective_from is not unset:
kwargs["pending_effective_from"] = pending_effective_from
if pending_usage_limit is not unset:
kwargs["pending_usage_limit"] = pending_usage_limit
if scope is not unset:
kwargs["scope"] = scope
if usage_limit is not unset:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self_, attributes: UsageQuotaBulkResultAttributes, id: str, type: U
"""
The result of writing one usage quota in a bulk create-or-update request.

:param attributes: Attributes of a usage quota bulk write result. On success, all fields except ``error`` are present. On failure, only ``error`` is present and the other fields are omitted.
:param attributes: Attributes of a usage quota bulk write result. On success, quota fields are present as applicable, and pending fields are present only when a change is scheduled. On failure, only ``error`` is present and the other fields are omitted.
:type attributes: UsageQuotaBulkResultAttributes

:param id: An opaque usage quota identifier. Clients must pass this value back verbatim in update and delete requests and must not infer any structure from it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

class UsageQuotaCreateAttributes(ModelNormal):
validations = {
"pending_usage_limit": {
"inclusive_minimum": 0,
},
"usage_limit": {
"inclusive_minimum": 0,
},
Expand All @@ -30,34 +33,47 @@ def openapi_types(_):

return {
"enforced": (bool,),
"pending_usage_limit": (int,),
"scope": (UsageQuotaRequestScope,),
"usage_limit": (int,),
}

attribute_map = {
"enforced": "enforced",
"pending_usage_limit": "pending_usage_limit",
"scope": "scope",
"usage_limit": "usage_limit",
}

def __init__(
self_, enforced: bool, usage_limit: int, scope: Union[UsageQuotaRequestScope, UnsetType] = unset, **kwargs
self_,
enforced: Union[bool, UnsetType] = unset,
pending_usage_limit: Union[int, UnsetType] = unset,
scope: Union[UsageQuotaRequestScope, UnsetType] = unset,
usage_limit: Union[int, UnsetType] = unset,
**kwargs,
):
"""
Attributes for creating or updating a usage quota by scope.
Attributes for creating or updating a usage quota by scope. Each item must provide ``usage_limit`` , ``pending_usage_limit`` , or both. Providing only ``pending_usage_limit`` updates an existing organization-wide quota, never creates one, requires ``enforced`` to be omitted, and fails if the quota does not exist.

:param enforced: Whether to actively block usage above the limit instead of only tracking or alerting on it.
:type enforced: bool
:param enforced: Whether to actively block usage above ``usage_limit`` instead of only tracking or alerting on it. Required when ``usage_limit`` is provided and must be omitted when only ``pending_usage_limit`` is provided.
:type enforced: bool, optional

:param pending_usage_limit: The non-negative, whole-number limit to schedule for the organization-wide quota in the usage units defined by the quota namespace. It is not checked against current usage. Each write schedules the value for 00:00 UTC on the first day of the next calendar month and replaces any previously scheduled change; the server computes ``pending_effective_from``. Omit this field to leave any scheduled change unchanged, including when raising ``usage_limit``. Cancel a scheduled change only by deleting the quota's ``/pending`` sub-resource.
:type pending_usage_limit: int, optional

:param scope: A namespace-specific key and value identifying what the quota applies to within an organization. The object must contain exactly one entry. Use ``"*"`` as the value for the default quota applied to entities without a specific quota, or omit the scope for an organization-wide quota. A specific value must identify an existing user handle in the caller's organization when ``include_descendants`` is false. When ``include_descendants`` is true, the handle must exist in the caller's organization or in at least one targeted descendant organization; the quota is then applied only to the organizations where that handle exists, and the request fails only if the handle exists in none of them.
:type scope: UsageQuotaRequestScope, optional

:param usage_limit: The quota limit to set in the usage units defined by the quota namespace. For an organization-wide quota (scope omitted), the limit must be greater than the usage already recorded in the current period.
:type usage_limit: int
:param usage_limit: The non-negative, whole-number quota limit to set in the usage units defined by the quota namespace. For an organization-wide quota (scope omitted), the limit must be greater than usage already recorded in the current period. When this field is provided, ``enforced`` is required.
:type usage_limit: int, optional
"""
if enforced is not unset:
kwargs["enforced"] = enforced
if pending_usage_limit is not unset:
kwargs["pending_usage_limit"] = pending_usage_limit
if scope is not unset:
kwargs["scope"] = scope
if usage_limit is not unset:
kwargs["usage_limit"] = usage_limit
super().__init__(kwargs)

self_.enforced = enforced
self_.usage_limit = usage_limit
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self_, attributes: UsageQuotaCreateAttributes, type: UsageQuotaType
"""
A usage quota resource to create or update by scope.

:param attributes: Attributes for creating or updating a usage quota by scope.
:param attributes: Attributes for creating or updating a usage quota by scope. Each item must provide ``usage_limit`` , ``pending_usage_limit`` , or both. Providing only ``pending_usage_limit`` updates an existing organization-wide quota, never creates one, requires ``enforced`` to be omitted, and fails if the quota does not exist.
:type attributes: UsageQuotaCreateAttributes

:param type: The JSON:API resource type for a usage quota.
Expand Down
Loading
Loading