Skip to content

Commit fb34c3e

Browse files
phm07jooola
andauthored
feat(datacenter, server_type): move available and recommended to server_type (#645)
See https://docs.hetzner.cloud/changelog#2026-04-01-datacenter-deprecations --------- Co-authored-by: jo <ljonas@riseup.net>
1 parent 8e36441 commit fb34c3e

5 files changed

Lines changed: 77 additions & 33 deletions

File tree

hcloud/datacenters/domain.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import warnings
34
from typing import TYPE_CHECKING
45

56
from ..core import BaseDomain, DomainIdentityMixin
@@ -24,8 +25,9 @@ class Datacenter(BaseDomain, DomainIdentityMixin):
2425
:param server_types: :class:`DatacenterServerTypes <hcloud.datacenters.domain.DatacenterServerTypes>`
2526
"""
2627

27-
__api_properties__ = ("id", "name", "description", "location", "server_types")
28-
__slots__ = __api_properties__
28+
__properties__ = ("id", "name", "description", "location")
29+
__api_properties__ = (*__properties__, "server_types")
30+
__slots__ = (*__properties__, "_server_types")
2931

3032
def __init__(
3133
self,
@@ -39,7 +41,29 @@ def __init__(
3941
self.name = name
4042
self.description = description
4143
self.location = location
42-
self.server_types = server_types
44+
self._server_types = server_types
45+
46+
@property
47+
def server_types(self) -> DatacenterServerTypes | None:
48+
"""
49+
.. deprecated:: 2.18.0
50+
The 'server_types' property is deprecated and will not be supported after 2026-10-01.
51+
Please use 'server_type.locations[]' instead.
52+
53+
See https://docs.hetzner.cloud/changelog#2026-04-01-datacenter-deprecations.
54+
"""
55+
warnings.warn(
56+
"The 'server_types' property is deprecated and will not be supported after 2026-10-01. "
57+
"Please use 'server_type.locations[]' instead. "
58+
"See https://docs.hetzner.cloud/changelog#2026-04-01-datacenter-deprecations.",
59+
DeprecationWarning,
60+
stacklevel=2,
61+
)
62+
return self._server_types
63+
64+
@server_types.setter
65+
def server_types(self, value: DatacenterServerTypes | None) -> None:
66+
self._server_types = value
4367

4468

4569
class DatacenterServerTypes(BaseDomain):

hcloud/server_types/domain.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,15 @@ class ServerTypeLocation(BaseDomain):
185185
186186
:param location: Location of the Server Type.
187187
:param deprecation: Wether the Server Type is deprecated in this Location.
188+
:param available: Whether the Server Type is currently available in this Location.
189+
:param recommended: Whether the Server Type is currently recommended in this Location.
188190
"""
189191

190192
__api_properties__ = (
191193
"location",
192194
"deprecation",
195+
"available",
196+
"recommended",
193197
)
194198
__slots__ = __api_properties__
195199

@@ -198,8 +202,12 @@ def __init__(
198202
*,
199203
location: BoundLocation,
200204
deprecation: dict[str, Any] | None,
205+
available: bool | None,
206+
recommended: bool | None,
201207
):
202208
self.location = location
203209
self.deprecation = (
204210
DeprecationInfo.from_dict(deprecation) if deprecation is not None else None
205211
)
212+
self.available = available
213+
self.recommended = recommended

tests/unit/datacenters/test_client.py

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,40 @@ def test_bound_datacenter_init(self, datacenter_response):
2525
assert bound_datacenter.location.name == "fsn1"
2626
assert bound_datacenter.location.complete is True
2727

28-
assert isinstance(bound_datacenter.server_types, DatacenterServerTypes)
29-
assert len(bound_datacenter.server_types.supported) == 3
30-
assert bound_datacenter.server_types.supported[0].id == 1
31-
assert bound_datacenter.server_types.supported[0].complete is False
32-
assert bound_datacenter.server_types.supported[1].id == 2
33-
assert bound_datacenter.server_types.supported[1].complete is False
34-
assert bound_datacenter.server_types.supported[2].id == 3
35-
assert bound_datacenter.server_types.supported[2].complete is False
36-
37-
assert len(bound_datacenter.server_types.available) == 3
38-
assert bound_datacenter.server_types.available[0].id == 1
39-
assert bound_datacenter.server_types.available[0].complete is False
40-
assert bound_datacenter.server_types.available[1].id == 2
41-
assert bound_datacenter.server_types.available[1].complete is False
42-
assert bound_datacenter.server_types.available[2].id == 3
43-
assert bound_datacenter.server_types.available[2].complete is False
44-
45-
assert len(bound_datacenter.server_types.available_for_migration) == 3
46-
assert bound_datacenter.server_types.available_for_migration[0].id == 1
47-
assert (
48-
bound_datacenter.server_types.available_for_migration[0].complete is False
49-
)
50-
assert bound_datacenter.server_types.available_for_migration[1].id == 2
51-
assert (
52-
bound_datacenter.server_types.available_for_migration[1].complete is False
53-
)
54-
assert bound_datacenter.server_types.available_for_migration[2].id == 3
55-
assert (
56-
bound_datacenter.server_types.available_for_migration[2].complete is False
57-
)
28+
with pytest.deprecated_call():
29+
assert isinstance(bound_datacenter.server_types, DatacenterServerTypes)
30+
assert len(bound_datacenter.server_types.supported) == 3
31+
assert bound_datacenter.server_types.supported[0].id == 1
32+
assert bound_datacenter.server_types.supported[0].complete is False
33+
assert bound_datacenter.server_types.supported[1].id == 2
34+
assert bound_datacenter.server_types.supported[1].complete is False
35+
assert bound_datacenter.server_types.supported[2].id == 3
36+
assert bound_datacenter.server_types.supported[2].complete is False
37+
38+
assert len(bound_datacenter.server_types.available) == 3
39+
assert bound_datacenter.server_types.available[0].id == 1
40+
assert bound_datacenter.server_types.available[0].complete is False
41+
assert bound_datacenter.server_types.available[1].id == 2
42+
assert bound_datacenter.server_types.available[1].complete is False
43+
assert bound_datacenter.server_types.available[2].id == 3
44+
assert bound_datacenter.server_types.available[2].complete is False
45+
46+
assert len(bound_datacenter.server_types.available_for_migration) == 3
47+
assert bound_datacenter.server_types.available_for_migration[0].id == 1
48+
assert (
49+
bound_datacenter.server_types.available_for_migration[0].complete
50+
is False
51+
)
52+
assert bound_datacenter.server_types.available_for_migration[1].id == 2
53+
assert (
54+
bound_datacenter.server_types.available_for_migration[1].complete
55+
is False
56+
)
57+
assert bound_datacenter.server_types.available_for_migration[2].id == 3
58+
assert (
59+
bound_datacenter.server_types.available_for_migration[2].complete
60+
is False
61+
)
5862

5963

6064
class TestDatacentersClient:

tests/unit/server_types/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def server_type_response():
4141
"id": 1,
4242
"name": "nbg1",
4343
"deprecation": None,
44+
"available": True,
45+
"recommended": False,
4446
},
4547
{
4648
"id": 2,
@@ -49,6 +51,8 @@ def server_type_response():
4951
"announced": "2023-06-01T00:00:00Z",
5052
"unavailable_after": "2023-09-01T00:00:00Z",
5153
},
54+
"available": True,
55+
"recommended": True,
5256
},
5357
],
5458
}

tests/unit/server_types/test_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def test_init(self, server_type_response):
3333
assert o.locations[0].location.id == 1
3434
assert o.locations[0].location.name == "nbg1"
3535
assert o.locations[0].deprecation is None
36+
assert o.locations[0].available is True
37+
assert o.locations[0].recommended is False
3638
assert o.locations[1].location.id == 2
3739
assert o.locations[1].location.name == "fsn1"
3840
assert (
@@ -43,6 +45,8 @@ def test_init(self, server_type_response):
4345
o.locations[1].deprecation.unavailable_after.isoformat()
4446
== "2023-09-01T00:00:00+00:00"
4547
)
48+
assert o.locations[1].available is True
49+
assert o.locations[1].recommended is True
4650

4751
with pytest.deprecated_call():
4852
assert o.deprecated is True

0 commit comments

Comments
 (0)