Skip to content

Commit 4a0fce7

Browse files
authored
feat: add deprecation field to ServerType (#192)
1 parent 58714d1 commit 4a0fce7

7 files changed

Lines changed: 82 additions & 2 deletions

File tree

docs/api.deprecation.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Deprecation Info
2+
==================
3+
4+
.. autoclass:: hcloud.deprecation.domain.DeprecationInfo
5+
:members:

docs/api.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,12 @@ Exceptions
2727

2828
.. autoclass:: hcloud.actions.domain.ActionTimeoutException
2929
:members:
30+
31+
Other
32+
-------------
33+
34+
.. toctree::
35+
:maxdepth: 3
36+
37+
api.helpers
38+
api.deprecation

hcloud/deprecation/__init__.py

Whitespace-only changes.

hcloud/deprecation/domain.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from dateutil.parser import isoparse
2+
3+
from hcloud.core.domain import BaseDomain
4+
5+
6+
class DeprecationInfo(BaseDomain):
7+
"""Describes if, when & how the resources was deprecated. If this field is set to ``None`` the resource is not
8+
deprecated. If it has a value, it is considered deprecated.
9+
10+
:param announced: datetime
11+
Date of when the deprecation was announced.
12+
:param unavailable_after: datetime
13+
After the time in this field, the resource will not be available from the general listing endpoint of the
14+
resource type, and it can not be used in new resources. For example, if this is an image, you can not create
15+
new servers with this image after the mentioned date.
16+
"""
17+
18+
__slots__ = (
19+
"announced",
20+
"unavailable_after",
21+
)
22+
23+
def __init__(
24+
self,
25+
announced=None,
26+
unavailable_after=None,
27+
):
28+
self.announced = isoparse(announced) if announced else None
29+
self.unavailable_after = (
30+
isoparse(unavailable_after) if unavailable_after else None
31+
)

hcloud/server_types/domain.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from hcloud.core.domain import BaseDomain, DomainIdentityMixin
2+
from hcloud.deprecation.domain import DeprecationInfo
23

34

45
class ServerType(BaseDomain, DomainIdentityMixin):
@@ -25,7 +26,10 @@ class ServerType(BaseDomain, DomainIdentityMixin):
2526
:param architecture: string
2627
Architecture of cpu. Choices: `x86`, `arm`
2728
:param deprecated: bool
28-
True if server type is deprecated
29+
True if server type is deprecated. This field is deprecated. Use `deprecation` instead.
30+
:param deprecation: :class:`DeprecationInfo <hcloud.deprecation.domain.DeprecationInfo>`, None
31+
Describes if, when & how the resources was deprecated. If this field is set to None the resource is not
32+
deprecated. If it has a value, it is considered deprecated.
2933
:param included_traffic: int
3034
Free traffic per month in bytes
3135
"""
@@ -42,6 +46,7 @@ class ServerType(BaseDomain, DomainIdentityMixin):
4246
"cpu_type",
4347
"architecture",
4448
"deprecated",
49+
"deprecation",
4550
"included_traffic",
4651
)
4752

@@ -58,6 +63,7 @@ def __init__(
5863
cpu_type=None,
5964
architecture=None,
6065
deprecated=None,
66+
deprecation=None,
6167
included_traffic=None,
6268
):
6369
self.id = id
@@ -71,4 +77,7 @@ def __init__(
7177
self.cpu_type = cpu_type
7278
self.architecture = architecture
7379
self.deprecated = deprecated
80+
self.deprecation = (
81+
DeprecationInfo.from_dict(deprecation) if deprecation is not None else None
82+
)
7483
self.included_traffic = included_traffic

tests/unit/server_types/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ def server_type_response():
2828
"cpu_type": "shared",
2929
"architecture": "x86",
3030
"included_traffic": 21990232555520,
31+
"deprecated": True,
32+
"deprecation": {
33+
"announced": "2023-06-01T00:00:00+00:00",
34+
"unavailable_after": "2023-09-01T00:00:00+00:00",
35+
},
3136
}
3237
}
3338

@@ -60,6 +65,11 @@ def two_server_types_response():
6065
"cpu_type": "shared",
6166
"architecture": "x86",
6267
"included_traffic": 21990232555520,
68+
"deprecated": True,
69+
"deprecation": {
70+
"announced": "2023-06-01T00:00:00+00:00",
71+
"unavailable_after": "2023-09-01T00:00:00+00:00",
72+
},
6373
},
6474
{
6575
"id": 2,
@@ -96,6 +106,8 @@ def two_server_types_response():
96106
"cpu_type": "shared",
97107
"architecture": "x86",
98108
"included_traffic": 21990232555520,
109+
"deprecated": False,
110+
"deprecation": None,
99111
},
100112
]
101113
}
@@ -129,6 +141,11 @@ def one_server_types_response():
129141
"cpu_type": "shared",
130142
"architecture": "x86",
131143
"included_traffic": 21990232555520,
144+
"deprecated": True,
145+
"deprecation": {
146+
"announced": "2023-06-01T00:00:00+00:00",
147+
"unavailable_after": "2023-09-01T00:00:00+00:00",
148+
},
132149
}
133150
]
134151
}

tests/unit/server_types/test_client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
from datetime import datetime, timezone
12
from unittest import mock
23

34
import pytest
45

56
from hcloud.server_types.client import BoundServerType, ServerTypesClient
67

78

8-
class TestBoundIso:
9+
class TestBoundServerType:
910
@pytest.fixture()
1011
def bound_server_type(self, hetzner_client):
1112
return BoundServerType(client=hetzner_client.server_types, data=dict(id=14))
@@ -24,6 +25,14 @@ def test_bound_server_type_init(self, server_type_response):
2425
assert bound_server_type.storage_type == "local"
2526
assert bound_server_type.cpu_type == "shared"
2627
assert bound_server_type.architecture == "x86"
28+
assert bound_server_type.deprecated is True
29+
assert bound_server_type.deprecation is not None
30+
assert bound_server_type.deprecation.announced == datetime(
31+
2023, 6, 1, tzinfo=timezone.utc
32+
)
33+
assert bound_server_type.deprecation.unavailable_after == datetime(
34+
2023, 9, 1, tzinfo=timezone.utc
35+
)
2736
assert bound_server_type.included_traffic == 21990232555520
2837

2938

0 commit comments

Comments
 (0)