Skip to content

Commit

Permalink
Remove deprecated private network functionality (#324)
Browse files Browse the repository at this point in the history
* Remove deprecated private network functionality

* Remove nolint directive on vpc
  • Loading branch information
optik-aper committed Sep 19, 2024
1 parent 17aedc2 commit 80900b6
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 526 deletions.
27 changes: 12 additions & 15 deletions govultr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
165 changes: 40 additions & 125 deletions instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -257,63 +237,53 @@ 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.
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
Expand Down Expand Up @@ -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)
Expand Down
69 changes: 0 additions & 69 deletions instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 2 additions & 6 deletions load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 80900b6

Please sign in to comment.