diff --git a/govultr.go b/govultr.go index 4d8af5d..23fc1f6 100644 --- a/govultr.go +++ b/govultr.go @@ -59,20 +59,18 @@ type Client struct { Kubernetes KubernetesService LoadBalancer LoadBalancerService Marketplace MarketplaceService - // Deprecated: Network should no longer be used. Instead, use VPC. - Network NetworkService - ObjectStorage ObjectStorageService - OS OSService - Plan PlanService - Region RegionService - ReservedIP ReservedIPService - Inference InferenceService - Snapshot SnapshotService - SSHKey SSHKeyService - StartupScript StartupScriptService - User UserService - VPC VPCService - VPC2 VPC2Service + ObjectStorage ObjectStorageService + OS OSService + Plan PlanService + Region RegionService + ReservedIP ReservedIPService + Inference InferenceService + Snapshot SnapshotService + SSHKey SSHKeyService + StartupScript StartupScriptService + User UserService + VPC VPCService + VPC2 VPC2Service // Optional function called after every successful request made to the Vultr API onRequestCompleted RequestCompletionCallback @@ -134,7 +132,6 @@ func NewClient(httpClient *http.Client) *Client { client.Kubernetes = &KubernetesHandler{client} client.LoadBalancer = &LoadBalancerHandler{client} client.Marketplace = &MarketplaceServiceHandler{client} - client.Network = &NetworkServiceHandler{client} client.ObjectStorage = &ObjectStorageServiceHandler{client} client.OS = &OSServiceHandler{client} client.Plan = &PlanServiceHandler{client} diff --git a/instance.go b/instance.go index 524d31b..148f0a6 100644 --- a/instance.go +++ b/instance.go @@ -33,13 +33,6 @@ type InstanceService interface { GetBandwidth(ctx context.Context, instanceID string) (*Bandwidth, *http.Response, error) GetNeighbors(ctx context.Context, instanceID string) (*Neighbors, *http.Response, error) - // Deprecated: ListPrivateNetworks should no longer be used. Instead, use ListVPCInfo. - ListPrivateNetworks(ctx context.Context, instanceID string, options *ListOptions) ([]PrivateNetwork, *Meta, *http.Response, error) - // Deprecated: AttachPrivateNetwork should no longer be used. Instead, use AttachVPC. - AttachPrivateNetwork(ctx context.Context, instanceID, networkID string) error - // Deprecated: DetachPrivateNetwork should no longer be used. Instead, use DetachVPC. - DetachPrivateNetwork(ctx context.Context, instanceID, networkID string) error - ListVPCInfo(ctx context.Context, instanceID string, options *ListOptions) ([]VPCInfo, *Meta, *http.Response, error) AttachVPC(ctx context.Context, instanceID, vpcID string) error DetachVPC(ctx context.Context, instanceID, vpcID string) error @@ -138,19 +131,6 @@ type Bandwidth struct { } `json:"bandwidth"` } -type privateNetworksBase struct { - PrivateNetworks []PrivateNetwork `json:"private_networks"` - Meta *Meta `json:"meta"` -} - -// PrivateNetwork information for a given instance. -// Deprecated: PrivateNetwork should no longer be used. Instead, use VPCInfo. -type PrivateNetwork struct { - NetworkID string `json:"network_id"` - MacAddress string `json:"mac_address"` - IPAddress string `json:"ip_address"` -} - type vpcInfoBase struct { VPCs []VPCInfo `json:"vpcs"` Meta *Meta `json:"meta"` @@ -257,34 +237,30 @@ type InstanceCreateReq struct { Plan string `json:"plan,omitempty"` Label string `json:"label,omitempty"` // Deprecated: Tag should no longer be used. Instead, use Tags. - Tag string `json:"tag,omitempty"` - Tags []string `json:"tags"` - OsID int `json:"os_id,omitempty"` - ISOID string `json:"iso_id,omitempty"` - AppID int `json:"app_id,omitempty"` - ImageID string `json:"image_id,omitempty"` - FirewallGroupID string `json:"firewall_group_id,omitempty"` - Hostname string `json:"hostname,omitempty"` - IPXEChainURL string `json:"ipxe_chain_url,omitempty"` - ScriptID string `json:"script_id,omitempty"` - SnapshotID string `json:"snapshot_id,omitempty"` - EnableIPv6 *bool `json:"enable_ipv6,omitempty"` - DisablePublicIPv4 *bool `json:"disable_public_ipv4,omitempty"` - // Deprecated: EnablePrivateNetwork should no longer be used. Instead, use EnableVPC. - EnablePrivateNetwork *bool `json:"enable_private_network,omitempty"` - // Deprecated: AttachPrivateNetwork should no longer be used. Instead, use AttachVPC. - AttachPrivateNetwork []string `json:"attach_private_network,omitempty"` - EnableVPC *bool `json:"enable_vpc,omitempty"` - AttachVPC []string `json:"attach_vpc,omitempty"` - EnableVPC2 *bool `json:"enable_vpc2,omitempty"` - AttachVPC2 []string `json:"attach_vpc2,omitempty"` - SSHKeys []string `json:"sshkey_id,omitempty"` - Backups string `json:"backups,omitempty"` - DDOSProtection *bool `json:"ddos_protection,omitempty"` - UserData string `json:"user_data,omitempty"` - ReservedIPv4 string `json:"reserved_ipv4,omitempty"` - ActivationEmail *bool `json:"activation_email,omitempty"` - AppVariables map[string]string `json:"app_variables,omitempty"` + Tag string `json:"tag,omitempty"` + Tags []string `json:"tags"` + OsID int `json:"os_id,omitempty"` + ISOID string `json:"iso_id,omitempty"` + AppID int `json:"app_id,omitempty"` + ImageID string `json:"image_id,omitempty"` + FirewallGroupID string `json:"firewall_group_id,omitempty"` + Hostname string `json:"hostname,omitempty"` + IPXEChainURL string `json:"ipxe_chain_url,omitempty"` + ScriptID string `json:"script_id,omitempty"` + SnapshotID string `json:"snapshot_id,omitempty"` + EnableIPv6 *bool `json:"enable_ipv6,omitempty"` + DisablePublicIPv4 *bool `json:"disable_public_ipv4,omitempty"` + EnableVPC *bool `json:"enable_vpc,omitempty"` + AttachVPC []string `json:"attach_vpc,omitempty"` + EnableVPC2 *bool `json:"enable_vpc2,omitempty"` + AttachVPC2 []string `json:"attach_vpc2,omitempty"` + SSHKeys []string `json:"sshkey_id,omitempty"` + Backups string `json:"backups,omitempty"` + DDOSProtection *bool `json:"ddos_protection,omitempty"` + UserData string `json:"user_data,omitempty"` + ReservedIPv4 string `json:"reserved_ipv4,omitempty"` + ActivationEmail *bool `json:"activation_email,omitempty"` + AppVariables map[string]string `json:"app_variables,omitempty"` } // InstanceUpdateReq struct used to update an instance. @@ -292,28 +268,22 @@ type InstanceUpdateReq struct { Plan string `json:"plan,omitempty"` Label string `json:"label,omitempty"` // Deprecated: Tag should no longer be used. Instead, use Tags. - Tag *string `json:"tag,omitempty"` - Tags []string `json:"tags"` - OsID int `json:"os_id,omitempty"` - AppID int `json:"app_id,omitempty"` - ImageID string `json:"image_id,omitempty"` - EnableIPv6 *bool `json:"enable_ipv6,omitempty"` - // Deprecated: EnablePrivateNetwork should no longer be used. Instead, use EnableVPC. - EnablePrivateNetwork *bool `json:"enable_private_network,omitempty"` - // Deprecated: AttachPrivateNetwork should no longer be used. Instead, use AttachVPC. - AttachPrivateNetwork []string `json:"attach_private_network,omitempty"` - // Deprecated: DetachPrivateNetwork should no longer be used. Instead, use DetachVPC. - DetachPrivateNetwork []string `json:"detach_private_network,omitempty"` - EnableVPC *bool `json:"enable_vpc,omitempty"` - AttachVPC []string `json:"attach_vpc,omitempty"` - DetachVPC []string `json:"detach_vpc,omitempty"` - EnableVPC2 *bool `json:"enable_vpc2,omitempty"` - AttachVPC2 []string `json:"attach_vpc2,omitempty"` - DetachVPC2 []string `json:"detach_vpc2,omitempty"` - Backups string `json:"backups,omitempty"` - DDOSProtection *bool `json:"ddos_protection"` - UserData string `json:"user_data,omitempty"` - FirewallGroupID string `json:"firewall_group_id,omitempty"` + Tag *string `json:"tag,omitempty"` + Tags []string `json:"tags"` + OsID int `json:"os_id,omitempty"` + AppID int `json:"app_id,omitempty"` + ImageID string `json:"image_id,omitempty"` + EnableIPv6 *bool `json:"enable_ipv6,omitempty"` + EnableVPC *bool `json:"enable_vpc,omitempty"` + AttachVPC []string `json:"attach_vpc,omitempty"` + DetachVPC []string `json:"detach_vpc,omitempty"` + EnableVPC2 *bool `json:"enable_vpc2,omitempty"` + AttachVPC2 []string `json:"attach_vpc2,omitempty"` + DetachVPC2 []string `json:"detach_vpc2,omitempty"` + Backups string `json:"backups,omitempty"` + DDOSProtection *bool `json:"ddos_protection"` + UserData string `json:"user_data,omitempty"` + FirewallGroupID string `json:"firewall_group_id,omitempty"` } // ReinstallReq struct used to allow changes during a reinstall @@ -547,61 +517,6 @@ func (i *InstanceServiceHandler) GetNeighbors(ctx context.Context, instanceID st return neighbors, resp, nil } -// ListPrivateNetworks currently attached to an instance. -// Deprecated: ListPrivateNetworks should no longer be used. Instead, use ListVPCInfo -func (i *InstanceServiceHandler) ListPrivateNetworks(ctx context.Context, instanceID string, options *ListOptions) ([]PrivateNetwork, *Meta, *http.Response, error) { //nolint:lll,dupl - uri := fmt.Sprintf("%s/%s/private-networks", instancePath, instanceID) - req, err := i.client.NewRequest(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, nil, nil, err - } - - newValues, err := query.Values(options) - if err != nil { - return nil, nil, nil, err - } - - req.URL.RawQuery = newValues.Encode() - - networks := new(privateNetworksBase) - resp, err := i.client.DoWithContext(ctx, req, networks) - if err != nil { - return nil, nil, resp, err - } - - return networks.PrivateNetworks, networks.Meta, resp, nil -} - -// AttachPrivateNetwork to an instance -// Deprecated: AttachPrivateNetwork should no longer be used. Instead, use AttachVPC -func (i *InstanceServiceHandler) AttachPrivateNetwork(ctx context.Context, instanceID, networkID string) error { - uri := fmt.Sprintf("%s/%s/private-networks/attach", instancePath, instanceID) - body := RequestBody{"network_id": networkID} - - req, err := i.client.NewRequest(ctx, http.MethodPost, uri, body) - if err != nil { - return err - } - - _, err = i.client.DoWithContext(ctx, req, nil) - return err -} - -// DetachPrivateNetwork from an instance. -// Deprecated: DetachPrivateNetwork should no longer be used. Instead, use DetachVPC -func (i *InstanceServiceHandler) DetachPrivateNetwork(ctx context.Context, instanceID, networkID string) error { - uri := fmt.Sprintf("%s/%s/private-networks/detach", instancePath, instanceID) - body := RequestBody{"network_id": networkID} - - req, err := i.client.NewRequest(ctx, http.MethodPost, uri, body) - if err != nil { - return err - } - - _, err = i.client.DoWithContext(ctx, req, nil) - return err -} - // ListVPCInfo currently attached to an instance. func (i *InstanceServiceHandler) ListVPCInfo(ctx context.Context, instanceID string, options *ListOptions) ([]VPCInfo, *Meta, *http.Response, error) { //nolint:lll,dupl uri := fmt.Sprintf("%s/%s/vpcs", instancePath, instanceID) diff --git a/instance_test.go b/instance_test.go index abb3230..9047a38 100644 --- a/instance_test.go +++ b/instance_test.go @@ -155,49 +155,6 @@ func TestServerServiceHandler_Neighbors(t *testing.T) { } } -func TestServerServiceHandler_ListPrivateNetworks(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/v2/instances/14b3e7d6-ffb5-4994-8502-57fcd9db3b33/private-networks", func(writer http.ResponseWriter, request *http.Request) { - response := `{"private_networks": [{"network_id": "v1-net539626f0798d7","mac_address": "5a:02:00:00:24:e9","ip_address": "10.99.0.3"}],"meta":{"total":1,"links":{"next":"thisismycusror","prev":""}}}` - fmt.Fprint(writer, response) - }) - - options := &ListOptions{ - PerPage: 1, - Cursor: "", - } - privateNetwork, meta, _, err := client.Instance.ListPrivateNetworks(ctx, "14b3e7d6-ffb5-4994-8502-57fcd9db3b33", options) - if err != nil { - t.Errorf("Instance.ListPrivateNetworks return %+v, ", err) - } - - expected := []PrivateNetwork{ - { - NetworkID: "v1-net539626f0798d7", - MacAddress: "5a:02:00:00:24:e9", - IPAddress: "10.99.0.3", - }, - } - - if !reflect.DeepEqual(privateNetwork, expected) { - t.Errorf("Instance.ListPrivateNetworks returned %+v, expected %+v", privateNetwork, expected) - } - - expectedMeta := &Meta{ - Total: 1, - Links: &Links{ - Next: "thisismycusror", - Prev: "", - }, - } - - if !reflect.DeepEqual(meta, expectedMeta) { - t.Errorf("Instance.ListPrivateNetworks meta returned %+v, expected %+v", meta, expectedMeta) - } -} - func TestServerServiceHandler_ListVPCInfo(t *testing.T) { setup() defer teardown() @@ -980,32 +937,6 @@ func TestServerServiceHandler_MassHalt(t *testing.T) { } } -func TestServerServiceHandler_AttachPrivateNetwork(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/v2/instances/14b3e7d6-ffb5-4994-8502-57fcd9db3b33/private-networks/attach", func(writer http.ResponseWriter, request *http.Request) { - fmt.Fprint(writer) - }) - - if err := client.Instance.AttachPrivateNetwork(ctx, "14b3e7d6-ffb5-4994-8502-57fcd9db3b33", "14b3e7d6-ffb5-4994-8502-57fcd9db3b33"); err != nil { - t.Errorf("Instance.AttachPrivateNetwork returned %+v", err) - } -} - -func TestServerServiceHandler_DetachPrivateNetwork(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/v2/instances/14b3e7d6-ffb5-4994-8502-57fcd9db3b33/private-networks/detach", func(writer http.ResponseWriter, request *http.Request) { - fmt.Fprint(writer) - }) - - if err := client.Instance.DetachPrivateNetwork(ctx, "14b3e7d6-ffb5-4994-8502-57fcd9db3b33", "14b3e7d6-ffb5-4994-8502-57fcd9db3b33"); err != nil { - t.Errorf("Instance.DetachPrivateNetwork returned %+v", err) - } -} - func TestServerServiceHandler_AttachVPC(t *testing.T) { setup() defer teardown() diff --git a/load_balancer.go b/load_balancer.go index 5135758..c028745 100644 --- a/load_balancer.go +++ b/load_balancer.go @@ -63,9 +63,7 @@ type LoadBalancerReq struct { ProxyProtocol *bool `json:"proxy_protocol,omitempty"` BalancingAlgorithm string `json:"balancing_algorithm,omitempty"` FirewallRules []LBFirewallRule `json:"firewall_rules"` - // Deprecated: PrivateNetwork should no longer be used. Instead, use VPC. - PrivateNetwork *string `json:"private_network,omitempty"` - VPC *string `json:"vpc,omitempty"` + VPC *string `json:"vpc,omitempty"` } // InstanceList represents instances that are attached to your load balancer @@ -90,9 +88,7 @@ type GenericInfo struct { SSLRedirect *bool `json:"ssl_redirect,omitempty"` StickySessions *StickySessions `json:"sticky_sessions,omitempty"` ProxyProtocol *bool `json:"proxy_protocol,omitempty"` - // Deprecated: PrivateNetwork should no longer be used. Instead, use VPC. - PrivateNetwork string `json:"private_network,omitempty"` - VPC string `json:"vpc,omitempty"` + VPC string `json:"vpc,omitempty"` } // StickySessions represents cookie for your load balancer diff --git a/load_balancer_test.go b/load_balancer_test.go index e4aff8f..a0e2e2a 100644 --- a/load_balancer_test.go +++ b/load_balancer_test.go @@ -27,7 +27,6 @@ func TestLoadBalancerHandler_List(t *testing.T) { "balancing_algorithm": "roundrobin", "ssl_redirect": false, "proxy_protocol": false, - "private_network": "8d5bdbdb-3324-4d0c-b303-03e1315e1c02", "vpc": "8d5bdbdb-3324-4d0c-b303-03e1315e1c02", "sticky_sessions": { "cookie_name": "my-cookie" @@ -107,7 +106,6 @@ func TestLoadBalancerHandler_List(t *testing.T) { BalancingAlgorithm: "roundrobin", SSLRedirect: BoolToBoolPtr(false), ProxyProtocol: BoolToBoolPtr(false), - PrivateNetwork: "8d5bdbdb-3324-4d0c-b303-03e1315e1c02", VPC: "8d5bdbdb-3324-4d0c-b303-03e1315e1c02", StickySessions: &StickySessions{ CookieName: "my-cookie", @@ -183,7 +181,6 @@ func TestLoadBalancerHandler_Get(t *testing.T) { "balancing_algorithm": "roundrobin", "ssl_redirect": false, "proxy_protocol": false, - "private_network": "8d5bdbdb-3324-4d0c-b303-03e1315e1c02", "vpc": "8d5bdbdb-3324-4d0c-b303-03e1315e1c02", "sticky_sessions": { "cookie_name": "my-cookie" @@ -254,7 +251,6 @@ func TestLoadBalancerHandler_Get(t *testing.T) { BalancingAlgorithm: "roundrobin", SSLRedirect: BoolToBoolPtr(false), ProxyProtocol: BoolToBoolPtr(false), - PrivateNetwork: "8d5bdbdb-3324-4d0c-b303-03e1315e1c02", VPC: "8d5bdbdb-3324-4d0c-b303-03e1315e1c02", StickySessions: &StickySessions{ CookieName: "my-cookie", @@ -423,7 +419,6 @@ func TestLoadBalancerHandler_Create(t *testing.T) { "balancing_algorithm": "roundrobin", "ssl_redirect": false, "proxy_protocol": false, - "private_network": "8d5bdbdb-3324-4d0c-b303-03e1315e1c02", "vpc": "8d5bdbdb-3324-4d0c-b303-03e1315e1c02", "sticky_sessions": { "cookie_name": "my-cookie" @@ -482,7 +477,6 @@ func TestLoadBalancerHandler_Create(t *testing.T) { SSLRedirect: BoolToBoolPtr(false), ProxyProtocol: BoolToBoolPtr(false), Nodes: 3, - PrivateNetwork: StringToStringPtr("8d5bdbdb-3324-4d0c-b303-03e1315e1c02"), VPC: StringToStringPtr("8d5bdbdb-3324-4d0c-b303-03e1315e1c02"), HealthCheck: &HealthCheck{ Protocol: "http", @@ -522,7 +516,6 @@ func TestLoadBalancerHandler_Create(t *testing.T) { BalancingAlgorithm: "roundrobin", SSLRedirect: BoolToBoolPtr(false), ProxyProtocol: BoolToBoolPtr(false), - PrivateNetwork: "8d5bdbdb-3324-4d0c-b303-03e1315e1c02", VPC: "8d5bdbdb-3324-4d0c-b303-03e1315e1c02", StickySessions: &StickySessions{ CookieName: "my-cookie", @@ -577,7 +570,6 @@ func TestLoadBalancerHandler_Update(t *testing.T) { BalancingAlgorithm: "roundrobin", SSLRedirect: BoolToBoolPtr(false), ProxyProtocol: BoolToBoolPtr(false), - PrivateNetwork: StringToStringPtr("8d5bdbdb-3324-4d0c-b303-03e1315e1c02"), VPC: StringToStringPtr("8d5bdbdb-3324-4d0c-b303-03e1315e1c02"), Nodes: 5, HealthCheck: &HealthCheck{ diff --git a/network.go b/network.go deleted file mode 100644 index 1b9a146..0000000 --- a/network.go +++ /dev/null @@ -1,148 +0,0 @@ -package govultr //nolint:dupl - -import ( - "context" - "fmt" - "net/http" - - "github.com/google/go-querystring/query" -) - -const netPath = "/v2/private-networks" - -// NetworkService is the interface to interact with the network endpoints on the Vultr API -// Link : https://www.vultr.com/api/#tag/private-Networks -// Deprecated: NetworkService should no longer be used. Instead, use VPCService. -type NetworkService interface { - // Deprecated: NetworkService Create should no longer be used. Instead, use VPCService Create. - Create(ctx context.Context, createReq *NetworkReq) (*Network, *http.Response, error) - // Deprecated: NetworkService Get should no longer be used. Instead, use VPCService Get. - Get(ctx context.Context, networkID string) (*Network, *http.Response, error) - // Deprecated: NetworkService Update should no longer be used. Instead, use VPCService Update. - Update(ctx context.Context, networkID string, description string) error - // Deprecated: NetworkService Delete should no longer be used. Instead, use VPCService Delete. - Delete(ctx context.Context, networkID string) error - // Deprecated: NetworkService List should no longer be used. Instead, use VPCService List. - List(ctx context.Context, options *ListOptions) ([]Network, *Meta, *http.Response, error) -} - -// NetworkServiceHandler handles interaction with the network methods for the Vultr API -// Deprecated: NetworkServiceHandler should no longer be used. Instead, use VPCServiceHandler. -type NetworkServiceHandler struct { - client *Client -} - -// Network represents a Vultr private network -// Deprecated: Network should no longer be used. Instead, use VPC. -type Network struct { - NetworkID string `json:"id"` - Region string `json:"region"` - Description string `json:"description"` - V4Subnet string `json:"v4_subnet"` - V4SubnetMask int `json:"v4_subnet_mask"` - DateCreated string `json:"date_created"` -} - -// NetworkReq represents parameters to create or update Network resource -// Deprecated: NetworkReq should no longer be used. Instead, use VPCReq. -type NetworkReq struct { - Region string `json:"region"` - Description string `json:"description"` - V4Subnet string `json:"v4_subnet"` - V4SubnetMask int `json:"v4_subnet_mask"` -} - -type networksBase struct { - Networks []Network `json:"networks"` - Meta *Meta `json:"meta"` -} - -type networkBase struct { - Network *Network `json:"network"` -} - -// Create a new private network. A private network can only be used at the location for which it was created. -// Deprecated: NetworkServiceHandler Create should no longer be used. Instead, use VPCServiceHandler Create. -func (n *NetworkServiceHandler) Create(ctx context.Context, createReq *NetworkReq) (*Network, *http.Response, error) { - req, err := n.client.NewRequest(ctx, http.MethodPost, netPath, createReq) - if err != nil { - return nil, nil, err - } - - network := new(networkBase) - resp, err := n.client.DoWithContext(ctx, req, network) - if err != nil { - return nil, resp, err - } - - return network.Network, resp, nil -} - -// Get gets the private networks of the requested ID -// Deprecated: NetworkServiceHandler Get should no longer be used. Instead use VPCServiceHandler Create. -func (n *NetworkServiceHandler) Get(ctx context.Context, networkID string) (*Network, *http.Response, error) { - uri := fmt.Sprintf("%s/%s", netPath, networkID) - req, err := n.client.NewRequest(ctx, http.MethodGet, uri, nil) - if err != nil { - return nil, nil, err - } - - network := new(networkBase) - resp, err := n.client.DoWithContext(ctx, req, network) - if err != nil { - return nil, resp, err - } - - return network.Network, resp, nil -} - -// Update updates a private network -// Deprecated: NetworkServiceHandler Update should no longer be used. Instead, use VPCServiceHandler Update. -func (n *NetworkServiceHandler) Update(ctx context.Context, networkID, description string) error { - uri := fmt.Sprintf("%s/%s", netPath, networkID) - - netReq := RequestBody{"description": description} - req, err := n.client.NewRequest(ctx, http.MethodPut, uri, netReq) - if err != nil { - return err - } - _, err = n.client.DoWithContext(ctx, req, nil) - return err -} - -// Delete a private network. Before deleting, a network must be disabled from all instances -// Deprecated: NetworkServiceHandler Delete should no longer be used. Instead, use VPCServiceHandler Delete. -func (n *NetworkServiceHandler) Delete(ctx context.Context, networkID string) error { - uri := fmt.Sprintf("%s/%s", netPath, networkID) - req, err := n.client.NewRequest(ctx, http.MethodDelete, uri, nil) - if err != nil { - return err - } - - _, err = n.client.DoWithContext(ctx, req, nil) - return err -} - -// List lists all private networks on the current account -// Deprecated: NetworkServiceHandler List should no longer be used. Instead, use VPCServiceHandler List. -func (n *NetworkServiceHandler) List(ctx context.Context, options *ListOptions) ([]Network, *Meta, *http.Response, error) { //nolint:dupl - req, err := n.client.NewRequest(ctx, http.MethodGet, netPath, nil) - if err != nil { - return nil, nil, nil, err - } - - newValues, err := query.Values(options) - if err != nil { - return nil, nil, nil, err - } - - req.URL.RawQuery = newValues.Encode() - - networks := new(networksBase) - resp, err := n.client.DoWithContext(ctx, req, networks) - if err != nil { - return nil, nil, resp, err - } - - return networks.Networks, networks.Meta, resp, nil -} diff --git a/network_test.go b/network_test.go deleted file mode 100644 index 868dbff..0000000 --- a/network_test.go +++ /dev/null @@ -1,154 +0,0 @@ -package govultr - -import ( - "fmt" - "net/http" - "reflect" - "testing" -) - -func TestNetworkServiceHandler_Create(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/v2/private-networks", func(writer http.ResponseWriter, request *http.Request) { - response := ` - { - "network": { - "id": "net539626f0798d7", - "date_created": "2017-08-25 12:23:45", - "region": "ewr", - "description": "test1", - "v4_subnet": "10.99.0.0", - "v4_subnet_mask": 24 - } - } - ` - - fmt.Fprint(writer, response) - }) - - options := &NetworkReq{ - Region: "ewr", - Description: "test1", - } - - net, _, err := client.Network.Create(ctx, options) - - if err != nil { - t.Errorf("Network.Create returned %+v, expected %+v", err, nil) - } - - expected := &Network{ - NetworkID: "net539626f0798d7", - Region: "ewr", - Description: "test1", - V4Subnet: "10.99.0.0", - V4SubnetMask: 24, - DateCreated: "2017-08-25 12:23:45", - } - - if !reflect.DeepEqual(net, expected) { - t.Errorf("Network.Create returned %+v, expected %+v", net, expected) - } -} - -func TestNetworkServiceHandler_Delete(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/v2/private-networks/net539626f0798d7", func(writer http.ResponseWriter, request *http.Request) { - fmt.Fprint(writer) - }) - - err := client.Network.Delete(ctx, "net539626f0798d7") - - if err != nil { - t.Errorf("Network.Delete returned %+v, expected %+v", err, nil) - } -} - -func TestNetworkServiceHandler_List(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/v2/private-networks", func(writer http.ResponseWriter, request *http.Request) { - response := ` - { - "networks": [{ - "id": "net539626f0798d7", - "date_created": "2017-08-25 12:23:45", - "region": "ewr", - "description": "test1", - "v4_subnet": "10.99.0.0", - "v4_subnet_mask": 24 - }] - } - ` - fmt.Fprint(writer, response) - }) - - networks, _, _, err := client.Network.List(ctx, nil) - - if err != nil { - t.Errorf("Network.List returned error: %v", err) - } - - expected := []Network{ - { - NetworkID: "net539626f0798d7", - Region: "ewr", - Description: "test1", - V4Subnet: "10.99.0.0", - V4SubnetMask: 24, - DateCreated: "2017-08-25 12:23:45", - }, - } - - if !reflect.DeepEqual(networks, expected) { - t.Errorf("Network.List returned %+v, expected %+v", networks, expected) - } -} - -func TestNetworkServiceHandler_Update(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/v2/private-networks/net539626f0798d7", func(writer http.ResponseWriter, request *http.Request) { - fmt.Fprint(writer) - }) - - err := client.Network.Update(ctx, "net539626f0798d7", "update") - - if err != nil { - t.Errorf("Network.Update returned %+v, expected %+v", err, nil) - } -} - -func TestNetworkServiceHandler_Get(t *testing.T) { - setup() - defer teardown() - - mux.HandleFunc("/v2/private-networks/net539626f0798d7", func(writer http.ResponseWriter, request *http.Request) { - req := `{"network": {"id": "cb676a46-66fd-4dfb-b839-443f2e6c0b60","date_created": "2020-10-10T01:56:20+00:00","region": "ewr","description": "sample desc","v4_subnet": "10.99.0.0","v4_subnet_mask": 24}}` - fmt.Fprint(writer, req) - }) - - network, _, err := client.Network.Get(ctx, "net539626f0798d7") - if err != nil { - t.Errorf("Network.Get returned %+v, expected %+v", err, nil) - } - - expected := &Network{ - NetworkID: "cb676a46-66fd-4dfb-b839-443f2e6c0b60", - Region: "ewr", - Description: "sample desc", - V4Subnet: "10.99.0.0", - V4SubnetMask: 24, - DateCreated: "2020-10-10T01:56:20+00:00", - } - - if !reflect.DeepEqual(network, expected) { - t.Errorf("Instance.Get returned %+v, expected %+v", network, expected) - } -} diff --git a/vpc.go b/vpc.go index 1de69f8..a221d63 100644 --- a/vpc.go +++ b/vpc.go @@ -1,4 +1,4 @@ -package govultr //nolint:dupl +package govultr import ( "context"