Skip to content

Support Object Storage Quota Limits Visibility #531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 16 additions & 0 deletions linode_api4/groups/object_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ObjectStorageCluster,
ObjectStorageKeyPermission,
ObjectStorageKeys,
ObjectStorageQuota,
)
from linode_api4.util import drop_null_keys

Expand Down Expand Up @@ -517,3 +518,18 @@ def object_url_create(
)

return MappedObject(**result)

def quotas(self, *filters):
"""
Lists the active ObjectStorage-related quotas applied to your account.

API Documentation: TBD

:param filters: Any number of filters to apply to this query.
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
for more details on filtering.

:returns: A list of Object Storage Quotas that matched the query.
:rtype: PaginatedList of ObjectStorageQuota
"""
return self.client._get_and_filter(ObjectStorageQuota, *filters)
39 changes: 39 additions & 0 deletions linode_api4/objects/object_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,42 @@ class ObjectStorageKeys(Base):
"limited": Property(),
"regions": Property(unordered=True),
}


class ObjectStorageQuota(Base):
"""
An Object Storage related quota information on your account.
Object Storage Quota related features are under v4beta and may not currently be available to all users.

API documentation: TBD
"""

api_endpoint = "/object-storage/quotas/{quota_id}"
id_attribute = "quota_id"

properties = {
"quota_id": Property(identifier=True),
"quota_name": Property(),
"endpoint_type": Property(),
"s3_endpoint": Property(),
"description": Property(),
"quota_limit": Property(),
"resource_metric": Property(),
}

def usage(self):
"""
Gets usage data for a specific ObjectStorage Quota resource you can have on your account and the current usage for that resource.

API documentation: TBD

:returns: The Object Storage Quota usage.
:rtype: MappedObject
"""

result = self._client.get(
f"{type(self).api_endpoint}/usage",
model=self,
)

return MappedObject(**result)
25 changes: 25 additions & 0 deletions test/fixtures/object-storage_quotas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"data": [
{
"quota_id": "obj-objects-us-ord-1",
"quota_name": "Object Storage Maximum Objects",
"description": "Maximum number of Objects this customer is allowed to have on this endpoint.",
"endpoint_type": "E1",
"s3_endpoint": "us-iad-1.linodeobjects.com",
"quota_limit": 50,
"resource_metric": "object"
},
{
"quota_id": "obj-bucket-us-ord-1",
"quota_name": "Object Storage Maximum Buckets",
"description": "Maximum number of buckets this customer is allowed to have on this endpoint.",
"endpoint_type": "E1",
"s3_endpoint": "us-iad-1.linodeobjects.com",
"quota_limit": 50,
"resource_metric": "bucket"
}
],
"page": 1,
"pages": 1,
"results": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"quota_id": "obj-objects-us-ord-1",
"quota_name": "Object Storage Maximum Objects",
"description": "Maximum number of Objects this customer is allowed to have on this endpoint.",
"endpoint_type": "E1",
"s3_endpoint": "us-iad-1.linodeobjects.com",
"quota_limit": 50,
"resource_metric": "object"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"quota_limit": 100,
"usage": 10
}
51 changes: 51 additions & 0 deletions test/unit/objects/object_storage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
ObjectStorageACL,
ObjectStorageBucket,
ObjectStorageCluster,
ObjectStorageQuota,
)


Expand Down Expand Up @@ -284,3 +285,53 @@ def test_object_acl_config_update(self):
"name": "example",
},
)

def test_quota_get_and_list(self):
"""
Test that you can get and list an Object storage quota and usage information.
"""
quota = ObjectStorageQuota(
self.client,
"obj-objects-us-ord-1",
)

self.assertIsNotNone(quota)
self.assertEqual(quota.quota_id, "obj-objects-us-ord-1")
self.assertEqual(quota.quota_name, "Object Storage Maximum Objects")
self.assertEqual(
quota.description,
"Maximum number of Objects this customer is allowed to have on this endpoint.",
)
self.assertEqual(quota.endpoint_type, "E1")
self.assertEqual(quota.s3_endpoint, "us-iad-1.linodeobjects.com")
self.assertEqual(quota.quota_limit, 50)
self.assertEqual(quota.resource_metric, "object")

quota_usage_url = "/object-storage/quotas/obj-objects-us-ord-1/usage"
with self.mock_get(quota_usage_url) as m:
usage = quota.usage()
self.assertIsNotNone(usage)
self.assertEqual(m.call_url, quota_usage_url)
self.assertEqual(usage.quota_limit, 100)
self.assertEqual(usage.usage, 10)

quota_list_url = "/object-storage/quotas"
with self.mock_get(quota_list_url) as m:
quotas = self.client.object_storage.quotas()
self.assertIsNotNone(quotas)
self.assertEqual(m.call_url, quota_list_url)
self.assertEqual(len(quotas), 2)
self.assertEqual(quotas[0].quota_id, "obj-objects-us-ord-1")
self.assertEqual(
quotas[0].quota_name, "Object Storage Maximum Objects"
)
self.assertEqual(
quotas[0].description,
"Maximum number of Objects this customer is allowed to have on this endpoint.",
)
self.assertEqual(quotas[0].endpoint_type, "E1")
self.assertEqual(
quotas[0].s3_endpoint, "us-iad-1.linodeobjects.com"
)
self.assertEqual(quotas[0].quota_limit, 50)
self.assertEqual(quotas[0].resource_metric, "object")