Skip to content

Commit 234cf84

Browse files
committed
feat(datacenter, server_type): move available and recommended to server_type
1 parent 8e36441 commit 234cf84

File tree

5 files changed

+71
-32
lines changed

5 files changed

+71
-32
lines changed

hcloud/datacenters/domain.py

Lines changed: 24 additions & 2 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
@@ -25,7 +26,7 @@ class Datacenter(BaseDomain, DomainIdentityMixin):
2526
"""
2627

2728
__api_properties__ = ("id", "name", "description", "location", "server_types")
28-
__slots__ = __api_properties__
29+
__slots__ = ("id", "name", "description", "location", "_server_types")
2930

3031
def __init__(
3132
self,
@@ -39,8 +40,29 @@ def __init__(
3940
self.name = name
4041
self.description = description
4142
self.location = location
42-
self.server_types = server_types
43+
self._server_types = server_types
44+
45+
@property
46+
def server_types(self) -> DatacenterServerTypes | None:
47+
"""
48+
.. deprecated:: 2.18.0
49+
The 'server_types' property is deprecated and will not be supported after 2026-10-01.
50+
Please use 'server_type.locations[]' instead.
51+
52+
See https://docs.hetzner.cloud/changelog#2026-04-01-datacenter-deprecations.
53+
"""
54+
warnings.warn(
55+
"The 'server_types' property is deprecated and will not be supported after 2026-10-01. "
56+
"Please use 'server_type.locations[]' instead. "
57+
"See https://docs.hetzner.cloud/changelog#2026-04-01-datacenter-deprecations",
58+
DeprecationWarning,
59+
stacklevel=2,
60+
)
61+
return self._server_types
4362

63+
@server_types.setter
64+
def server_types(self, value: DatacenterServerTypes | None) -> None:
65+
self._server_types = value
4466

4567
class DatacenterServerTypes(BaseDomain):
4668
"""DatacenterServerTypes Domain

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: True if the Server Type is currently available in this Location.
189+
:param recommended: True if 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: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,37 @@ 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 is False
50+
)
51+
assert bound_datacenter.server_types.available_for_migration[1].id == 2
52+
assert (
53+
bound_datacenter.server_types.available_for_migration[1].complete is False
54+
)
55+
assert bound_datacenter.server_types.available_for_migration[2].id == 3
56+
assert (
57+
bound_datacenter.server_types.available_for_migration[2].complete is False
58+
)
5859

5960

6061
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)