Skip to content

fix(ipam): make public detach & move ips idempotency #646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 10, 2024
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
28 changes: 22 additions & 6 deletions scaleway-async/scaleway_async/ipam/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
AttachIPRequest,
BookIPRequest,
CustomResource,
DetachIPRequest,
IP,
ListIPsResponse,
MoveIPRequest,
Expand All @@ -32,6 +33,7 @@
unmarshal_ListIPsResponse,
marshal_AttachIPRequest,
marshal_BookIPRequest,
marshal_DetachIPRequest,
marshal_MoveIPRequest,
marshal_ReleaseIPSetRequest,
marshal_UpdateIPRequest,
Expand Down Expand Up @@ -63,7 +65,7 @@ async def book_ip(
:param project_id: When creating an IP in a Private Network, the Project must match the Private Network's Project.
:param address: The requested address should not include the subnet mask (/suffix). Note that only the Private Network source allows you to pick a specific IP. If the requested IP is already booked, then the call will fail.
:param tags: Tags for the IP.
:param resource: Custom resource to attach to the IP being booked. An example of a custom resource is a virtual machine hosted on an Elastic Metal server, or an additional user network interface on an Instance. Do not use this for attaching IP addresses to standard Scaleway resources, as it will fail - instead, see the relevant product API for an equivalent method.
:param resource: Custom resource to attach to the IP being booked. An example of a custom resource is a virtual machine hosted on an Elastic Metal server. Do not use this for attaching IP addresses to standard Scaleway resources, as it will fail - instead, see the relevant product API for an equivalent method.
:return: :class:`IP <IP>`

Usage:
Expand Down Expand Up @@ -426,7 +428,7 @@ async def attach_ip(
) -> IP:
"""
Attach existing IP to custom resource.
Attach an existing IP from a Private Network subnet to a custom, named resource via its MAC address. An example of a custom resource is a virtual machine hosted on an Elastic Metal server, or an additional user network interface on an Instance. Do not use this method for attaching IP addresses to standard Scaleway resources as it will fail - see the relevant product API for an equivalent method.
Attach an existing IP from a Private Network subnet to a custom, named resource via its MAC address. An example of a custom resource is a virtual machine hosted on an Elastic Metal server. Do not use this method for attaching IP addresses to standard Scaleway resources as it will fail - see the relevant product API for an equivalent method.
:param ip_id: IP ID.
:param resource: Custom resource to be attached to the IP.
:param region: Region to target. If none is passed will use default region from the config.
Expand Down Expand Up @@ -466,12 +468,14 @@ async def detach_ip(
self,
*,
ip_id: str,
resource: CustomResource,
region: Optional[Region] = None,
) -> IP:
"""
Detach existing IP from a custom resource.
Detach a private IP from a custom resource. An example of a custom resource is a virtual machine hosted on an Elastic Metal server. Do not use this method for attaching IP addresses to standard Scaleway resources (e.g. Instances, Load Balancers) as it will fail - see the relevant product API for an equivalent method.
:param ip_id: IP ID.
:param resource: Custom resource currently attached to the IP.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`IP <IP>`

Expand All @@ -480,6 +484,7 @@ async def detach_ip(

result = await api.detach_ip(
ip_id="example",
resource=CustomResource(),
)
"""

Expand All @@ -491,7 +496,14 @@ async def detach_ip(
res = self._request(
"POST",
f"/ipam/v1/regions/{param_region}/ips/{param_ip_id}/detach",
body={},
body=marshal_DetachIPRequest(
DetachIPRequest(
ip_id=ip_id,
resource=resource,
region=region,
),
self.client,
),
)

self._throw_on_error(res)
Expand All @@ -501,22 +513,25 @@ async def move_ip(
self,
*,
ip_id: str,
from_resource: CustomResource,
region: Optional[Region] = None,
resource: Optional[CustomResource] = None,
to_resource: Optional[CustomResource] = None,
) -> IP:
"""
Move existing IP to a custom resource.
Move an existing private IP from one custom resource (e.g. a virtual machine hosted on an Elastic Metal server) to another custom resource. This will detach it from the first resource, and attach it to the second. Do not use this method for moving IP addresses between standard Scaleway resources (e.g. Instances, Load Balancers) as it will fail - see the relevant product API for an equivalent method.
:param ip_id: IP ID.
:param from_resource: Custom resource currently attached to the IP.
:param region: Region to target. If none is passed will use default region from the config.
:param resource: Custom resource to be attached to the IP.
:param to_resource: Custom resource to be attached to the IP.
:return: :class:`IP <IP>`

Usage:
::

result = await api.move_ip(
ip_id="example",
from_resource=CustomResource(),
)
"""

Expand All @@ -531,8 +546,9 @@ async def move_ip(
body=marshal_MoveIPRequest(
MoveIPRequest(
ip_id=ip_id,
from_resource=from_resource,
region=region,
resource=resource,
to_resource=to_resource,
),
self.client,
),
Expand Down
22 changes: 20 additions & 2 deletions scaleway-async/scaleway_async/ipam/v1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
CustomResource,
AttachIPRequest,
BookIPRequest,
DetachIPRequest,
MoveIPRequest,
ReleaseIPSetRequest,
UpdateIPRequest,
Expand Down Expand Up @@ -267,8 +268,8 @@ def marshal_BookIPRequest(
return output


def marshal_MoveIPRequest(
request: MoveIPRequest,
def marshal_DetachIPRequest(
request: DetachIPRequest,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}
Expand All @@ -279,6 +280,23 @@ def marshal_MoveIPRequest(
return output


def marshal_MoveIPRequest(
request: MoveIPRequest,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}

if request.from_resource is not None:
output["from_resource"] = marshal_CustomResource(
request.from_resource, defaults
)

if request.to_resource is not None:
output["to_resource"] = marshal_CustomResource(request.to_resource, defaults)

return output


def marshal_ReleaseIPSetRequest(
request: ReleaseIPSetRequest,
defaults: ProfileDefaults,
Expand Down
14 changes: 12 additions & 2 deletions scaleway-async/scaleway_async/ipam/v1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class BookIPRequest:

resource: Optional[CustomResource]
"""
Custom resource to attach to the IP being booked. An example of a custom resource is a virtual machine hosted on an Elastic Metal server, or an additional user network interface on an Instance. Do not use this for attaching IP addresses to standard Scaleway resources, as it will fail - instead, see the relevant product API for an equivalent method.
Custom resource to attach to the IP being booked. An example of a custom resource is a virtual machine hosted on an Elastic Metal server. Do not use this for attaching IP addresses to standard Scaleway resources, as it will fail - instead, see the relevant product API for an equivalent method.
"""


Expand All @@ -234,6 +234,11 @@ class DetachIPRequest:
IP ID.
"""

resource: CustomResource
"""
Custom resource currently attached to the IP.
"""

region: Optional[Region]
"""
Region to target. If none is passed will use default region from the config.
Expand Down Expand Up @@ -351,12 +356,17 @@ class MoveIPRequest:
IP ID.
"""

from_resource: CustomResource
"""
Custom resource currently attached to the IP.
"""

region: Optional[Region]
"""
Region to target. If none is passed will use default region from the config.
"""

resource: Optional[CustomResource]
to_resource: Optional[CustomResource]
"""
Custom resource to be attached to the IP.
"""
Expand Down
28 changes: 22 additions & 6 deletions scaleway/scaleway/ipam/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
AttachIPRequest,
BookIPRequest,
CustomResource,
DetachIPRequest,
IP,
ListIPsResponse,
MoveIPRequest,
Expand All @@ -32,6 +33,7 @@
unmarshal_ListIPsResponse,
marshal_AttachIPRequest,
marshal_BookIPRequest,
marshal_DetachIPRequest,
marshal_MoveIPRequest,
marshal_ReleaseIPSetRequest,
marshal_UpdateIPRequest,
Expand Down Expand Up @@ -63,7 +65,7 @@ def book_ip(
:param project_id: When creating an IP in a Private Network, the Project must match the Private Network's Project.
:param address: The requested address should not include the subnet mask (/suffix). Note that only the Private Network source allows you to pick a specific IP. If the requested IP is already booked, then the call will fail.
:param tags: Tags for the IP.
:param resource: Custom resource to attach to the IP being booked. An example of a custom resource is a virtual machine hosted on an Elastic Metal server, or an additional user network interface on an Instance. Do not use this for attaching IP addresses to standard Scaleway resources, as it will fail - instead, see the relevant product API for an equivalent method.
:param resource: Custom resource to attach to the IP being booked. An example of a custom resource is a virtual machine hosted on an Elastic Metal server. Do not use this for attaching IP addresses to standard Scaleway resources, as it will fail - instead, see the relevant product API for an equivalent method.
:return: :class:`IP <IP>`

Usage:
Expand Down Expand Up @@ -426,7 +428,7 @@ def attach_ip(
) -> IP:
"""
Attach existing IP to custom resource.
Attach an existing IP from a Private Network subnet to a custom, named resource via its MAC address. An example of a custom resource is a virtual machine hosted on an Elastic Metal server, or an additional user network interface on an Instance. Do not use this method for attaching IP addresses to standard Scaleway resources as it will fail - see the relevant product API for an equivalent method.
Attach an existing IP from a Private Network subnet to a custom, named resource via its MAC address. An example of a custom resource is a virtual machine hosted on an Elastic Metal server. Do not use this method for attaching IP addresses to standard Scaleway resources as it will fail - see the relevant product API for an equivalent method.
:param ip_id: IP ID.
:param resource: Custom resource to be attached to the IP.
:param region: Region to target. If none is passed will use default region from the config.
Expand Down Expand Up @@ -466,12 +468,14 @@ def detach_ip(
self,
*,
ip_id: str,
resource: CustomResource,
region: Optional[Region] = None,
) -> IP:
"""
Detach existing IP from a custom resource.
Detach a private IP from a custom resource. An example of a custom resource is a virtual machine hosted on an Elastic Metal server. Do not use this method for attaching IP addresses to standard Scaleway resources (e.g. Instances, Load Balancers) as it will fail - see the relevant product API for an equivalent method.
:param ip_id: IP ID.
:param resource: Custom resource currently attached to the IP.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`IP <IP>`

Expand All @@ -480,6 +484,7 @@ def detach_ip(

result = api.detach_ip(
ip_id="example",
resource=CustomResource(),
)
"""

Expand All @@ -491,7 +496,14 @@ def detach_ip(
res = self._request(
"POST",
f"/ipam/v1/regions/{param_region}/ips/{param_ip_id}/detach",
body={},
body=marshal_DetachIPRequest(
DetachIPRequest(
ip_id=ip_id,
resource=resource,
region=region,
),
self.client,
),
)

self._throw_on_error(res)
Expand All @@ -501,22 +513,25 @@ def move_ip(
self,
*,
ip_id: str,
from_resource: CustomResource,
region: Optional[Region] = None,
resource: Optional[CustomResource] = None,
to_resource: Optional[CustomResource] = None,
) -> IP:
"""
Move existing IP to a custom resource.
Move an existing private IP from one custom resource (e.g. a virtual machine hosted on an Elastic Metal server) to another custom resource. This will detach it from the first resource, and attach it to the second. Do not use this method for moving IP addresses between standard Scaleway resources (e.g. Instances, Load Balancers) as it will fail - see the relevant product API for an equivalent method.
:param ip_id: IP ID.
:param from_resource: Custom resource currently attached to the IP.
:param region: Region to target. If none is passed will use default region from the config.
:param resource: Custom resource to be attached to the IP.
:param to_resource: Custom resource to be attached to the IP.
:return: :class:`IP <IP>`

Usage:
::

result = api.move_ip(
ip_id="example",
from_resource=CustomResource(),
)
"""

Expand All @@ -531,8 +546,9 @@ def move_ip(
body=marshal_MoveIPRequest(
MoveIPRequest(
ip_id=ip_id,
from_resource=from_resource,
region=region,
resource=resource,
to_resource=to_resource,
),
self.client,
),
Expand Down
22 changes: 20 additions & 2 deletions scaleway/scaleway/ipam/v1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
CustomResource,
AttachIPRequest,
BookIPRequest,
DetachIPRequest,
MoveIPRequest,
ReleaseIPSetRequest,
UpdateIPRequest,
Expand Down Expand Up @@ -267,8 +268,8 @@ def marshal_BookIPRequest(
return output


def marshal_MoveIPRequest(
request: MoveIPRequest,
def marshal_DetachIPRequest(
request: DetachIPRequest,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}
Expand All @@ -279,6 +280,23 @@ def marshal_MoveIPRequest(
return output


def marshal_MoveIPRequest(
request: MoveIPRequest,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}

if request.from_resource is not None:
output["from_resource"] = marshal_CustomResource(
request.from_resource, defaults
)

if request.to_resource is not None:
output["to_resource"] = marshal_CustomResource(request.to_resource, defaults)

return output


def marshal_ReleaseIPSetRequest(
request: ReleaseIPSetRequest,
defaults: ProfileDefaults,
Expand Down
14 changes: 12 additions & 2 deletions scaleway/scaleway/ipam/v1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class BookIPRequest:

resource: Optional[CustomResource]
"""
Custom resource to attach to the IP being booked. An example of a custom resource is a virtual machine hosted on an Elastic Metal server, or an additional user network interface on an Instance. Do not use this for attaching IP addresses to standard Scaleway resources, as it will fail - instead, see the relevant product API for an equivalent method.
Custom resource to attach to the IP being booked. An example of a custom resource is a virtual machine hosted on an Elastic Metal server. Do not use this for attaching IP addresses to standard Scaleway resources, as it will fail - instead, see the relevant product API for an equivalent method.
"""


Expand All @@ -234,6 +234,11 @@ class DetachIPRequest:
IP ID.
"""

resource: CustomResource
"""
Custom resource currently attached to the IP.
"""

region: Optional[Region]
"""
Region to target. If none is passed will use default region from the config.
Expand Down Expand Up @@ -351,12 +356,17 @@ class MoveIPRequest:
IP ID.
"""

from_resource: CustomResource
"""
Custom resource currently attached to the IP.
"""

region: Optional[Region]
"""
Region to target. If none is passed will use default region from the config.
"""

resource: Optional[CustomResource]
to_resource: Optional[CustomResource]
"""
Custom resource to be attached to the IP.
"""
Expand Down