Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
30 changes: 27 additions & 3 deletions hcloud/datacenters/domain.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import warnings
from typing import TYPE_CHECKING

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

__api_properties__ = ("id", "name", "description", "location", "server_types")
__slots__ = __api_properties__
__properties__ = ("id", "name", "description", "location")
__api_properties__ = (*__properties__, "server_types")
__slots__ = (*__properties__, "_server_types")

def __init__(
self,
Expand All @@ -39,7 +41,29 @@ def __init__(
self.name = name
self.description = description
self.location = location
self.server_types = server_types
self._server_types = server_types

@property
def server_types(self) -> DatacenterServerTypes | None:
"""
.. deprecated:: 2.18.0
The 'server_types' property is deprecated and will not be supported after 2026-10-01.
Please use 'server_type.locations[]' instead.

See https://docs.hetzner.cloud/changelog#2026-04-01-datacenter-deprecations.
"""
warnings.warn(
"The 'server_types' property is deprecated and will not be supported after 2026-10-01. "
"Please use 'server_type.locations[]' instead. "
"See https://docs.hetzner.cloud/changelog#2026-04-01-datacenter-deprecations",
DeprecationWarning,
stacklevel=2,
)
return self._server_types

@server_types.setter
def server_types(self, value: DatacenterServerTypes | None) -> None:
self._server_types = value


class DatacenterServerTypes(BaseDomain):
Expand Down
8 changes: 8 additions & 0 deletions hcloud/server_types/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,15 @@ class ServerTypeLocation(BaseDomain):

:param location: Location of the Server Type.
:param deprecation: Wether the Server Type is deprecated in this Location.
:param available: Whether the Server Type is currently available in this Location.
:param recommended: Whether the Server Type is currently recommended in this Location.
"""

__api_properties__ = (
"location",
"deprecation",
"available",
"recommended",
)
__slots__ = __api_properties__

Expand All @@ -198,8 +202,12 @@ def __init__(
*,
location: BoundLocation,
deprecation: dict[str, Any] | None,
available: bool | None,
recommended: bool | None,
):
self.location = location
self.deprecation = (
DeprecationInfo.from_dict(deprecation) if deprecation is not None else None
)
self.available = available
self.recommended = recommended
64 changes: 34 additions & 30 deletions tests/unit/datacenters/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,40 @@ def test_bound_datacenter_init(self, datacenter_response):
assert bound_datacenter.location.name == "fsn1"
assert bound_datacenter.location.complete is True

assert isinstance(bound_datacenter.server_types, DatacenterServerTypes)
assert len(bound_datacenter.server_types.supported) == 3
assert bound_datacenter.server_types.supported[0].id == 1
assert bound_datacenter.server_types.supported[0].complete is False
assert bound_datacenter.server_types.supported[1].id == 2
assert bound_datacenter.server_types.supported[1].complete is False
assert bound_datacenter.server_types.supported[2].id == 3
assert bound_datacenter.server_types.supported[2].complete is False

assert len(bound_datacenter.server_types.available) == 3
assert bound_datacenter.server_types.available[0].id == 1
assert bound_datacenter.server_types.available[0].complete is False
assert bound_datacenter.server_types.available[1].id == 2
assert bound_datacenter.server_types.available[1].complete is False
assert bound_datacenter.server_types.available[2].id == 3
assert bound_datacenter.server_types.available[2].complete is False

assert len(bound_datacenter.server_types.available_for_migration) == 3
assert bound_datacenter.server_types.available_for_migration[0].id == 1
assert (
bound_datacenter.server_types.available_for_migration[0].complete is False
)
assert bound_datacenter.server_types.available_for_migration[1].id == 2
assert (
bound_datacenter.server_types.available_for_migration[1].complete is False
)
assert bound_datacenter.server_types.available_for_migration[2].id == 3
assert (
bound_datacenter.server_types.available_for_migration[2].complete is False
)
with pytest.deprecated_call():
assert isinstance(bound_datacenter.server_types, DatacenterServerTypes)
assert len(bound_datacenter.server_types.supported) == 3
assert bound_datacenter.server_types.supported[0].id == 1
assert bound_datacenter.server_types.supported[0].complete is False
assert bound_datacenter.server_types.supported[1].id == 2
assert bound_datacenter.server_types.supported[1].complete is False
assert bound_datacenter.server_types.supported[2].id == 3
assert bound_datacenter.server_types.supported[2].complete is False

assert len(bound_datacenter.server_types.available) == 3
assert bound_datacenter.server_types.available[0].id == 1
assert bound_datacenter.server_types.available[0].complete is False
assert bound_datacenter.server_types.available[1].id == 2
assert bound_datacenter.server_types.available[1].complete is False
assert bound_datacenter.server_types.available[2].id == 3
assert bound_datacenter.server_types.available[2].complete is False

assert len(bound_datacenter.server_types.available_for_migration) == 3
assert bound_datacenter.server_types.available_for_migration[0].id == 1
assert (
bound_datacenter.server_types.available_for_migration[0].complete
is False
)
assert bound_datacenter.server_types.available_for_migration[1].id == 2
assert (
bound_datacenter.server_types.available_for_migration[1].complete
is False
)
assert bound_datacenter.server_types.available_for_migration[2].id == 3
assert (
bound_datacenter.server_types.available_for_migration[2].complete
is False
)


class TestDatacentersClient:
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/server_types/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def server_type_response():
"id": 1,
"name": "nbg1",
"deprecation": None,
"available": True,
"recommended": False,
},
{
"id": 2,
Expand All @@ -49,6 +51,8 @@ def server_type_response():
"announced": "2023-06-01T00:00:00Z",
"unavailable_after": "2023-09-01T00:00:00Z",
},
"available": True,
"recommended": True,
},
],
}
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/server_types/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def test_init(self, server_type_response):
assert o.locations[0].location.id == 1
assert o.locations[0].location.name == "nbg1"
assert o.locations[0].deprecation is None
assert o.locations[0].available is True
assert o.locations[0].recommended is False
assert o.locations[1].location.id == 2
assert o.locations[1].location.name == "fsn1"
assert (
Expand All @@ -43,6 +45,8 @@ def test_init(self, server_type_response):
o.locations[1].deprecation.unavailable_after.isoformat()
== "2023-09-01T00:00:00+00:00"
)
assert o.locations[1].available is True
assert o.locations[1].recommended is True

with pytest.deprecated_call():
assert o.deprecated is True
Expand Down
Loading