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: 26 additions & 4 deletions hcloud/_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import time
import warnings
from http import HTTPStatus
from random import uniform
from typing import Any, Protocol
Expand Down Expand Up @@ -180,11 +181,10 @@ def __init__(
timeout=timeout,
)

self.datacenters = DatacentersClient(self)
"""DatacentersClient Instance
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
self.datacenters = DatacentersClient(self)

:type: :class:`DatacentersClient <hcloud.datacenters.client.DatacentersClient>`
"""
self.locations = LocationsClient(self)
"""LocationsClient Instance

Expand Down Expand Up @@ -302,6 +302,28 @@ def request( # type: ignore[no-untyped-def]
"""
return self._client.request(method, url, **kwargs)

@property
def datacenters(self) -> bool | None:
"""DatacentersClient Instance

.. deprecated:: 2.21.0
The datacenters client is deprecated and will be removed after the 2026-10-01.
See https://docs.hetzner.cloud/changelog#2026-06-02-datacenters-deprecated.

:type: :class:`DatacentersClient <hcloud.datacenters.client.DatacentersClient>`
"""
warnings.warn(
"The datacenters client is deprecated and will be removed after the 2026-10-01. "
"See https://docs.hetzner.cloud/changelog#2026-06-02-datacenters-deprecated.",
DeprecationWarning,
stacklevel=2,
)
return self._datacenters

@datacenters.setter
def datacenters(self, value: DatacentersClient) -> None:
self._datacenters = value


class ClientBase:
def __init__(
Expand Down
23 changes: 23 additions & 0 deletions hcloud/datacenters/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import warnings
from typing import Any, NamedTuple

from ..core import BoundModelBase, Meta, ResourceClientBase
Expand All @@ -15,6 +16,12 @@


class BoundDatacenter(BoundModelBase[Datacenter], Datacenter):
"""
.. deprecated:: 2.21.0
The bound datacenter class is deprecated and will be removed after the 2026-10-01.
See https://docs.hetzner.cloud/changelog#2026-06-02-datacenters-deprecated.
"""

_client: DatacentersClient

model = Datacenter
Expand Down Expand Up @@ -54,11 +61,27 @@ def __init__(self, client: DatacentersClient, data: dict[str, Any]):


class DatacentersPageResult(NamedTuple):
"""
.. deprecated:: 2.21.0
The datacenters page result class is deprecated and will be removed after the 2026-10-01.
See https://docs.hetzner.cloud/changelog#2026-06-02-datacenters-deprecated.
"""

datacenters: list[BoundDatacenter]
meta: Meta


@warnings.deprecated(
"The datacenters client class is deprecated and will be removed after the 2026-10-01. "
"See https://docs.hetzner.cloud/changelog#2026-06-02-datacenters-deprecated.",
)
class DatacentersClient(ResourceClientBase):
"""
.. deprecated:: 2.21.0
The datacenters client class is deprecated and will be removed after the 2026-10-01.
See https://docs.hetzner.cloud/changelog#2026-06-02-datacenters-deprecated.
"""

_base_url = "/datacenters"

def get_by_id(self, id: int) -> BoundDatacenter:
Expand Down
8 changes: 8 additions & 0 deletions hcloud/datacenters/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
class Datacenter(BaseDomain, DomainIdentityMixin):
"""Datacenter Domain

.. deprecated:: 2.21.0
The datacenters domain class is deprecated and will be removed after the 2026-10-01.
See https://docs.hetzner.cloud/changelog#2026-06-02-datacenters-deprecated.

:param id: int ID of Datacenter
:param name: str Name of Datacenter
:param description: str Description of Datacenter
Expand Down Expand Up @@ -69,6 +73,10 @@ def server_types(self, value: DatacenterServerTypes | None) -> None:
class DatacenterServerTypes(BaseDomain):
"""DatacenterServerTypes Domain

.. deprecated:: 2.21.0
The datacenters domain class is deprecated and will be removed after the 2026-10-01.
See https://docs.hetzner.cloud/changelog#2026-06-02-datacenters-deprecated.

:param available: List[:class:`BoundServerTypes <hcloud.server_types.client.BoundServerTypes>`]
All available server types for this datacenter
:param supported: List[:class:`BoundServerTypes <hcloud.server_types.client.BoundServerTypes>`]
Expand Down
4 changes: 3 additions & 1 deletion hcloud/primary_ips/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def __init__(

raw = data.get("datacenter", {})
if raw:
data["datacenter"] = BoundDatacenter(client._parent.datacenters, raw)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
data["datacenter"] = BoundDatacenter(client._parent.datacenters, raw)

raw = data.get("location", {})
if raw:
Expand Down
4 changes: 3 additions & 1 deletion hcloud/servers/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def __init__(
):
raw = data.get("datacenter")
if raw:
data["datacenter"] = BoundDatacenter(client._parent.datacenters, raw)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
data["datacenter"] = BoundDatacenter(client._parent.datacenters, raw)

raw = data.get("location")
if raw:
Expand Down
14 changes: 10 additions & 4 deletions tests/unit/actions/test_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import inspect
import warnings
from unittest import mock

import pytest
Expand Down Expand Up @@ -47,10 +48,15 @@ def test_resources_with_actions(client: Client):
"""
Ensure that the list of resource clients above is up to date.
"""
members = inspect.getmembers(
client,
predicate=lambda p: isinstance(p, ResourceClientBase) and hasattr(p, "actions"),
)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)

members = inspect.getmembers(
client,
predicate=lambda p: isinstance(p, ResourceClientBase)
and hasattr(p, "actions"),
)

for name, member in members:
assert name in resources_with_actions

Expand Down
7 changes: 6 additions & 1 deletion tests/unit/datacenters/test_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import warnings
from unittest import mock # noqa: F401

import pytest # noqa: F401
Expand All @@ -8,6 +9,8 @@
from hcloud.datacenters import BoundDatacenter, DatacentersClient, DatacenterServerTypes
from hcloud.locations import BoundLocation

warnings.filterwarnings("ignore", category=DeprecationWarning)


class TestBoundDatacenter:
def test_bound_datacenter_init(self, datacenter_response):
Expand Down Expand Up @@ -64,7 +67,9 @@ def test_bound_datacenter_init(self, datacenter_response):
class TestDatacentersClient:
@pytest.fixture()
def datacenters_client(self, client: Client):
return DatacentersClient(client)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
return DatacentersClient(client)

def test_get_by_id(
self,
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/datacenters/test_domain.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from __future__ import annotations

import warnings

import pytest

from hcloud.datacenters import Datacenter, DatacenterServerTypes

warnings.filterwarnings("ignore", category=DeprecationWarning)


@pytest.mark.parametrize(
"value",
Expand Down
Loading