Skip to content

Commit 5e95833

Browse files
authored
feat(vpc_gw): add a call to migrate a V1 gateway to V2 (scaleway#2427)
1 parent 40ac504 commit 5e95833

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

api/vpcgw/v1/vpcgw_sdk.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,14 @@ func (r *ListPATRulesResponse) UnsafeAppend(res interface{}) (uint32, error) {
14621462
return uint32(len(results.PatRules)), nil
14631463
}
14641464

1465+
// MigrateToV2Request: migrate to v2 request.
1466+
type MigrateToV2Request struct {
1467+
// Zone: zone to target. If none is passed will use default zone from the config.
1468+
Zone scw.Zone `json:"-"`
1469+
1470+
GatewayID string `json:"-"`
1471+
}
1472+
14651473
// RefreshSSHKeysRequest: refresh ssh keys request.
14661474
type RefreshSSHKeysRequest struct {
14671475
// Zone: zone to target. If none is passed will use default zone from the config.
@@ -2937,3 +2945,37 @@ func (s *API) RefreshSSHKeys(req *RefreshSSHKeysRequest, opts ...scw.RequestOpti
29372945
}
29382946
return &resp, nil
29392947
}
2948+
2949+
// MigrateToV2:
2950+
func (s *API) MigrateToV2(req *MigrateToV2Request, opts ...scw.RequestOption) error {
2951+
var err error
2952+
2953+
if req.Zone == "" {
2954+
defaultZone, _ := s.client.GetDefaultZone()
2955+
req.Zone = defaultZone
2956+
}
2957+
2958+
if fmt.Sprint(req.Zone) == "" {
2959+
return errors.New("field Zone cannot be empty in request")
2960+
}
2961+
2962+
if fmt.Sprint(req.GatewayID) == "" {
2963+
return errors.New("field GatewayID cannot be empty in request")
2964+
}
2965+
2966+
scwReq := &scw.ScalewayRequest{
2967+
Method: "POST",
2968+
Path: "/vpc-gw/v1/zones/" + fmt.Sprint(req.Zone) + "/gateways/" + fmt.Sprint(req.GatewayID) + "/migrate-to-v2",
2969+
}
2970+
2971+
err = scwReq.SetBody(req)
2972+
if err != nil {
2973+
return err
2974+
}
2975+
2976+
err = s.client.Do(scwReq, nil, opts...)
2977+
if err != nil {
2978+
return err
2979+
}
2980+
return nil
2981+
}

0 commit comments

Comments
 (0)