Skip to content

feat(vpc_gw): introduce idempotent call to migrate PGWs to IPMob #440

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
Feb 16, 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
30 changes: 30 additions & 0 deletions scaleway-async/scaleway_async/vpcgw/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,36 @@ async def upgrade_gateway(
self._throw_on_error(res)
return unmarshal_Gateway(res.json())

async def enable_ip_mobility(
self,
*,
gateway_id: str,
zone: Optional[Zone] = None,
) -> Gateway:
"""
Upgrade a Public Gateway to IP mobility.
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.
:param zone: Zone to target. If none is passed will use default zone from the config.
:param gateway_id: ID of the gateway to upgrade to IP mobility.
:return: :class:`Gateway <Gateway>`

Usage:
::

result = await api.enable_ip_mobility(gateway_id="example")
"""

param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_gateway_id = validate_path_param("gateway_id", gateway_id)

res = self._request(
"POST",
f"/vpc-gw/v1/zones/{param_zone}/gateways/{param_gateway_id}/enable-ip-mobility",
)

self._throw_on_error(res)
return unmarshal_Gateway(res.json())

async def list_gateway_networks(
self,
*,
Expand Down
35 changes: 22 additions & 13 deletions scaleway-async/scaleway_async/vpcgw/v1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ def unmarshal_Gateway(data: Any) -> Gateway:
field = data.get("ip", None)
args["ip"] = unmarshal_IP(field) if field is not None else None

field = data.get("ip_mobility_enabled", None)
args["ip_mobility_enabled"] = field

field = data.get("is_legacy", None)
args["is_legacy"] = field

Expand Down Expand Up @@ -697,20 +700,24 @@ def marshal_CreateGatewayNetworkRequest(
),
OneOfPossibility(
"dhcp",
marshal_CreateDHCPRequest(request.dhcp, defaults)
if request.dhcp is not None
else None,
(
marshal_CreateDHCPRequest(request.dhcp, defaults)
if request.dhcp is not None
else None
),
),
OneOfPossibility(
"address", request.address if request.address is not None else None
),
OneOfPossibility(
"ipam_config",
marshal_CreateGatewayNetworkRequestIpamConfig(
request.ipam_config, defaults
)
if request.ipam_config is not None
else None,
(
marshal_CreateGatewayNetworkRequestIpamConfig(
request.ipam_config, defaults
)
if request.ipam_config is not None
else None
),
),
]
),
Expand Down Expand Up @@ -917,11 +924,13 @@ def marshal_UpdateGatewayNetworkRequest(
),
OneOfPossibility(
"ipam_config",
marshal_UpdateGatewayNetworkRequestIpamConfig(
request.ipam_config, defaults
)
if request.ipam_config is not None
else None,
(
marshal_UpdateGatewayNetworkRequestIpamConfig(
request.ipam_config, defaults
)
if request.ipam_config is not None
else None
),
),
]
),
Expand Down
20 changes: 19 additions & 1 deletion scaleway-async/scaleway_async/vpcgw/v1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,12 @@ class Gateway:

is_legacy: bool
"""
Whether this uses non-IPAM IP configurations.
Defines whether the gateway uses non-IPAM IP configurations.
"""

ip_mobility_enabled: bool
"""
Defines whether the gateway uses routed IPs (IP mobility) instead of NAT IPs.
"""

zone: Zone
Expand Down Expand Up @@ -1023,6 +1028,19 @@ class UpgradeGatewayRequest:
"""


@dataclass
class EnableIPMobilityRequest:
zone: Optional[Zone]
"""
Zone to target. If none is passed will use default zone from the config.
"""

gateway_id: str
"""
ID of the gateway to upgrade to IP mobility.
"""


@dataclass
class ListGatewayNetworksRequest:
zone: Optional[Zone]
Expand Down
30 changes: 30 additions & 0 deletions scaleway/scaleway/vpcgw/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,36 @@ def upgrade_gateway(
self._throw_on_error(res)
return unmarshal_Gateway(res.json())

def enable_ip_mobility(
self,
*,
gateway_id: str,
zone: Optional[Zone] = None,
) -> Gateway:
"""
Upgrade a Public Gateway to IP mobility.
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.
:param zone: Zone to target. If none is passed will use default zone from the config.
:param gateway_id: ID of the gateway to upgrade to IP mobility.
:return: :class:`Gateway <Gateway>`

Usage:
::

result = api.enable_ip_mobility(gateway_id="example")
"""

param_zone = validate_path_param("zone", zone or self.client.default_zone)
param_gateway_id = validate_path_param("gateway_id", gateway_id)

res = self._request(
"POST",
f"/vpc-gw/v1/zones/{param_zone}/gateways/{param_gateway_id}/enable-ip-mobility",
)

self._throw_on_error(res)
return unmarshal_Gateway(res.json())

def list_gateway_networks(
self,
*,
Expand Down
35 changes: 22 additions & 13 deletions scaleway/scaleway/vpcgw/v1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ def unmarshal_Gateway(data: Any) -> Gateway:
field = data.get("ip", None)
args["ip"] = unmarshal_IP(field) if field is not None else None

field = data.get("ip_mobility_enabled", None)
args["ip_mobility_enabled"] = field

field = data.get("is_legacy", None)
args["is_legacy"] = field

Expand Down Expand Up @@ -697,20 +700,24 @@ def marshal_CreateGatewayNetworkRequest(
),
OneOfPossibility(
"dhcp",
marshal_CreateDHCPRequest(request.dhcp, defaults)
if request.dhcp is not None
else None,
(
marshal_CreateDHCPRequest(request.dhcp, defaults)
if request.dhcp is not None
else None
),
),
OneOfPossibility(
"address", request.address if request.address is not None else None
),
OneOfPossibility(
"ipam_config",
marshal_CreateGatewayNetworkRequestIpamConfig(
request.ipam_config, defaults
)
if request.ipam_config is not None
else None,
(
marshal_CreateGatewayNetworkRequestIpamConfig(
request.ipam_config, defaults
)
if request.ipam_config is not None
else None
),
),
]
),
Expand Down Expand Up @@ -917,11 +924,13 @@ def marshal_UpdateGatewayNetworkRequest(
),
OneOfPossibility(
"ipam_config",
marshal_UpdateGatewayNetworkRequestIpamConfig(
request.ipam_config, defaults
)
if request.ipam_config is not None
else None,
(
marshal_UpdateGatewayNetworkRequestIpamConfig(
request.ipam_config, defaults
)
if request.ipam_config is not None
else None
),
),
]
),
Expand Down
20 changes: 19 additions & 1 deletion scaleway/scaleway/vpcgw/v1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,12 @@ class Gateway:

is_legacy: bool
"""
Whether this uses non-IPAM IP configurations.
Defines whether the gateway uses non-IPAM IP configurations.
"""

ip_mobility_enabled: bool
"""
Defines whether the gateway uses routed IPs (IP mobility) instead of NAT IPs.
"""

zone: Zone
Expand Down Expand Up @@ -1023,6 +1028,19 @@ class UpgradeGatewayRequest:
"""


@dataclass
class EnableIPMobilityRequest:
zone: Optional[Zone]
"""
Zone to target. If none is passed will use default zone from the config.
"""

gateway_id: str
"""
ID of the gateway to upgrade to IP mobility.
"""


@dataclass
class ListGatewayNetworksRequest:
zone: Optional[Zone]
Expand Down