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
19 changes: 0 additions & 19 deletions hcloud/primary_ips/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

if TYPE_CHECKING:
from .._client import Client
from ..datacenters import BoundDatacenter, Datacenter
from ..locations import BoundLocation, Location


Expand All @@ -39,15 +38,8 @@ def __init__(
complete: bool = True,
):
# pylint: disable=import-outside-toplevel
from ..datacenters import BoundDatacenter
from ..locations import BoundLocation

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

raw = data.get("location", {})
if raw:
data["location"] = BoundLocation(client._parent.locations, raw)
Expand Down Expand Up @@ -311,7 +303,6 @@ def create(
self,
type: str,
name: str,
datacenter: Datacenter | BoundDatacenter | None = None,
location: Location | BoundLocation | None = None,
assignee_type: str | None = None,
assignee_id: int | None = None,
Expand All @@ -322,7 +313,6 @@ def create(

:param type: str Primary IP type Choices: ipv4, ipv6
:param name: str
:param datacenter: Datacenter (optional)
:param location: Location (optional)
:param assignee_type: str (optional)
:param assignee_id: int (optional)
Expand All @@ -336,15 +326,6 @@ def create(
"auto_delete": auto_delete,
}

if datacenter is not None:
warnings.warn(
"The 'datacenter' argument is deprecated and will be removed after 1 July 2026. "
"Please use the 'location' argument instead. "
"See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters",
DeprecationWarning,
stacklevel=2,
)
data["datacenter"] = datacenter.id_or_name
if location is not None:
data["location"] = location.id_or_name
if assignee_id is not None:
Expand Down
41 changes: 2 additions & 39 deletions hcloud/primary_ips/domain.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from __future__ import annotations

import warnings
from typing import TYPE_CHECKING, TypedDict

from ..core import BaseDomain, DomainIdentityMixin

if TYPE_CHECKING:
from ..actions import BoundAction
from ..datacenters import BoundDatacenter
from ..locations import BoundLocation
from ..rdns import DNSPtr
from .client import BoundPrimaryIP
Expand All @@ -30,14 +28,6 @@ class PrimaryIP(BaseDomain, DomainIdentityMixin):
Type of Primary IP. Choices: `ipv4`, `ipv6`
:param dns_ptr: List[Dict]
Array of reverse DNS entries
:param datacenter: :class:`Datacenter <hcloud.datacenters.client.BoundDatacenter>`
Datacenter the Primary IP was created in.

This property is deprecated and will be removed after 1 July 2026.
Please use the ``location`` property instead.

See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters.

:param location: :class:`Location <hcloud.locations.client.BoundLocation>`
Location the Primary IP was created in.
:param blocked: boolean
Expand All @@ -58,7 +48,7 @@ class PrimaryIP(BaseDomain, DomainIdentityMixin):
Delete the Primary IP when the Assignee it is assigned to is deleted.
"""

__properties__ = (
__api_properties__ = (
"id",
"ip",
"type",
Expand All @@ -73,22 +63,14 @@ class PrimaryIP(BaseDomain, DomainIdentityMixin):
"assignee_type",
"auto_delete",
)
__api_properties__ = (
*__properties__,
"datacenter",
)
__slots__ = (
*__properties__,
"_datacenter",
)
__slots__ = __api_properties__

def __init__(
self,
id: int | None = None,
type: str | None = None,
ip: str | None = None,
dns_ptr: list[DNSPtr] | None = None,
datacenter: BoundDatacenter | None = None,
location: BoundLocation | None = None,
blocked: bool | None = None,
protection: PrimaryIPProtection | None = None,
Expand All @@ -103,7 +85,6 @@ def __init__(
self.type = type
self.ip = ip
self.dns_ptr = dns_ptr
self.datacenter = datacenter
self.location = location
self.blocked = blocked
self.protection = protection
Expand All @@ -114,24 +95,6 @@ def __init__(
self.assignee_type = assignee_type
self.auto_delete = auto_delete

@property
def datacenter(self) -> BoundDatacenter | None:
"""
:meta private:
"""
warnings.warn(
"The 'datacenter' property is deprecated and will be removed after 1 July 2026. "
"Please use the 'location' property instead. "
"See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters.",
DeprecationWarning,
stacklevel=2,
)
return self._datacenter

@datacenter.setter
def datacenter(self, value: BoundDatacenter | None) -> None:
self._datacenter = value


class PrimaryIPProtection(TypedDict):
delete: bool
Expand Down
20 changes: 0 additions & 20 deletions hcloud/servers/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import warnings
from datetime import datetime
from typing import TYPE_CHECKING, Any, NamedTuple

Expand All @@ -15,7 +14,6 @@
)
from ..actions.client import ResourceClientBaseActionsMixin
from ..core import BoundModelBase, Meta, ResourceClientBase
from ..datacenters import BoundDatacenter
from ..firewalls import BoundFirewall
from ..floating_ips import BoundFloatingIP
from ..images import BoundImage, CreateImageResponse
Expand Down Expand Up @@ -44,7 +42,6 @@

if TYPE_CHECKING:
from .._client import Client
from ..datacenters import Datacenter
from ..firewalls import Firewall
from ..images import Image
from ..isos import Iso
Expand Down Expand Up @@ -75,12 +72,6 @@ def __init__(
data: dict[str, Any],
complete: bool = True,
):
raw = data.get("datacenter")
if raw:
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
data["datacenter"] = BoundDatacenter(client._parent.datacenters, raw)

raw = data.get("location")
if raw:
data["location"] = BoundLocation(client._parent.locations, raw)
Expand Down Expand Up @@ -636,7 +627,6 @@ def create(
user_data: str | None = None,
labels: dict[str, str] | None = None,
location: Location | BoundLocation | None = None,
datacenter: Datacenter | BoundDatacenter | None = None,
start_after_create: bool | None = True,
automount: bool | None = None,
placement_group: PlacementGroup | BoundPlacementGroup | None = None,
Expand All @@ -661,7 +651,6 @@ def create(
:param labels: Dict[str,str] (optional)
User-defined labels (key-value pairs)
:param location: :class:`BoundLocation <hcloud.locations.client.BoundLocation>` or :class:`Location <hcloud.locations.domain.Location>`
:param datacenter: :class:`BoundDatacenter <hcloud.datacenters.client.BoundDatacenter>` or :class:`Datacenter <hcloud.datacenters.domain.Datacenter>`
:param start_after_create: boolean (optional)
Start Server right after creation. Defaults to True.
:param automount: boolean (optional)
Expand All @@ -681,15 +670,6 @@ def create(

if location is not None:
data["location"] = location.id_or_name
if datacenter is not None:
warnings.warn(
"The 'datacenter' argument is deprecated and will be removed after 1 July 2026. "
"Please use the 'location' argument instead. "
"See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters",
DeprecationWarning,
stacklevel=2,
)
data["datacenter"] = datacenter.id_or_name
if ssh_keys is not None:
data["ssh_keys"] = [ssh_key.id_or_name for ssh_key in ssh_keys]
if volumes is not None:
Expand Down
39 changes: 2 additions & 37 deletions hcloud/servers/domain.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from __future__ import annotations

import warnings
from typing import TYPE_CHECKING, Literal, TypedDict

from ..core import BaseDomain, DomainIdentityMixin

if TYPE_CHECKING:
from ..actions import BoundAction
from ..datacenters import BoundDatacenter
from ..firewalls import BoundFirewall
from ..floating_ips import BoundFloatingIP
from ..images import BoundImage
Expand Down Expand Up @@ -56,12 +54,6 @@ class Server(BaseDomain, DomainIdentityMixin):
:param public_net: :class:`PublicNetwork <hcloud.servers.domain.PublicNetwork>`
Public network information.
:param server_type: :class:`BoundServerType <hcloud.server_types.client.BoundServerType>`
:param datacenter: :class:`BoundDatacenter <hcloud.datacenters.client.BoundDatacenter>`

This property is deprecated and will be removed after 1 July 2026.
Please use the ``location`` property instead.

See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters.
:param location: :class:`BoundLocation <hcloud.locations.client.BoundLocation>`
:param image: :class:`BoundImage <hcloud.images.client.BoundImage>`, None
:param iso: :class:`BoundIso <hcloud.isos.client.BoundIso>`, None
Expand Down Expand Up @@ -108,7 +100,7 @@ class Server(BaseDomain, DomainIdentityMixin):
STATUS_UNKNOWN = "unknown"
"""Server Status unknown"""

__properties__ = (
__api_properties__ = (
"id",
"name",
"status",
Expand All @@ -131,14 +123,7 @@ class Server(BaseDomain, DomainIdentityMixin):
"primary_disk_size",
"placement_group",
)
__api_properties__ = (
*__properties__,
"datacenter",
)
__slots__ = (
*__properties__,
"_datacenter",
)
__slots__ = __api_properties__

# pylint: disable=too-many-locals
def __init__(
Expand All @@ -149,7 +134,6 @@ def __init__(
created: str | None = None,
public_net: PublicNetwork | None = None,
server_type: BoundServerType | None = None,
datacenter: BoundDatacenter | None = None,
location: BoundLocation | None = None,
image: BoundImage | None = None,
iso: BoundIso | None = None,
Expand All @@ -172,7 +156,6 @@ def __init__(
self.created = self._parse_datetime(created)
self.public_net = public_net
self.server_type = server_type
self.datacenter = datacenter
self.location = location
self.image = image
self.iso = iso
Expand All @@ -199,24 +182,6 @@ def private_net_for(self, network: BoundNetwork | Network) -> PrivateNet | None:
return o
return None

@property
def datacenter(self) -> BoundDatacenter | None:
"""
:meta private:
"""
warnings.warn(
"The 'datacenter' property is deprecated and will be removed after 1 July 2026. "
"Please use the 'location' property instead. "
"See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters.",
DeprecationWarning,
stacklevel=2,
)
return self._datacenter

@datacenter.setter
def datacenter(self, value: BoundDatacenter | None) -> None:
self._datacenter = value


class ServerProtection(TypedDict):
rebuild: bool
Expand Down
8 changes: 0 additions & 8 deletions tests/unit/primary_ips/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ def primary_ip1():
"assignee_type": "server",
"auto_delete": True,
"blocked": False,
"datacenter": {
"id": 4,
"name": "fsn1-dc14",
},
"location": {
"id": 1,
"name": "fsn1",
Expand All @@ -42,10 +38,6 @@ def primary_ip2():
"assignee_type": "server",
"auto_delete": True,
"blocked": False,
"datacenter": {
"id": 4,
"name": "fsn1-dc14",
},
"location": {
"id": 1,
"name": "fsn1",
Expand Down
39 changes: 0 additions & 39 deletions tests/unit/primary_ips/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import pytest

from hcloud import Client
from hcloud.datacenters import BoundDatacenter, Datacenter
from hcloud.locations import BoundLocation, Location
from hcloud.primary_ips import BoundPrimaryIP, PrimaryIP, PrimaryIPsClient

Expand Down Expand Up @@ -62,13 +61,6 @@ def test_init(self, primary_ip1):
assert o.location.id == 1
assert o.location.name == "fsn1"

with pytest.deprecated_call():
datacenter = o.datacenter

assert isinstance(datacenter, BoundDatacenter)
assert datacenter.id == 4
assert datacenter.name == "fsn1-dc14"


class TestPrimaryIPsClient:
@pytest.fixture()
Expand Down Expand Up @@ -169,37 +161,6 @@ def test_create_with_location(
assert_bound_primary_ip1(result.primary_ip, resource_client)
assert result.action is None

def test_create_with_datacenter(
self,
request_mock: mock.MagicMock,
resource_client: PrimaryIPsClient,
primary_ip1,
):
request_mock.return_value = {
"primary_ip": primary_ip1,
"action": None,
}

with pytest.deprecated_call():
result = resource_client.create(
type="ipv4",
name="primary-ip1",
datacenter=Datacenter(name="fsn1-dc14"),
)

request_mock.assert_called_with(
method="POST",
url="/primary_ips",
json={
"name": "primary-ip1",
"type": "ipv4",
"datacenter": "fsn1-dc14",
"auto_delete": False,
},
)
assert_bound_primary_ip1(result.primary_ip, resource_client)
assert result.action is None

def test_create_with_assignee_id(
self,
request_mock: mock.MagicMock,
Expand Down
Loading
Loading