Skip to content

Commit f9adaf2

Browse files
authored
feat(vpc_gw): introduce idempotent call to migrate PGWs to IPMob (#440)
1 parent 297128b commit f9adaf2

File tree

6 files changed

+142
-28
lines changed

6 files changed

+142
-28
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,36 @@ async def upgrade_gateway(
470470
self._throw_on_error(res)
471471
return unmarshal_Gateway(res.json())
472472

473+
async def enable_ip_mobility(
474+
self,
475+
*,
476+
gateway_id: str,
477+
zone: Optional[Zone] = None,
478+
) -> Gateway:
479+
"""
480+
Upgrade a Public Gateway to IP mobility.
481+
Upgrade a Public Gateway to IP mobility (move from NAT IP to routed IP). This is idempotent: repeated calls after the first will return no error but have no effect.
482+
:param zone: Zone to target. If none is passed will use default zone from the config.
483+
:param gateway_id: ID of the gateway to upgrade to IP mobility.
484+
:return: :class:`Gateway <Gateway>`
485+
486+
Usage:
487+
::
488+
489+
result = await api.enable_ip_mobility(gateway_id="example")
490+
"""
491+
492+
param_zone = validate_path_param("zone", zone or self.client.default_zone)
493+
param_gateway_id = validate_path_param("gateway_id", gateway_id)
494+
495+
res = self._request(
496+
"POST",
497+
f"/vpc-gw/v1/zones/{param_zone}/gateways/{param_gateway_id}/enable-ip-mobility",
498+
)
499+
500+
self._throw_on_error(res)
501+
return unmarshal_Gateway(res.json())
502+
473503
async def list_gateway_networks(
474504
self,
475505
*,

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ def unmarshal_Gateway(data: Any) -> Gateway:
314314
field = data.get("ip", None)
315315
args["ip"] = unmarshal_IP(field) if field is not None else None
316316

317+
field = data.get("ip_mobility_enabled", None)
318+
args["ip_mobility_enabled"] = field
319+
317320
field = data.get("is_legacy", None)
318321
args["is_legacy"] = field
319322

@@ -697,20 +700,24 @@ def marshal_CreateGatewayNetworkRequest(
697700
),
698701
OneOfPossibility(
699702
"dhcp",
700-
marshal_CreateDHCPRequest(request.dhcp, defaults)
701-
if request.dhcp is not None
702-
else None,
703+
(
704+
marshal_CreateDHCPRequest(request.dhcp, defaults)
705+
if request.dhcp is not None
706+
else None
707+
),
703708
),
704709
OneOfPossibility(
705710
"address", request.address if request.address is not None else None
706711
),
707712
OneOfPossibility(
708713
"ipam_config",
709-
marshal_CreateGatewayNetworkRequestIpamConfig(
710-
request.ipam_config, defaults
711-
)
712-
if request.ipam_config is not None
713-
else None,
714+
(
715+
marshal_CreateGatewayNetworkRequestIpamConfig(
716+
request.ipam_config, defaults
717+
)
718+
if request.ipam_config is not None
719+
else None
720+
),
714721
),
715722
]
716723
),
@@ -917,11 +924,13 @@ def marshal_UpdateGatewayNetworkRequest(
917924
),
918925
OneOfPossibility(
919926
"ipam_config",
920-
marshal_UpdateGatewayNetworkRequestIpamConfig(
921-
request.ipam_config, defaults
922-
)
923-
if request.ipam_config is not None
924-
else None,
927+
(
928+
marshal_UpdateGatewayNetworkRequestIpamConfig(
929+
request.ipam_config, defaults
930+
)
931+
if request.ipam_config is not None
932+
else None
933+
),
925934
),
926935
]
927936
),

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,12 @@ class Gateway:
395395

396396
is_legacy: bool
397397
"""
398-
Whether this uses non-IPAM IP configurations.
398+
Defines whether the gateway uses non-IPAM IP configurations.
399+
"""
400+
401+
ip_mobility_enabled: bool
402+
"""
403+
Defines whether the gateway uses routed IPs (IP mobility) instead of NAT IPs.
399404
"""
400405

401406
zone: Zone
@@ -1023,6 +1028,19 @@ class UpgradeGatewayRequest:
10231028
"""
10241029

10251030

1031+
@dataclass
1032+
class EnableIPMobilityRequest:
1033+
zone: Optional[Zone]
1034+
"""
1035+
Zone to target. If none is passed will use default zone from the config.
1036+
"""
1037+
1038+
gateway_id: str
1039+
"""
1040+
ID of the gateway to upgrade to IP mobility.
1041+
"""
1042+
1043+
10261044
@dataclass
10271045
class ListGatewayNetworksRequest:
10281046
zone: Optional[Zone]

scaleway/scaleway/vpcgw/v1/api.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,36 @@ def upgrade_gateway(
470470
self._throw_on_error(res)
471471
return unmarshal_Gateway(res.json())
472472

473+
def enable_ip_mobility(
474+
self,
475+
*,
476+
gateway_id: str,
477+
zone: Optional[Zone] = None,
478+
) -> Gateway:
479+
"""
480+
Upgrade a Public Gateway to IP mobility.
481+
Upgrade a Public Gateway to IP mobility (move from NAT IP to routed IP). This is idempotent: repeated calls after the first will return no error but have no effect.
482+
:param zone: Zone to target. If none is passed will use default zone from the config.
483+
:param gateway_id: ID of the gateway to upgrade to IP mobility.
484+
:return: :class:`Gateway <Gateway>`
485+
486+
Usage:
487+
::
488+
489+
result = api.enable_ip_mobility(gateway_id="example")
490+
"""
491+
492+
param_zone = validate_path_param("zone", zone or self.client.default_zone)
493+
param_gateway_id = validate_path_param("gateway_id", gateway_id)
494+
495+
res = self._request(
496+
"POST",
497+
f"/vpc-gw/v1/zones/{param_zone}/gateways/{param_gateway_id}/enable-ip-mobility",
498+
)
499+
500+
self._throw_on_error(res)
501+
return unmarshal_Gateway(res.json())
502+
473503
def list_gateway_networks(
474504
self,
475505
*,

scaleway/scaleway/vpcgw/v1/marshalling.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ def unmarshal_Gateway(data: Any) -> Gateway:
314314
field = data.get("ip", None)
315315
args["ip"] = unmarshal_IP(field) if field is not None else None
316316

317+
field = data.get("ip_mobility_enabled", None)
318+
args["ip_mobility_enabled"] = field
319+
317320
field = data.get("is_legacy", None)
318321
args["is_legacy"] = field
319322

@@ -697,20 +700,24 @@ def marshal_CreateGatewayNetworkRequest(
697700
),
698701
OneOfPossibility(
699702
"dhcp",
700-
marshal_CreateDHCPRequest(request.dhcp, defaults)
701-
if request.dhcp is not None
702-
else None,
703+
(
704+
marshal_CreateDHCPRequest(request.dhcp, defaults)
705+
if request.dhcp is not None
706+
else None
707+
),
703708
),
704709
OneOfPossibility(
705710
"address", request.address if request.address is not None else None
706711
),
707712
OneOfPossibility(
708713
"ipam_config",
709-
marshal_CreateGatewayNetworkRequestIpamConfig(
710-
request.ipam_config, defaults
711-
)
712-
if request.ipam_config is not None
713-
else None,
714+
(
715+
marshal_CreateGatewayNetworkRequestIpamConfig(
716+
request.ipam_config, defaults
717+
)
718+
if request.ipam_config is not None
719+
else None
720+
),
714721
),
715722
]
716723
),
@@ -917,11 +924,13 @@ def marshal_UpdateGatewayNetworkRequest(
917924
),
918925
OneOfPossibility(
919926
"ipam_config",
920-
marshal_UpdateGatewayNetworkRequestIpamConfig(
921-
request.ipam_config, defaults
922-
)
923-
if request.ipam_config is not None
924-
else None,
927+
(
928+
marshal_UpdateGatewayNetworkRequestIpamConfig(
929+
request.ipam_config, defaults
930+
)
931+
if request.ipam_config is not None
932+
else None
933+
),
925934
),
926935
]
927936
),

scaleway/scaleway/vpcgw/v1/types.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,12 @@ class Gateway:
395395

396396
is_legacy: bool
397397
"""
398-
Whether this uses non-IPAM IP configurations.
398+
Defines whether the gateway uses non-IPAM IP configurations.
399+
"""
400+
401+
ip_mobility_enabled: bool
402+
"""
403+
Defines whether the gateway uses routed IPs (IP mobility) instead of NAT IPs.
399404
"""
400405

401406
zone: Zone
@@ -1023,6 +1028,19 @@ class UpgradeGatewayRequest:
10231028
"""
10241029

10251030

1031+
@dataclass
1032+
class EnableIPMobilityRequest:
1033+
zone: Optional[Zone]
1034+
"""
1035+
Zone to target. If none is passed will use default zone from the config.
1036+
"""
1037+
1038+
gateway_id: str
1039+
"""
1040+
ID of the gateway to upgrade to IP mobility.
1041+
"""
1042+
1043+
10261044
@dataclass
10271045
class ListGatewayNetworksRequest:
10281046
zone: Optional[Zone]

0 commit comments

Comments
 (0)