Skip to content

Commit e2132a7

Browse files
authored
fix(ipam): make public detach & move ips idempotency (#646)
1 parent be21c2d commit e2132a7

File tree

6 files changed

+108
-20
lines changed

6 files changed

+108
-20
lines changed

scaleway-async/scaleway_async/ipam/v1/api.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
AttachIPRequest,
2020
BookIPRequest,
2121
CustomResource,
22+
DetachIPRequest,
2223
IP,
2324
ListIPsResponse,
2425
MoveIPRequest,
@@ -32,6 +33,7 @@
3233
unmarshal_ListIPsResponse,
3334
marshal_AttachIPRequest,
3435
marshal_BookIPRequest,
36+
marshal_DetachIPRequest,
3537
marshal_MoveIPRequest,
3638
marshal_ReleaseIPSetRequest,
3739
marshal_UpdateIPRequest,
@@ -63,7 +65,7 @@ async def book_ip(
6365
:param project_id: When creating an IP in a Private Network, the Project must match the Private Network's Project.
6466
: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.
6567
:param tags: Tags for the IP.
66-
: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.
68+
: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.
6769
:return: :class:`IP <IP>`
6870
6971
Usage:
@@ -426,7 +428,7 @@ async def attach_ip(
426428
) -> IP:
427429
"""
428430
Attach existing IP to custom resource.
429-
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.
431+
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.
430432
:param ip_id: IP ID.
431433
:param resource: Custom resource to be attached to the IP.
432434
:param region: Region to target. If none is passed will use default region from the config.
@@ -466,12 +468,14 @@ async def detach_ip(
466468
self,
467469
*,
468470
ip_id: str,
471+
resource: CustomResource,
469472
region: Optional[Region] = None,
470473
) -> IP:
471474
"""
472475
Detach existing IP from a custom resource.
473476
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.
474477
:param ip_id: IP ID.
478+
:param resource: Custom resource currently attached to the IP.
475479
:param region: Region to target. If none is passed will use default region from the config.
476480
:return: :class:`IP <IP>`
477481
@@ -480,6 +484,7 @@ async def detach_ip(
480484
481485
result = await api.detach_ip(
482486
ip_id="example",
487+
resource=CustomResource(),
483488
)
484489
"""
485490

@@ -491,7 +496,14 @@ async def detach_ip(
491496
res = self._request(
492497
"POST",
493498
f"/ipam/v1/regions/{param_region}/ips/{param_ip_id}/detach",
494-
body={},
499+
body=marshal_DetachIPRequest(
500+
DetachIPRequest(
501+
ip_id=ip_id,
502+
resource=resource,
503+
region=region,
504+
),
505+
self.client,
506+
),
495507
)
496508

497509
self._throw_on_error(res)
@@ -501,22 +513,25 @@ async def move_ip(
501513
self,
502514
*,
503515
ip_id: str,
516+
from_resource: CustomResource,
504517
region: Optional[Region] = None,
505-
resource: Optional[CustomResource] = None,
518+
to_resource: Optional[CustomResource] = None,
506519
) -> IP:
507520
"""
508521
Move existing IP to a custom resource.
509522
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.
510523
:param ip_id: IP ID.
524+
:param from_resource: Custom resource currently attached to the IP.
511525
:param region: Region to target. If none is passed will use default region from the config.
512-
:param resource: Custom resource to be attached to the IP.
526+
:param to_resource: Custom resource to be attached to the IP.
513527
:return: :class:`IP <IP>`
514528
515529
Usage:
516530
::
517531
518532
result = await api.move_ip(
519533
ip_id="example",
534+
from_resource=CustomResource(),
520535
)
521536
"""
522537

@@ -531,8 +546,9 @@ async def move_ip(
531546
body=marshal_MoveIPRequest(
532547
MoveIPRequest(
533548
ip_id=ip_id,
549+
from_resource=from_resource,
534550
region=region,
535-
resource=resource,
551+
to_resource=to_resource,
536552
),
537553
self.client,
538554
),

scaleway-async/scaleway_async/ipam/v1/marshalling.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
CustomResource,
1919
AttachIPRequest,
2020
BookIPRequest,
21+
DetachIPRequest,
2122
MoveIPRequest,
2223
ReleaseIPSetRequest,
2324
UpdateIPRequest,
@@ -267,8 +268,8 @@ def marshal_BookIPRequest(
267268
return output
268269

269270

270-
def marshal_MoveIPRequest(
271-
request: MoveIPRequest,
271+
def marshal_DetachIPRequest(
272+
request: DetachIPRequest,
272273
defaults: ProfileDefaults,
273274
) -> Dict[str, Any]:
274275
output: Dict[str, Any] = {}
@@ -279,6 +280,23 @@ def marshal_MoveIPRequest(
279280
return output
280281

281282

283+
def marshal_MoveIPRequest(
284+
request: MoveIPRequest,
285+
defaults: ProfileDefaults,
286+
) -> Dict[str, Any]:
287+
output: Dict[str, Any] = {}
288+
289+
if request.from_resource is not None:
290+
output["from_resource"] = marshal_CustomResource(
291+
request.from_resource, defaults
292+
)
293+
294+
if request.to_resource is not None:
295+
output["to_resource"] = marshal_CustomResource(request.to_resource, defaults)
296+
297+
return output
298+
299+
282300
def marshal_ReleaseIPSetRequest(
283301
request: ReleaseIPSetRequest,
284302
defaults: ProfileDefaults,

scaleway-async/scaleway_async/ipam/v1/types.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class BookIPRequest:
223223

224224
resource: Optional[CustomResource]
225225
"""
226-
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.
226+
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.
227227
"""
228228

229229

@@ -234,6 +234,11 @@ class DetachIPRequest:
234234
IP ID.
235235
"""
236236

237+
resource: CustomResource
238+
"""
239+
Custom resource currently attached to the IP.
240+
"""
241+
237242
region: Optional[Region]
238243
"""
239244
Region to target. If none is passed will use default region from the config.
@@ -351,12 +356,17 @@ class MoveIPRequest:
351356
IP ID.
352357
"""
353358

359+
from_resource: CustomResource
360+
"""
361+
Custom resource currently attached to the IP.
362+
"""
363+
354364
region: Optional[Region]
355365
"""
356366
Region to target. If none is passed will use default region from the config.
357367
"""
358368

359-
resource: Optional[CustomResource]
369+
to_resource: Optional[CustomResource]
360370
"""
361371
Custom resource to be attached to the IP.
362372
"""

scaleway/scaleway/ipam/v1/api.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
AttachIPRequest,
2020
BookIPRequest,
2121
CustomResource,
22+
DetachIPRequest,
2223
IP,
2324
ListIPsResponse,
2425
MoveIPRequest,
@@ -32,6 +33,7 @@
3233
unmarshal_ListIPsResponse,
3334
marshal_AttachIPRequest,
3435
marshal_BookIPRequest,
36+
marshal_DetachIPRequest,
3537
marshal_MoveIPRequest,
3638
marshal_ReleaseIPSetRequest,
3739
marshal_UpdateIPRequest,
@@ -63,7 +65,7 @@ def book_ip(
6365
:param project_id: When creating an IP in a Private Network, the Project must match the Private Network's Project.
6466
: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.
6567
:param tags: Tags for the IP.
66-
: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.
68+
: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.
6769
:return: :class:`IP <IP>`
6870
6971
Usage:
@@ -426,7 +428,7 @@ def attach_ip(
426428
) -> IP:
427429
"""
428430
Attach existing IP to custom resource.
429-
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.
431+
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.
430432
:param ip_id: IP ID.
431433
:param resource: Custom resource to be attached to the IP.
432434
:param region: Region to target. If none is passed will use default region from the config.
@@ -466,12 +468,14 @@ def detach_ip(
466468
self,
467469
*,
468470
ip_id: str,
471+
resource: CustomResource,
469472
region: Optional[Region] = None,
470473
) -> IP:
471474
"""
472475
Detach existing IP from a custom resource.
473476
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.
474477
:param ip_id: IP ID.
478+
:param resource: Custom resource currently attached to the IP.
475479
:param region: Region to target. If none is passed will use default region from the config.
476480
:return: :class:`IP <IP>`
477481
@@ -480,6 +484,7 @@ def detach_ip(
480484
481485
result = api.detach_ip(
482486
ip_id="example",
487+
resource=CustomResource(),
483488
)
484489
"""
485490

@@ -491,7 +496,14 @@ def detach_ip(
491496
res = self._request(
492497
"POST",
493498
f"/ipam/v1/regions/{param_region}/ips/{param_ip_id}/detach",
494-
body={},
499+
body=marshal_DetachIPRequest(
500+
DetachIPRequest(
501+
ip_id=ip_id,
502+
resource=resource,
503+
region=region,
504+
),
505+
self.client,
506+
),
495507
)
496508

497509
self._throw_on_error(res)
@@ -501,22 +513,25 @@ def move_ip(
501513
self,
502514
*,
503515
ip_id: str,
516+
from_resource: CustomResource,
504517
region: Optional[Region] = None,
505-
resource: Optional[CustomResource] = None,
518+
to_resource: Optional[CustomResource] = None,
506519
) -> IP:
507520
"""
508521
Move existing IP to a custom resource.
509522
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.
510523
:param ip_id: IP ID.
524+
:param from_resource: Custom resource currently attached to the IP.
511525
:param region: Region to target. If none is passed will use default region from the config.
512-
:param resource: Custom resource to be attached to the IP.
526+
:param to_resource: Custom resource to be attached to the IP.
513527
:return: :class:`IP <IP>`
514528
515529
Usage:
516530
::
517531
518532
result = api.move_ip(
519533
ip_id="example",
534+
from_resource=CustomResource(),
520535
)
521536
"""
522537

@@ -531,8 +546,9 @@ def move_ip(
531546
body=marshal_MoveIPRequest(
532547
MoveIPRequest(
533548
ip_id=ip_id,
549+
from_resource=from_resource,
534550
region=region,
535-
resource=resource,
551+
to_resource=to_resource,
536552
),
537553
self.client,
538554
),

scaleway/scaleway/ipam/v1/marshalling.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
CustomResource,
1919
AttachIPRequest,
2020
BookIPRequest,
21+
DetachIPRequest,
2122
MoveIPRequest,
2223
ReleaseIPSetRequest,
2324
UpdateIPRequest,
@@ -267,8 +268,8 @@ def marshal_BookIPRequest(
267268
return output
268269

269270

270-
def marshal_MoveIPRequest(
271-
request: MoveIPRequest,
271+
def marshal_DetachIPRequest(
272+
request: DetachIPRequest,
272273
defaults: ProfileDefaults,
273274
) -> Dict[str, Any]:
274275
output: Dict[str, Any] = {}
@@ -279,6 +280,23 @@ def marshal_MoveIPRequest(
279280
return output
280281

281282

283+
def marshal_MoveIPRequest(
284+
request: MoveIPRequest,
285+
defaults: ProfileDefaults,
286+
) -> Dict[str, Any]:
287+
output: Dict[str, Any] = {}
288+
289+
if request.from_resource is not None:
290+
output["from_resource"] = marshal_CustomResource(
291+
request.from_resource, defaults
292+
)
293+
294+
if request.to_resource is not None:
295+
output["to_resource"] = marshal_CustomResource(request.to_resource, defaults)
296+
297+
return output
298+
299+
282300
def marshal_ReleaseIPSetRequest(
283301
request: ReleaseIPSetRequest,
284302
defaults: ProfileDefaults,

scaleway/scaleway/ipam/v1/types.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class BookIPRequest:
223223

224224
resource: Optional[CustomResource]
225225
"""
226-
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.
226+
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.
227227
"""
228228

229229

@@ -234,6 +234,11 @@ class DetachIPRequest:
234234
IP ID.
235235
"""
236236

237+
resource: CustomResource
238+
"""
239+
Custom resource currently attached to the IP.
240+
"""
241+
237242
region: Optional[Region]
238243
"""
239244
Region to target. If none is passed will use default region from the config.
@@ -351,12 +356,17 @@ class MoveIPRequest:
351356
IP ID.
352357
"""
353358

359+
from_resource: CustomResource
360+
"""
361+
Custom resource currently attached to the IP.
362+
"""
363+
354364
region: Optional[Region]
355365
"""
356366
Region to target. If none is passed will use default region from the config.
357367
"""
358368

359-
resource: Optional[CustomResource]
369+
to_resource: Optional[CustomResource]
360370
"""
361371
Custom resource to be attached to the IP.
362372
"""

0 commit comments

Comments
 (0)