Skip to content

Commit

Permalink
Migrated network_ips to nodebalancer and reran fixtures (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezilber-akamai authored Jul 8, 2024
1 parent 8ce268c commit 72ef4eb
Show file tree
Hide file tree
Showing 42 changed files with 3,403 additions and 2,407 deletions.
20 changes: 20 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
69 changes: 12 additions & 57 deletions network_ips.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,8 @@ package linodego

import (
"context"
"encoding/json"
"fmt"
"net/url"

"github.com/go-resty/resty/v2"
)

// IPAddressesPagedResponse represents a paginated IPAddress API response
type IPAddressesPagedResponse struct {
*PageOptions
Data []InstanceIP `json:"data"`
}

// IPAddressUpdateOptions fields are those accepted by UpdateToken
type IPAddressUpdateOptions struct {
// The reverse DNS assigned to this address. For public IPv4 addresses, this will be set to a default value provided by Linode if set to nil.
Expand Down Expand Up @@ -52,84 +41,50 @@ func (i InstanceIP) GetUpdateOptions() (o IPAddressUpdateOptions) {
return
}

// endpoint gets the endpoint URL for IPAddress
func (IPAddressesPagedResponse) endpoint(_ ...any) string {
return "networking/ips"
}

func (resp *IPAddressesPagedResponse) castResult(r *resty.Request, e string) (int, int, error) {
res, err := coupleAPIErrors(r.SetResult(IPAddressesPagedResponse{}).Get(e))
if err != nil {
return 0, 0, err
}
castedRes := res.Result().(*IPAddressesPagedResponse)
resp.Data = append(resp.Data, castedRes.Data...)
return castedRes.Pages, castedRes.Results, nil
}

// ListIPAddresses lists IPAddresses
func (c *Client) ListIPAddresses(ctx context.Context, opts *ListOptions) ([]InstanceIP, error) {
response := IPAddressesPagedResponse{}
err := c.listHelper(ctx, &response, opts)
response, err := getPaginatedResults[InstanceIP](ctx, c, "networking/ips", opts)
if err != nil {
return nil, err
}
return response.Data, nil

return response, nil
}

// GetIPAddress gets the template with the provided ID
func (c *Client) GetIPAddress(ctx context.Context, id string) (*InstanceIP, error) {
id = url.PathEscape(id)
e := fmt.Sprintf("networking/ips/%s", id)
req := c.R(ctx).SetResult(&InstanceIP{})
r, err := coupleAPIErrors(req.Get(e))
e := formatAPIPath("networking/ips/%s", id)
response, err := doGETRequest[InstanceIP](ctx, c, e)
if err != nil {
return nil, err
}
return r.Result().(*InstanceIP), nil

return response, nil
}

// UpdateIPAddress updates the IPAddress with the specified id
func (c *Client) UpdateIPAddress(ctx context.Context, id string, opts IPAddressUpdateOptions) (*InstanceIP, error) {
body, err := json.Marshal(opts)
e := formatAPIPath("networking/ips/%s", id)
response, err := doPUTRequest[InstanceIP](ctx, c, e, opts)
if err != nil {
return nil, err
}

id = url.PathEscape(id)
e := fmt.Sprintf("networking/ips/%s", id)
req := c.R(ctx).SetResult(&InstanceIP{}).SetBody(string(body))
r, err := coupleAPIErrors(req.Put(e))
if err != nil {
return nil, err
}
return r.Result().(*InstanceIP), nil
return response, nil
}

// InstancesAssignIPs assigns multiple IPv4 addresses and/or IPv6 ranges to multiple Linodes in one Region.
// This allows swapping, shuffling, or otherwise reorganizing IPs to your Linodes.
func (c *Client) InstancesAssignIPs(ctx context.Context, opts LinodesAssignIPsOptions) error {
body, err := json.Marshal(opts)
if err != nil {
return err
}

e := "networking/ips/assign"
req := c.R(ctx).SetBody(string(body))
_, err = coupleAPIErrors(req.Post(e))
_, err := doPOSTRequest[InstanceIP](ctx, c, e, opts)
return err
}

// ShareIPAddresses allows IP address reassignment (also referred to as IP failover)
// from one Linode to another if the primary Linode becomes unresponsive.
func (c *Client) ShareIPAddresses(ctx context.Context, opts IPAddressesShareOptions) error {
body, err := json.Marshal(opts)
if err != nil {
return err
}

e := "networking/ips/share"
req := c.R(ctx).SetBody(string(body))
_, err = coupleAPIErrors(req.Post(e))
_, err := doPOSTRequest[InstanceIP](ctx, c, e, opts)
return err
}
40 changes: 7 additions & 33 deletions network_pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,25 @@ package linodego

import (
"context"
"fmt"
"net/url"

"github.com/go-resty/resty/v2"
)

// IPv6PoolsPagedResponse represents a paginated IPv6Pool API response
type IPv6PoolsPagedResponse struct {
*PageOptions
Data []IPv6Range `json:"data"`
}

// endpoint gets the endpoint URL for IPv6Pool
func (IPv6PoolsPagedResponse) endpoint(_ ...any) string {
return "networking/ipv6/pools"
}

func (resp *IPv6PoolsPagedResponse) castResult(r *resty.Request, e string) (int, int, error) {
res, err := coupleAPIErrors(r.SetResult(IPv6PoolsPagedResponse{}).Get(e))
if err != nil {
return 0, 0, err
}
castedRes := res.Result().(*IPv6PoolsPagedResponse)
resp.Data = append(resp.Data, castedRes.Data...)
return castedRes.Pages, castedRes.Results, nil
}

// ListIPv6Pools lists IPv6Pools
func (c *Client) ListIPv6Pools(ctx context.Context, opts *ListOptions) ([]IPv6Range, error) {
response := IPv6PoolsPagedResponse{}
err := c.listHelper(ctx, &response, opts)
response, err := getPaginatedResults[IPv6Range](ctx, c, "networking/ipv6/pools", opts)
if err != nil {
return nil, err
}
return response.Data, nil

return response, nil
}

// GetIPv6Pool gets the template with the provided ID
func (c *Client) GetIPv6Pool(ctx context.Context, id string) (*IPv6Range, error) {
id = url.PathEscape(id)
e := fmt.Sprintf("networking/ipv6/pools/%s", id)
req := c.R(ctx).SetResult(&IPv6Range{})
r, err := coupleAPIErrors(req.Get(e))
e := formatAPIPath("networking/ipv6/pools/%s", id)
response, err := doGETRequest[IPv6Range](ctx, c, e)
if err != nil {
return nil, err
}
return r.Result().(*IPv6Range), nil

return response, nil
}
57 changes: 12 additions & 45 deletions network_ranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,83 +2,50 @@ package linodego

import (
"context"
"encoding/json"
"fmt"
"net/url"

"github.com/go-resty/resty/v2"
)

// IPv6RangesPagedResponse represents a paginated IPv6Range API response
type IPv6RangesPagedResponse struct {
*PageOptions
Data []IPv6Range `json:"data"`
}

// IPv6RangeCreateOptions fields are those accepted by CreateIPv6Range
type IPv6RangeCreateOptions struct {
LinodeID int `json:"linode_id,omitempty"`
PrefixLength int `json:"prefix_length"`
RouteTarget string `json:"route_target,omitempty"`
}

// endpoint gets the endpoint URL for IPv6Range
func (IPv6RangesPagedResponse) endpoint(_ ...any) string {
return "networking/ipv6/ranges"
}

func (resp *IPv6RangesPagedResponse) castResult(r *resty.Request, e string) (int, int, error) {
res, err := coupleAPIErrors(r.SetResult(IPv6RangesPagedResponse{}).Get(e))
if err != nil {
return 0, 0, err
}
castedRes := res.Result().(*IPv6RangesPagedResponse)
resp.Data = append(resp.Data, castedRes.Data...)
return castedRes.Pages, castedRes.Results, nil
}

// ListIPv6Ranges lists IPv6Ranges
func (c *Client) ListIPv6Ranges(ctx context.Context, opts *ListOptions) ([]IPv6Range, error) {
response := IPv6RangesPagedResponse{}
err := c.listHelper(ctx, &response, opts)
response, err := getPaginatedResults[IPv6Range](ctx, c, "networking/ipv6/ranges", opts)
if err != nil {
return nil, err
}
return response.Data, nil

return response, nil
}

// GetIPv6Range gets details about an IPv6 range
func (c *Client) GetIPv6Range(ctx context.Context, ipRange string) (*IPv6Range, error) {
ipRange = url.PathEscape(ipRange)
e := fmt.Sprintf("networking/ipv6/ranges/%s", ipRange)
req := c.R(ctx).SetResult(&IPv6Range{})
r, err := coupleAPIErrors(req.Get(e))
e := formatAPIPath("networking/ipv6/ranges/%s", ipRange)
response, err := doGETRequest[IPv6Range](ctx, c, e)
if err != nil {
return nil, err
}
return r.Result().(*IPv6Range), nil

return response, nil
}

// CreateIPv6Range creates an IPv6 Range and assigns it based on the provided Linode or route target IPv6 SLAAC address.
func (c *Client) CreateIPv6Range(ctx context.Context, opts IPv6RangeCreateOptions) (*IPv6Range, error) {
body, err := json.Marshal(opts)
if err != nil {
return nil, err
}

e := "networking/ipv6/ranges"
req := c.R(ctx).SetResult(&IPv6Range{}).SetBody(string(body))
r, err := coupleAPIErrors(req.Post(e))
response, err := doPOSTRequest[IPv6Range](ctx, c, e, opts)
if err != nil {
return nil, err
}
return r.Result().(*IPv6Range), nil

return response, nil
}

// DeleteIPv6Range deletes an IPv6 Range.
func (c *Client) DeleteIPv6Range(ctx context.Context, ipRange string) error {
ipRange = url.PathEscape(ipRange)
e := fmt.Sprintf("networking/ipv6/ranges/%s", ipRange)
_, err := coupleAPIErrors(c.R(ctx).Delete(e))
e := formatAPIPath("networking/ipv6/ranges/%s", ipRange)
err := doDELETERequest(ctx, c, e)
return err
}
Loading

0 comments on commit 72ef4eb

Please sign in to comment.