Skip to content

Commit fc914d1

Browse files
feat(interlink): add support for SetRoutingPolicy (#2715)
Co-authored-by: Rémy Léone <[email protected]>
1 parent 9294f11 commit fc914d1

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

api/interlink/v1beta1/interlink_sdk.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const (
4545
BgpStatusUnknownBgpStatus = BgpStatus("unknown_bgp_status")
4646
BgpStatusUp = BgpStatus("up")
4747
BgpStatusDown = BgpStatus("down")
48+
BgpStatusDisabled = BgpStatus("disabled")
4849
)
4950

5051
func (enum BgpStatus) String() string {
@@ -60,6 +61,7 @@ func (enum BgpStatus) Values() []BgpStatus {
6061
"unknown_bgp_status",
6162
"up",
6263
"down",
64+
"disabled",
6365
}
6466
}
6567

@@ -180,6 +182,7 @@ const (
180182
LinkStatusDeprovisioning = LinkStatus("deprovisioning")
181183
LinkStatusDeleted = LinkStatus("deleted")
182184
LinkStatusLocked = LinkStatus("locked")
185+
LinkStatusReady = LinkStatus("ready")
183186
)
184187

185188
func (enum LinkStatus) String() string {
@@ -205,6 +208,7 @@ func (enum LinkStatus) Values() []LinkStatus {
205208
"deprovisioning",
206209
"deleted",
207210
"locked",
211+
"ready",
208212
}
209213
}
210214

@@ -726,6 +730,12 @@ type CreateLinkRequest struct {
726730

727731
// 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.
728732
Vlan *uint32 `json:"vlan,omitempty"`
733+
734+
// RoutingPolicyV4ID: if set, attaches this routing policy containing IPv4 prefixes to the Link. Hence, a BGP IPv4 session will be created.
735+
RoutingPolicyV4ID *string `json:"routing_policy_v4_id,omitempty"`
736+
737+
// RoutingPolicyV6ID: if set, attaches this routing policy containing IPv6 prefixes to the Link. Hence, a BGP IPv6 session will be created.
738+
RoutingPolicyV6ID *string `json:"routing_policy_v6_id,omitempty"`
729739
}
730740

731741
// CreateRoutingPolicyRequest: create routing policy request.
@@ -1176,6 +1186,18 @@ func (r *ListRoutingPoliciesResponse) UnsafeAppend(res any) (uint64, error) {
11761186
return uint64(len(results.RoutingPolicies)), nil
11771187
}
11781188

1189+
// SetRoutingPolicyRequest: set routing policy request.
1190+
type SetRoutingPolicyRequest struct {
1191+
// Region: region to target. If none is passed will use default region from the config.
1192+
Region scw.Region `json:"-"`
1193+
1194+
// LinkID: ID of the link to set a routing policy from.
1195+
LinkID string `json:"-"`
1196+
1197+
// RoutingPolicyID: ID of the routing policy to be set.
1198+
RoutingPolicyID string `json:"routing_policy_id"`
1199+
}
1200+
11791201
// UpdateLinkRequest: update link request.
11801202
type UpdateLinkRequest struct {
11811203
// Region: region to target. If none is passed will use default region from the config.
@@ -1783,6 +1805,42 @@ func (s *API) DetachRoutingPolicy(req *DetachRoutingPolicyRequest, opts ...scw.R
17831805
return &resp, nil
17841806
}
17851807

1808+
// SetRoutingPolicy: Replace a routing policy from an existing link. This is useful when route propagation is enabled because it changes the routing policy "in place", without blocking all routes like a attach / detach would do.
1809+
func (s *API) SetRoutingPolicy(req *SetRoutingPolicyRequest, opts ...scw.RequestOption) (*Link, error) {
1810+
var err error
1811+
1812+
if req.Region == "" {
1813+
defaultRegion, _ := s.client.GetDefaultRegion()
1814+
req.Region = defaultRegion
1815+
}
1816+
1817+
if fmt.Sprint(req.Region) == "" {
1818+
return nil, errors.New("field Region cannot be empty in request")
1819+
}
1820+
1821+
if fmt.Sprint(req.LinkID) == "" {
1822+
return nil, errors.New("field LinkID cannot be empty in request")
1823+
}
1824+
1825+
scwReq := &scw.ScalewayRequest{
1826+
Method: "POST",
1827+
Path: "/interlink/v1beta1/regions/" + fmt.Sprint(req.Region) + "/links/" + fmt.Sprint(req.LinkID) + "/set-routing-policy",
1828+
}
1829+
1830+
err = scwReq.SetBody(req)
1831+
if err != nil {
1832+
return nil, err
1833+
}
1834+
1835+
var resp Link
1836+
1837+
err = s.client.Do(scwReq, &resp, opts...)
1838+
if err != nil {
1839+
return nil, err
1840+
}
1841+
return &resp, nil
1842+
}
1843+
17861844
// EnableRoutePropagation: Enable all allowed prefixes (defined in a routing policy) to be announced in the BGP session. This allows traffic to flow between the attached VPC and the on-premises infrastructure along the announced routes. Note that by default, even when route propagation is enabled, all routes are blocked. It is essential to attach a routing policy to define the ranges of routes to announce.
17871845
func (s *API) EnableRoutePropagation(req *EnableRoutePropagationRequest, opts ...scw.RequestOption) (*Link, error) {
17881846
var err error

0 commit comments

Comments
 (0)