Skip to content

Commit 4e97e70

Browse files
authored
feat(vpc/v2): allow routing activation on existing VPCs (#2045)
1 parent 287e07c commit 4e97e70

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

api/vpc/v2/vpc_sdk.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,14 @@ type EnableDHCPRequest struct {
394394
PrivateNetworkID string `json:"-"`
395395
}
396396

397+
// EnableRoutingRequest: enable routing request.
398+
type EnableRoutingRequest struct {
399+
// Region: region to target. If none is passed will use default region from the config.
400+
Region scw.Region `json:"-"`
401+
402+
VpcID string `json:"-"`
403+
}
404+
397405
// GetPrivateNetworkRequest: get private network request.
398406
type GetPrivateNetworkRequest struct {
399407
// Region: region to target. If none is passed will use default region from the config.
@@ -1119,6 +1127,42 @@ func (s *API) EnableDHCP(req *EnableDHCPRequest, opts ...scw.RequestOption) (*Pr
11191127
return &resp, nil
11201128
}
11211129

1130+
// EnableRouting: Enable routing on an existing VPC. Note that you will not be able to deactivate it afterwards.
1131+
func (s *API) EnableRouting(req *EnableRoutingRequest, opts ...scw.RequestOption) (*VPC, error) {
1132+
var err error
1133+
1134+
if req.Region == "" {
1135+
defaultRegion, _ := s.client.GetDefaultRegion()
1136+
req.Region = defaultRegion
1137+
}
1138+
1139+
if fmt.Sprint(req.Region) == "" {
1140+
return nil, errors.New("field Region cannot be empty in request")
1141+
}
1142+
1143+
if fmt.Sprint(req.VpcID) == "" {
1144+
return nil, errors.New("field VpcID cannot be empty in request")
1145+
}
1146+
1147+
scwReq := &scw.ScalewayRequest{
1148+
Method: "POST",
1149+
Path: "/vpc/v2/regions/" + fmt.Sprint(req.Region) + "/vpcs/" + fmt.Sprint(req.VpcID) + "/enable-routing",
1150+
}
1151+
1152+
err = scwReq.SetBody(req)
1153+
if err != nil {
1154+
return nil, err
1155+
}
1156+
1157+
var resp VPC
1158+
1159+
err = s.client.Do(scwReq, &resp, opts...)
1160+
if err != nil {
1161+
return nil, err
1162+
}
1163+
return &resp, nil
1164+
}
1165+
11221166
// SetSubnets: Set subnets for an existing Private Network. Note that the method is PUT and not PATCH. Any existing subnets will be removed in favor of the new specified set of subnets.
11231167
func (s *API) SetSubnets(req *SetSubnetsRequest, opts ...scw.RequestOption) (*SetSubnetsResponse, error) {
11241168
var err error

0 commit comments

Comments
 (0)