Skip to content

Commit a063163

Browse files
authored
feat(interlink): add support for SetRoutingPolicyRequest (#1231)
1 parent 89ab4ea commit a063163

File tree

8 files changed

+208
-0
lines changed

8 files changed

+208
-0
lines changed

scaleway-async/scaleway_async/interlink/v1beta1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from .types import ListPopsResponse
4545
from .types import ListRoutingPoliciesRequest
4646
from .types import ListRoutingPoliciesResponse
47+
from .types import SetRoutingPolicyRequest
4748
from .types import UpdateLinkRequest
4849
from .types import UpdateRoutingPolicyRequest
4950
from .api import InterlinkV1Beta1API
@@ -93,6 +94,7 @@
9394
"ListPopsResponse",
9495
"ListRoutingPoliciesRequest",
9596
"ListRoutingPoliciesResponse",
97+
"SetRoutingPolicyRequest",
9698
"UpdateLinkRequest",
9799
"UpdateRoutingPolicyRequest",
98100
"InterlinkV1Beta1API",

scaleway-async/scaleway_async/interlink/v1beta1/api.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
Partner,
3939
Pop,
4040
RoutingPolicy,
41+
SetRoutingPolicyRequest,
4142
UpdateLinkRequest,
4243
UpdateRoutingPolicyRequest,
4344
)
@@ -61,6 +62,7 @@
6162
marshal_CreateLinkRequest,
6263
marshal_CreateRoutingPolicyRequest,
6364
marshal_DetachRoutingPolicyRequest,
65+
marshal_SetRoutingPolicyRequest,
6466
marshal_UpdateLinkRequest,
6567
marshal_UpdateRoutingPolicyRequest,
6668
)
@@ -768,6 +770,8 @@ async def create_link(
768770
partner_id: Optional[str] = None,
769771
peer_asn: Optional[int] = None,
770772
vlan: Optional[int] = None,
773+
routing_policy_v4_id: Optional[str] = None,
774+
routing_policy_v6_id: Optional[str] = None,
771775
) -> Link:
772776
"""
773777
Create a link.
@@ -784,6 +788,8 @@ async def create_link(
784788
One-Of ('host'): at most one of 'connection_id', 'partner_id' could be set.
785789
:param peer_asn: For self-hosted links we need the peer AS Number to establish BGP session. If not given, a default one will be assigned.
786790
:param vlan: For self-hosted links only, it is possible to choose the VLAN ID. If the VLAN is not available (ie already taken or out of range), an error is returned.
791+
:param routing_policy_v4_id: If set, attaches this routing policy containing IPv4 prefixes to the Link. Hence, a BGP IPv4 session will be created.
792+
:param routing_policy_v6_id: If set, attaches this routing policy containing IPv6 prefixes to the Link. Hence, a BGP IPv6 session will be created.
787793
:return: :class:`Link <Link>`
788794
789795
Usage:
@@ -813,6 +819,8 @@ async def create_link(
813819
tags=tags,
814820
peer_asn=peer_asn,
815821
vlan=vlan,
822+
routing_policy_v4_id=routing_policy_v4_id,
823+
routing_policy_v6_id=routing_policy_v6_id,
816824
connection_id=connection_id,
817825
partner_id=partner_id,
818826
),
@@ -1077,6 +1085,51 @@ async def detach_routing_policy(
10771085
self._throw_on_error(res)
10781086
return unmarshal_Link(res.json())
10791087

1088+
async def set_routing_policy(
1089+
self,
1090+
*,
1091+
link_id: str,
1092+
routing_policy_id: str,
1093+
region: Optional[ScwRegion] = None,
1094+
) -> Link:
1095+
"""
1096+
Set a routing policy.
1097+
Replace a routing policy from an existing link. This is usefull when route propagation is enabled because it changes the routing policy "in place", without blocking all routes like a attach / detach would do.
1098+
:param link_id: ID of the link to set a routing policy from.
1099+
:param routing_policy_id: ID of the routing policy to be set.
1100+
:param region: Region to target. If none is passed will use default region from the config.
1101+
:return: :class:`Link <Link>`
1102+
1103+
Usage:
1104+
::
1105+
1106+
result = await api.set_routing_policy(
1107+
link_id="example",
1108+
routing_policy_id="example",
1109+
)
1110+
"""
1111+
1112+
param_region = validate_path_param(
1113+
"region", region or self.client.default_region
1114+
)
1115+
param_link_id = validate_path_param("link_id", link_id)
1116+
1117+
res = self._request(
1118+
"POST",
1119+
f"/interlink/v1beta1/regions/{param_region}/links/{param_link_id}/set-routing-policy",
1120+
body=marshal_SetRoutingPolicyRequest(
1121+
SetRoutingPolicyRequest(
1122+
link_id=link_id,
1123+
routing_policy_id=routing_policy_id,
1124+
region=region,
1125+
),
1126+
self.client,
1127+
),
1128+
)
1129+
1130+
self._throw_on_error(res)
1131+
return unmarshal_Link(res.json())
1132+
10801133
async def enable_route_propagation(
10811134
self,
10821135
*,

scaleway-async/scaleway_async/interlink/v1beta1/marshalling.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
CreateLinkRequest,
3232
CreateRoutingPolicyRequest,
3333
DetachRoutingPolicyRequest,
34+
SetRoutingPolicyRequest,
3435
UpdateLinkRequest,
3536
UpdateRoutingPolicyRequest,
3637
)
@@ -732,6 +733,12 @@ def marshal_CreateLinkRequest(
732733
if request.vlan is not None:
733734
output["vlan"] = request.vlan
734735

736+
if request.routing_policy_v4_id is not None:
737+
output["routing_policy_v4_id"] = request.routing_policy_v4_id
738+
739+
if request.routing_policy_v6_id is not None:
740+
output["routing_policy_v6_id"] = request.routing_policy_v6_id
741+
735742
return output
736743

737744

@@ -776,6 +783,18 @@ def marshal_DetachRoutingPolicyRequest(
776783
return output
777784

778785

786+
def marshal_SetRoutingPolicyRequest(
787+
request: SetRoutingPolicyRequest,
788+
defaults: ProfileDefaults,
789+
) -> dict[str, Any]:
790+
output: dict[str, Any] = {}
791+
792+
if request.routing_policy_id is not None:
793+
output["routing_policy_id"] = request.routing_policy_id
794+
795+
return output
796+
797+
779798
def marshal_UpdateLinkRequest(
780799
request: UpdateLinkRequest,
781800
defaults: ProfileDefaults,

scaleway-async/scaleway_async/interlink/v1beta1/types.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class BgpStatus(str, Enum, metaclass=StrEnumMeta):
1919
UNKNOWN_BGP_STATUS = "unknown_bgp_status"
2020
UP = "up"
2121
DOWN = "down"
22+
DISABLED = "disabled"
2223

2324
def __str__(self) -> str:
2425
return str(self.value)
@@ -60,6 +61,7 @@ class LinkStatus(str, Enum, metaclass=StrEnumMeta):
6061
DEPROVISIONING = "deprovisioning"
6162
DELETED = "deleted"
6263
LOCKED = "locked"
64+
READY = "ready"
6365

6466
def __str__(self) -> str:
6567
return str(self.value)
@@ -558,6 +560,16 @@ class CreateLinkRequest:
558560
For self-hosted links only, it is possible to choose the VLAN ID. If the VLAN is not available (ie already taken or out of range), an error is returned.
559561
"""
560562

563+
routing_policy_v4_id: Optional[str] = None
564+
"""
565+
If set, attaches this routing policy containing IPv4 prefixes to the Link. Hence, a BGP IPv4 session will be created.
566+
"""
567+
568+
routing_policy_v6_id: Optional[str] = None
569+
"""
570+
If set, attaches this routing policy containing IPv6 prefixes to the Link. Hence, a BGP IPv6 session will be created.
571+
"""
572+
561573
connection_id: Optional[str] = None
562574

563575
partner_id: Optional[str] = None
@@ -1093,6 +1105,24 @@ class ListRoutingPoliciesResponse:
10931105
total_count: int
10941106

10951107

1108+
@dataclass
1109+
class SetRoutingPolicyRequest:
1110+
link_id: str
1111+
"""
1112+
ID of the link to set a routing policy from.
1113+
"""
1114+
1115+
routing_policy_id: str
1116+
"""
1117+
ID of the routing policy to be set.
1118+
"""
1119+
1120+
region: Optional[ScwRegion] = None
1121+
"""
1122+
Region to target. If none is passed will use default region from the config.
1123+
"""
1124+
1125+
10961126
@dataclass
10971127
class UpdateLinkRequest:
10981128
link_id: str

scaleway/scaleway/interlink/v1beta1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from .types import ListPopsResponse
4545
from .types import ListRoutingPoliciesRequest
4646
from .types import ListRoutingPoliciesResponse
47+
from .types import SetRoutingPolicyRequest
4748
from .types import UpdateLinkRequest
4849
from .types import UpdateRoutingPolicyRequest
4950
from .api import InterlinkV1Beta1API
@@ -93,6 +94,7 @@
9394
"ListPopsResponse",
9495
"ListRoutingPoliciesRequest",
9596
"ListRoutingPoliciesResponse",
97+
"SetRoutingPolicyRequest",
9698
"UpdateLinkRequest",
9799
"UpdateRoutingPolicyRequest",
98100
"InterlinkV1Beta1API",

scaleway/scaleway/interlink/v1beta1/api.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
Partner,
3939
Pop,
4040
RoutingPolicy,
41+
SetRoutingPolicyRequest,
4142
UpdateLinkRequest,
4243
UpdateRoutingPolicyRequest,
4344
)
@@ -61,6 +62,7 @@
6162
marshal_CreateLinkRequest,
6263
marshal_CreateRoutingPolicyRequest,
6364
marshal_DetachRoutingPolicyRequest,
65+
marshal_SetRoutingPolicyRequest,
6466
marshal_UpdateLinkRequest,
6567
marshal_UpdateRoutingPolicyRequest,
6668
)
@@ -766,6 +768,8 @@ def create_link(
766768
partner_id: Optional[str] = None,
767769
peer_asn: Optional[int] = None,
768770
vlan: Optional[int] = None,
771+
routing_policy_v4_id: Optional[str] = None,
772+
routing_policy_v6_id: Optional[str] = None,
769773
) -> Link:
770774
"""
771775
Create a link.
@@ -782,6 +786,8 @@ def create_link(
782786
One-Of ('host'): at most one of 'connection_id', 'partner_id' could be set.
783787
:param peer_asn: For self-hosted links we need the peer AS Number to establish BGP session. If not given, a default one will be assigned.
784788
:param vlan: For self-hosted links only, it is possible to choose the VLAN ID. If the VLAN is not available (ie already taken or out of range), an error is returned.
789+
:param routing_policy_v4_id: If set, attaches this routing policy containing IPv4 prefixes to the Link. Hence, a BGP IPv4 session will be created.
790+
:param routing_policy_v6_id: If set, attaches this routing policy containing IPv6 prefixes to the Link. Hence, a BGP IPv6 session will be created.
785791
:return: :class:`Link <Link>`
786792
787793
Usage:
@@ -811,6 +817,8 @@ def create_link(
811817
tags=tags,
812818
peer_asn=peer_asn,
813819
vlan=vlan,
820+
routing_policy_v4_id=routing_policy_v4_id,
821+
routing_policy_v6_id=routing_policy_v6_id,
814822
connection_id=connection_id,
815823
partner_id=partner_id,
816824
),
@@ -1075,6 +1083,51 @@ def detach_routing_policy(
10751083
self._throw_on_error(res)
10761084
return unmarshal_Link(res.json())
10771085

1086+
def set_routing_policy(
1087+
self,
1088+
*,
1089+
link_id: str,
1090+
routing_policy_id: str,
1091+
region: Optional[ScwRegion] = None,
1092+
) -> Link:
1093+
"""
1094+
Set a routing policy.
1095+
Replace a routing policy from an existing link. This is usefull when route propagation is enabled because it changes the routing policy "in place", without blocking all routes like a attach / detach would do.
1096+
:param link_id: ID of the link to set a routing policy from.
1097+
:param routing_policy_id: ID of the routing policy to be set.
1098+
:param region: Region to target. If none is passed will use default region from the config.
1099+
:return: :class:`Link <Link>`
1100+
1101+
Usage:
1102+
::
1103+
1104+
result = api.set_routing_policy(
1105+
link_id="example",
1106+
routing_policy_id="example",
1107+
)
1108+
"""
1109+
1110+
param_region = validate_path_param(
1111+
"region", region or self.client.default_region
1112+
)
1113+
param_link_id = validate_path_param("link_id", link_id)
1114+
1115+
res = self._request(
1116+
"POST",
1117+
f"/interlink/v1beta1/regions/{param_region}/links/{param_link_id}/set-routing-policy",
1118+
body=marshal_SetRoutingPolicyRequest(
1119+
SetRoutingPolicyRequest(
1120+
link_id=link_id,
1121+
routing_policy_id=routing_policy_id,
1122+
region=region,
1123+
),
1124+
self.client,
1125+
),
1126+
)
1127+
1128+
self._throw_on_error(res)
1129+
return unmarshal_Link(res.json())
1130+
10781131
def enable_route_propagation(
10791132
self,
10801133
*,

scaleway/scaleway/interlink/v1beta1/marshalling.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
CreateLinkRequest,
3232
CreateRoutingPolicyRequest,
3333
DetachRoutingPolicyRequest,
34+
SetRoutingPolicyRequest,
3435
UpdateLinkRequest,
3536
UpdateRoutingPolicyRequest,
3637
)
@@ -732,6 +733,12 @@ def marshal_CreateLinkRequest(
732733
if request.vlan is not None:
733734
output["vlan"] = request.vlan
734735

736+
if request.routing_policy_v4_id is not None:
737+
output["routing_policy_v4_id"] = request.routing_policy_v4_id
738+
739+
if request.routing_policy_v6_id is not None:
740+
output["routing_policy_v6_id"] = request.routing_policy_v6_id
741+
735742
return output
736743

737744

@@ -776,6 +783,18 @@ def marshal_DetachRoutingPolicyRequest(
776783
return output
777784

778785

786+
def marshal_SetRoutingPolicyRequest(
787+
request: SetRoutingPolicyRequest,
788+
defaults: ProfileDefaults,
789+
) -> dict[str, Any]:
790+
output: dict[str, Any] = {}
791+
792+
if request.routing_policy_id is not None:
793+
output["routing_policy_id"] = request.routing_policy_id
794+
795+
return output
796+
797+
779798
def marshal_UpdateLinkRequest(
780799
request: UpdateLinkRequest,
781800
defaults: ProfileDefaults,

0 commit comments

Comments
 (0)