Skip to content

Commit

Permalink
feat(vpc_gw): introduce idempotent call to migrate PGWs to IPMob (#2002)
Browse files Browse the repository at this point in the history
Co-authored-by: Mia-Cross <[email protected]>
  • Loading branch information
scaleway-bot and Mia-Cross authored Feb 16, 2024
1 parent 3fffbca commit 8458171
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion api/vpcgw/v1/vpcgw_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,9 +674,12 @@ type Gateway struct {
// SMTPEnabled: defines whether SMTP traffic is allowed to pass through the gateway.
SMTPEnabled bool `json:"smtp_enabled"`

// IsLegacy: whether this uses non-IPAM IP configurations.
// IsLegacy: defines whether the gateway uses non-IPAM IP configurations.
IsLegacy bool `json:"is_legacy"`

// IPMobilityEnabled: defines whether the gateway uses routed IPs (IP mobility) instead of NAT IPs.
IPMobilityEnabled bool `json:"ip_mobility_enabled"`

// Zone: zone of the gateway.
Zone scw.Zone `json:"zone"`
}
Expand Down Expand Up @@ -923,6 +926,15 @@ type DeletePATRuleRequest struct {
PatRuleID string `json:"-"`
}

// EnableIPMobilityRequest: enable ip mobility request.
type EnableIPMobilityRequest struct {
// Zone: zone to target. If none is passed will use default zone from the config.
Zone scw.Zone `json:"-"`

// GatewayID: ID of the gateway to upgrade to IP mobility.
GatewayID string `json:"-"`
}

// GetDHCPEntryRequest: get dhcp entry request.
type GetDHCPEntryRequest struct {
// Zone: zone to target. If none is passed will use default zone from the config.
Expand Down Expand Up @@ -1790,6 +1802,42 @@ func (s *API) UpgradeGateway(req *UpgradeGatewayRequest, opts ...scw.RequestOpti
return &resp, nil
}

// EnableIPMobility: 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.
func (s *API) EnableIPMobility(req *EnableIPMobilityRequest, opts ...scw.RequestOption) (*Gateway, error) {
var err error

if req.Zone == "" {
defaultZone, _ := s.client.GetDefaultZone()
req.Zone = defaultZone
}

if fmt.Sprint(req.Zone) == "" {
return nil, errors.New("field Zone cannot be empty in request")
}

if fmt.Sprint(req.GatewayID) == "" {
return nil, errors.New("field GatewayID cannot be empty in request")
}

scwReq := &scw.ScalewayRequest{
Method: "POST",
Path: "/vpc-gw/v1/zones/" + fmt.Sprint(req.Zone) + "/gateways/" + fmt.Sprint(req.GatewayID) + "/enable-ip-mobility",
}

err = scwReq.SetBody(req)
if err != nil {
return nil, err
}

var resp Gateway

err = s.client.Do(scwReq, &resp, opts...)
if err != nil {
return nil, err
}
return &resp, nil
}

// ListGatewayNetworks: List the connections between Public Gateways and Private Networks (a connection = a GatewayNetwork). You can choose to filter by `gateway-id` to list all Private Networks attached to the specified Public Gateway, or by `private_network_id` to list all Public Gateways attached to the specified Private Network. Other query parameters are also available. The result is an array of GatewayNetwork objects, each giving details of the connection between a given Public Gateway and a given Private Network.
func (s *API) ListGatewayNetworks(req *ListGatewayNetworksRequest, opts ...scw.RequestOption) (*ListGatewayNetworksResponse, error) {
var err error
Expand Down

0 comments on commit 8458171

Please sign in to comment.