Skip to content
Merged
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
21 changes: 17 additions & 4 deletions hcloud/primary_ips/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def create(
name: str,
datacenter: Datacenter | BoundDatacenter | None = None,
location: Location | BoundLocation | None = None,
assignee_type: str | None = "server",
assignee_type: str | None = None,
assignee_id: int | None = None,
auto_delete: bool | None = False,
labels: dict[str, str] | None = None,
Expand All @@ -328,13 +328,12 @@ def create(
:param labels: Dict[str, str] (optional) User-defined labels (key-value pairs)
:return: :class:`CreatePrimaryIPResponse <hcloud.primary_ips.domain.CreatePrimaryIPResponse>`
"""

data: dict[str, Any] = {
"name": name,
"type": type,
"assignee_type": assignee_type,
"auto_delete": auto_delete,
}

if datacenter is not None:
warnings.warn(
"The 'datacenter' argument is deprecated and will be removed after 1 July 2026. "
Expand All @@ -348,10 +347,24 @@ def create(
data["location"] = location.id_or_name
if assignee_id is not None:
data["assignee_id"] = assignee_id
if assignee_type is None:
assignee_type = "server"
warnings.warn(
"The 'assignee_type' argument will no longer default to 'server' "
"and will be required together with the 'assignee_id' argument. "
"Please explicitly set the 'assignee_type' argument.",
DeprecationWarning,
stacklevel=2,
)
data["assignee_type"] = assignee_type
if labels is not None:
data["labels"] = labels

response = self._client.request(url=self._base_url, json=data, method="POST")
response = self._client.request(
method="POST",
url=self._base_url,
json=data,
)

action = None
if response.get("action") is not None:
Expand Down
33 changes: 31 additions & 2 deletions tests/unit/primary_ips/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ def test_create_with_location(
json={
"name": "primary-ip1",
"type": "ipv4",
"assignee_type": "server",
"location": "fsn1",
"auto_delete": False,
},
Expand Down Expand Up @@ -194,7 +193,6 @@ def test_create_with_datacenter(
json={
"name": "primary-ip1",
"type": "ipv4",
"assignee_type": "server",
"datacenter": "fsn1-dc14",
"auto_delete": False,
},
Expand Down Expand Up @@ -236,6 +234,37 @@ def test_create_with_assignee_id(
assert_bound_primary_ip1(result.primary_ip, resource_client)
assert_bound_action1(result.action, resource_client._parent.actions)

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

with pytest.deprecated_call():
resource_client.create(
type="ipv4",
name="primary-ip1",
assignee_id=17,
)

request_mock.assert_called_with(
method="POST",
url="/primary_ips",
json={
"name": "primary-ip1",
"type": "ipv4",
"assignee_id": 17,
"assignee_type": "server",
"auto_delete": False,
},
)

@pytest.mark.parametrize(
"primary_ip",
[
Expand Down
Loading