Skip to content

Commit 36a5938

Browse files
committed
feat: deprecate datacenter in primary ips and servers
See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters
1 parent 9e7cd39 commit 36a5938

File tree

4 files changed

+81
-6
lines changed

4 files changed

+81
-6
lines changed

hcloud/primary_ips/client.py

Lines changed: 13 additions & 0 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, Any, NamedTuple
45

56
from ..actions import BoundAction, ResourceActionsClient
@@ -9,6 +10,7 @@
910
if TYPE_CHECKING:
1011
from .._client import Client
1112
from ..datacenters import BoundDatacenter, Datacenter
13+
from ..locations import BoundLocation, Location
1214

1315

1416
class BoundPrimaryIP(BoundModelBase, PrimaryIP):
@@ -196,6 +198,7 @@ def create(
196198
type: str,
197199
name: str,
198200
datacenter: Datacenter | BoundDatacenter | None = None,
201+
location: Location | BoundLocation | None = None,
199202
assignee_type: str | None = "server",
200203
assignee_id: int | None = None,
201204
auto_delete: bool | None = False,
@@ -206,6 +209,7 @@ def create(
206209
:param type: str Primary IP type Choices: ipv4, ipv6
207210
:param name: str
208211
:param datacenter: Datacenter (optional)
212+
:param location: Location (optional)
209213
:param assignee_type: str (optional)
210214
:param assignee_id: int (optional)
211215
:param auto_delete: bool (optional)
@@ -220,7 +224,16 @@ def create(
220224
"auto_delete": auto_delete,
221225
}
222226
if datacenter is not None:
227+
warnings.warn(
228+
"The 'datacenter' argument is deprecated and will be removed after 1 July 2026. "
229+
"Please use the 'location' argument instead. "
230+
"See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters",
231+
DeprecationWarning,
232+
stacklevel=2,
233+
)
223234
data["datacenter"] = datacenter.id_or_name
235+
if location is not None:
236+
data["location"] = location.id_or_name
224237
if assignee_id is not None:
225238
data["assignee_id"] = assignee_id
226239
if labels is not None:

hcloud/primary_ips/domain.py

Lines changed: 30 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 dateutil.parser import isoparse
@@ -9,6 +10,7 @@
910
if TYPE_CHECKING:
1011
from ..actions import BoundAction
1112
from ..datacenters import BoundDatacenter
13+
from ..locations import BoundLocation
1214
from .client import BoundPrimaryIP
1315

1416

@@ -25,6 +27,8 @@ class PrimaryIP(BaseDomain, DomainIdentityMixin):
2527
Array of reverse DNS entries
2628
:param datacenter: :class:`Datacenter <hcloud.datacenters.client.BoundDatacenter>`
2729
Datacenter the Primary IP was created in.
30+
:param location: :class:`Location <hcloud.locations.client.BoundLocation>`
31+
Location the Primary IP was created in.
2832
:param blocked: boolean
2933
Whether the IP is blocked
3034
:param protection: dict
@@ -43,12 +47,11 @@ class PrimaryIP(BaseDomain, DomainIdentityMixin):
4347
Delete the Primary IP when the Assignee it is assigned to is deleted.
4448
"""
4549

46-
__api_properties__ = (
50+
__properties__ = (
4751
"id",
4852
"ip",
4953
"type",
5054
"dns_ptr",
51-
"datacenter",
5255
"blocked",
5356
"protection",
5457
"labels",
@@ -58,7 +61,14 @@ class PrimaryIP(BaseDomain, DomainIdentityMixin):
5861
"assignee_type",
5962
"auto_delete",
6063
)
61-
__slots__ = __api_properties__
64+
__api_properties__ = (
65+
*__properties__,
66+
"datacenter",
67+
)
68+
__slots__ = (
69+
*__properties__,
70+
"_datacenter",
71+
)
6272

6373
def __init__(
6474
self,
@@ -67,6 +77,7 @@ def __init__(
6777
ip: str | None = None,
6878
dns_ptr: list[dict] | None = None,
6979
datacenter: BoundDatacenter | None = None,
80+
location: BoundLocation | None = None,
7081
blocked: bool | None = None,
7182
protection: dict | None = None,
7283
labels: dict[str, dict] | None = None,
@@ -81,6 +92,7 @@ def __init__(
8192
self.ip = ip
8293
self.dns_ptr = dns_ptr
8394
self.datacenter = datacenter
95+
self.location = location
8496
self.blocked = blocked
8597
self.protection = protection
8698
self.labels = labels
@@ -90,6 +102,21 @@ def __init__(
90102
self.assignee_type = assignee_type
91103
self.auto_delete = auto_delete
92104

105+
@property
106+
def datacenter(self) -> BoundDatacenter | None:
107+
warnings.warn(
108+
"The 'datacenter' property is deprecated and will be removed after 1 July 2026. "
109+
"Please use the 'location' property instead. "
110+
"See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters",
111+
DeprecationWarning,
112+
stacklevel=2,
113+
)
114+
return self._datacenter
115+
116+
@datacenter.setter
117+
def datacenter(self, value: BoundDatacenter | None) -> None:
118+
self._datacenter = value
119+
93120

94121
class CreatePrimaryIPResponse(BaseDomain):
95122
"""Create Primary IP Response Domain

hcloud/servers/client.py

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

3+
import warnings
34
from datetime import datetime
45
from typing import TYPE_CHECKING, Any, NamedTuple
56

@@ -657,6 +658,13 @@ def create(
657658
if location is not None:
658659
data["location"] = location.id_or_name
659660
if datacenter is not None:
661+
warnings.warn(
662+
"The 'datacenter' argument is deprecated and will be removed after 1 July 2026. "
663+
"Please use the 'location' argument instead. "
664+
"See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters",
665+
DeprecationWarning,
666+
stacklevel=2,
667+
)
660668
data["datacenter"] = datacenter.id_or_name
661669
if ssh_keys is not None:
662670
data["ssh_keys"] = [ssh_key.id_or_name for ssh_key in ssh_keys]

hcloud/servers/domain.py

Lines changed: 30 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, Literal
45

56
from dateutil.parser import isoparse
@@ -13,6 +14,7 @@
1314
from ..floating_ips import BoundFloatingIP
1415
from ..images import BoundImage
1516
from ..isos import BoundIso
17+
from ..locations import BoundLocation
1618
from ..metrics import Metrics
1719
from ..networks import BoundNetwork, Network
1820
from ..placement_groups import BoundPlacementGroup
@@ -37,6 +39,7 @@ class Server(BaseDomain, DomainIdentityMixin):
3739
Public network information.
3840
:param server_type: :class:`BoundServerType <hcloud.server_types.client.BoundServerType>`
3941
:param datacenter: :class:`BoundDatacenter <hcloud.datacenters.client.BoundDatacenter>`
42+
:param location: :class:`BoundLocation <hcloud.locations.client.BoundLocation>`
4043
:param image: :class:`BoundImage <hcloud.images.client.BoundImage>`, None
4144
:param iso: :class:`BoundIso <hcloud.isos.client.BoundIso>`, None
4245
:param rescue_enabled: bool
@@ -82,13 +85,13 @@ class Server(BaseDomain, DomainIdentityMixin):
8285
STATUS_UNKNOWN = "unknown"
8386
"""Server Status unknown"""
8487

85-
__api_properties__ = (
88+
__properties__ = (
8689
"id",
8790
"name",
8891
"status",
8992
"public_net",
9093
"server_type",
91-
"datacenter",
94+
"location",
9295
"image",
9396
"iso",
9497
"rescue_enabled",
@@ -105,7 +108,14 @@ class Server(BaseDomain, DomainIdentityMixin):
105108
"primary_disk_size",
106109
"placement_group",
107110
)
108-
__slots__ = __api_properties__
111+
__api_properties__ = (
112+
*__properties__,
113+
"datacenter",
114+
)
115+
__slots__ = (
116+
*__properties__,
117+
"_datacenter",
118+
)
109119

110120
# pylint: disable=too-many-locals
111121
def __init__(
@@ -117,6 +127,7 @@ def __init__(
117127
public_net: PublicNetwork | None = None,
118128
server_type: BoundServerType | None = None,
119129
datacenter: BoundDatacenter | None = None,
130+
location: BoundLocation | None = None,
120131
image: BoundImage | None = None,
121132
iso: BoundIso | None = None,
122133
rescue_enabled: bool | None = None,
@@ -139,6 +150,7 @@ def __init__(
139150
self.public_net = public_net
140151
self.server_type = server_type
141152
self.datacenter = datacenter
153+
self.location = location
142154
self.image = image
143155
self.iso = iso
144156
self.rescue_enabled = rescue_enabled
@@ -164,6 +176,21 @@ def private_net_for(self, network: BoundNetwork | Network) -> PrivateNet | None:
164176
return o
165177
return None
166178

179+
@property
180+
def datacenter(self) -> BoundDatacenter | None:
181+
warnings.warn(
182+
"The 'datacenter' property is deprecated and will be removed after 1 July 2026. "
183+
"Please use the 'location' property instead. "
184+
"See https://docs.hetzner.cloud/changelog#2025-12-16-phasing-out-datacenters",
185+
DeprecationWarning,
186+
stacklevel=2,
187+
)
188+
return self._datacenter
189+
190+
@datacenter.setter
191+
def datacenter(self, value: BoundDatacenter | None) -> None:
192+
self._datacenter = value
193+
167194

168195
class CreateServerResponse(BaseDomain):
169196
"""Create Server Response Domain

0 commit comments

Comments
 (0)