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
27 changes: 21 additions & 6 deletions plugins/modules/object_storage_quota_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from __future__ import absolute_import, division, print_function

from typing import Any

from ansible_collections.linode.cloud.plugins.module_utils.doc_fragments import (
object_storage_quota_info as docs,
)
Expand All @@ -14,7 +16,24 @@
InfoModuleResult,
)
from ansible_specdoc.objects import FieldType
from linode_api4 import ObjectStorageQuota
from linode_api4 import LinodeClient, ObjectStorageQuota


def get_quota_usage(
client: LinodeClient,
object_storage_quota: dict[str, Any],
_: dict | None,
) -> dict[str, Any] | None:
Comment thread
zliang-akamai marked this conversation as resolved.
"""Return quota usage details for a quota when usage is available."""
if not object_storage_quota["has_usage"]:
return None

return (
ObjectStorageQuota(client, object_storage_quota["quota_id"])
.usage()
.dict
)


module = InfoModule(
examples=docs.specdoc_examples,
Expand All @@ -33,11 +52,7 @@
docs_url="https://techdocs.akamai.com/linode-api/reference"
"/get-object-storage-quota-usage",
samples=docs.result_object_storage_quota_usage_samples,
get=lambda client, object_storage_quota, params: ObjectStorageQuota(
client, object_storage_quota["quota_id"]
)
.usage()
.dict,
get=get_quota_usage,
),
],
attributes=[
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ line_length = 80
[tool.black]
line-length = 80
target-version = [
"py39",
"py310",
"py311",
"py312",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
assert:
that:
- obj_quota.object_storage_quota.quota_id == obj_quota_list.object_storage_quotas[0].quota_id
- obj_quota.quota_usage.quota_limit
- ((obj_quota.object_storage_quota.has_usage | bool) and (obj_quota.quota_usage.quota_limit is integer)) or ((not (obj_quota.object_storage_quota.has_usage | bool)) and (obj_quota.quota_usage is none))

environment:
LINODE_UA_PREFIX: '{{ ua_prefix }}'
Expand Down