Skip to content

Commit 8458171

Browse files
feat(vpc_gw): introduce idempotent call to migrate PGWs to IPMob (#2002)
Co-authored-by: Mia-Cross <[email protected]>
1 parent 3fffbca commit 8458171

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

api/vpcgw/v1/vpcgw_sdk.go

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,9 +674,12 @@ type Gateway struct {
674674
// SMTPEnabled: defines whether SMTP traffic is allowed to pass through the gateway.
675675
SMTPEnabled bool `json:"smtp_enabled"`
676676

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

680+
// IPMobilityEnabled: defines whether the gateway uses routed IPs (IP mobility) instead of NAT IPs.
681+
IPMobilityEnabled bool `json:"ip_mobility_enabled"`
682+
680683
// Zone: zone of the gateway.
681684
Zone scw.Zone `json:"zone"`
682685
}
@@ -923,6 +926,15 @@ type DeletePATRuleRequest struct {
923926
PatRuleID string `json:"-"`
924927
}
925928

929+
// EnableIPMobilityRequest: enable ip mobility request.
930+
type EnableIPMobilityRequest struct {
931+
// Zone: zone to target. If none is passed will use default zone from the config.
932+
Zone scw.Zone `json:"-"`
933+
934+
// GatewayID: ID of the gateway to upgrade to IP mobility.
935+
GatewayID string `json:"-"`
936+
}
937+
926938
// GetDHCPEntryRequest: get dhcp entry request.
927939
type GetDHCPEntryRequest struct {
928940
// Zone: zone to target. If none is passed will use default zone from the config.
@@ -1790,6 +1802,42 @@ func (s *API) UpgradeGateway(req *UpgradeGatewayRequest, opts ...scw.RequestOpti
17901802
return &resp, nil
17911803
}
17921804

1805+
// 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.
1806+
func (s *API) EnableIPMobility(req *EnableIPMobilityRequest, opts ...scw.RequestOption) (*Gateway, error) {
1807+
var err error
1808+
1809+
if req.Zone == "" {
1810+
defaultZone, _ := s.client.GetDefaultZone()
1811+
req.Zone = defaultZone
1812+
}
1813+
1814+
if fmt.Sprint(req.Zone) == "" {
1815+
return nil, errors.New("field Zone cannot be empty in request")
1816+
}
1817+
1818+
if fmt.Sprint(req.GatewayID) == "" {
1819+
return nil, errors.New("field GatewayID cannot be empty in request")
1820+
}
1821+
1822+
scwReq := &scw.ScalewayRequest{
1823+
Method: "POST",
1824+
Path: "/vpc-gw/v1/zones/" + fmt.Sprint(req.Zone) + "/gateways/" + fmt.Sprint(req.GatewayID) + "/enable-ip-mobility",
1825+
}
1826+
1827+
err = scwReq.SetBody(req)
1828+
if err != nil {
1829+
return nil, err
1830+
}
1831+
1832+
var resp Gateway
1833+
1834+
err = s.client.Do(scwReq, &resp, opts...)
1835+
if err != nil {
1836+
return nil, err
1837+
}
1838+
return &resp, nil
1839+
}
1840+
17931841
// 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.
17941842
func (s *API) ListGatewayNetworks(req *ListGatewayNetworksRequest, opts ...scw.RequestOption) (*ListGatewayNetworksResponse, error) {
17951843
var err error

0 commit comments

Comments
 (0)