Skip to content

Commit 1c30986

Browse files
Support listing Object Storage Types
1 parent f424bd2 commit 1c30986

File tree

5 files changed

+97
-0
lines changed

5 files changed

+97
-0
lines changed

linode_api4/groups/object_storage.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from linode_api4 import (
99
ObjectStorageEndpoint,
1010
ObjectStorageEndpointType,
11+
ObjectStorageType,
1112
PaginatedList,
1213
)
1314
from linode_api4.errors import UnexpectedResponseError
@@ -70,6 +71,24 @@ def keys(self, *filters):
7071
"""
7172
return self.client._get_and_filter(ObjectStorageKeys, *filters)
7273

74+
def types(self, *filters):
75+
"""
76+
Returns a :any:`PaginatedList` of :any:`ObjectStorageType` objects that represents a valid Object Storage type.
77+
78+
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-object-storage-types
79+
80+
:param filters: Any number of filters to apply to this query.
81+
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
82+
for more details on filtering.
83+
84+
:returns: A Paginated List of Object Storage types that match the query.
85+
:rtype: PaginatedList of ObjectStorageType
86+
"""
87+
88+
return self.client._get_and_filter(
89+
ObjectStorageType, *filters, endpoint="/object-storage/types"
90+
)
91+
7392
def keys_create(
7493
self,
7594
label: str,

linode_api4/objects/object_storage.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from deprecated import deprecated
66

7+
from linode_api4.common import Price, RegionPrice
78
from linode_api4.errors import UnexpectedResponseError
89
from linode_api4.objects import (
910
Base,
@@ -50,6 +51,24 @@ class ObjectStorageEndpoint(JSONObject):
5051
s3_endpoint: Optional[str] = None
5152

5253

54+
class ObjectStorageType(Base):
55+
"""
56+
An ObjectStorageType represents the structure of a valid Object Storage type.
57+
Currently, the ObjectStorageType can only be retrieved by listing, i.e.:
58+
types = client.object_storage.types()
59+
60+
API documentation: https://techdocs.akamai.com/linode-api/reference/get-object-storage-types
61+
"""
62+
63+
properties = {
64+
"id": Property(identifier=True),
65+
"label": Property(),
66+
"price": Property(json_object=Price),
67+
"region_prices": Property(json_object=RegionPrice),
68+
"transfer": Property(),
69+
}
70+
71+
5372
class ObjectStorageBucket(DerivedBase):
5473
"""
5574
A bucket where objects are stored in.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"data": [
3+
{
4+
"id": "objectstorage",
5+
"label": "Object Storage",
6+
"price": {
7+
"hourly": 0.0015,
8+
"monthly": 0.1
9+
},
10+
"region_prices": [
11+
{
12+
"hourly": 0.00018,
13+
"id": "us-east",
14+
"monthly": 0.12
15+
}
16+
],
17+
"transfer": 0
18+
}
19+
],
20+
"page": 1,
21+
"pages": 1,
22+
"results": 1
23+
}

test/integration/models/object_storage/test_obj.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55

6+
from linode_api4.common import RegionPrice
67
from linode_api4.linode_client import LinodeClient
78
from linode_api4.objects.object_storage import (
89
ObjectStorageACL,
@@ -11,6 +12,7 @@
1112
ObjectStorageEndpointType,
1213
ObjectStorageKeyPermission,
1314
ObjectStorageKeys,
15+
ObjectStorageType,
1416
)
1517

1618

@@ -191,3 +193,22 @@ def test_get_buckets_in_cluster(
191193
):
192194
cluster = test_linode_client.load(ObjectStorageCluster, bucket.cluster)
193195
assert any(bucket.id == b.id for b in cluster.buckets_in_cluster())
196+
197+
198+
def test_object_storage_types(test_linode_client):
199+
types = test_linode_client.object_storage.types()
200+
201+
if len(types) > 0:
202+
for object_storage_type in types:
203+
assert type(object_storage_type) is ObjectStorageType
204+
assert object_storage_type.price.monthly is None or (
205+
isinstance(object_storage_type.price.monthly, (float, int))
206+
and object_storage_type.price.monthly >= 0
207+
)
208+
if len(object_storage_type.region_prices) > 0:
209+
region_price = object_storage_type.region_prices[0]
210+
assert type(region_price) is RegionPrice
211+
assert object_storage_type.price.monthly is None or (
212+
isinstance(object_storage_type.price.monthly, (float, int))
213+
and object_storage_type.price.monthly >= 0
214+
)

test/unit/linode_client_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,21 @@ def test_get_keys(self):
980980
self.assertEqual(key2.access_key, "testAccessKeyHere456")
981981
self.assertEqual(key2.secret_key, "[REDACTED]")
982982

983+
def test_object_storage_types(self):
984+
"""
985+
Tests that a list of ObjectStorageTypes can be retrieved
986+
"""
987+
types = self.client.object_storage.types()
988+
self.assertEqual(len(types), 1)
989+
self.assertEqual(types[0].id, "objectstorage")
990+
self.assertEqual(types[0].label, "Object Storage")
991+
self.assertEqual(types[0].price.hourly, 0.0015)
992+
self.assertEqual(types[0].price.monthly, 0.1)
993+
self.assertEqual(types[0].region_prices[0].id, "us-east")
994+
self.assertEqual(types[0].region_prices[0].hourly, 0.00018)
995+
self.assertEqual(types[0].region_prices[0].monthly, 0.12)
996+
self.assertEqual(types[0].transfer, 0)
997+
983998
def test_keys_create(self):
984999
"""
9851000
Tests that you can create Object Storage Keys

0 commit comments

Comments
 (0)