Skip to content

Commit

Permalink
Merge pull request #13 from ddymko/vc2z-changes
Browse files Browse the repository at this point in the history
Vc2z changes
  • Loading branch information
ddymko authored Jun 12, 2019
2 parents 166608d + f9540d1 commit 04b4a42
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 31 deletions.
4 changes: 2 additions & 2 deletions bare_metal_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type BareMetalServer struct {
RAM string `json:"ram"`
Disk string `json:"disk"`
MainIP string `json:"main_ip"`
CPUCount int `json:"cpu_count"`
CPUs int `json:"cpu_count"`
Location string `json:"location"`
RegionID int `json:"DCID"`
DefaultPassword string `json:"default_password"`
Expand Down Expand Up @@ -114,7 +114,7 @@ func (b *BareMetalServer) UnmarshalJSON(data []byte) error {
if err != nil {
return err
}
b.CPUCount = cpu
b.CPUs = cpu

region, err := b.unmarshalInt(fmt.Sprintf("%v", v["DCID"]))
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions bare_metal_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func TestBareMetalServerServiceHandler_List(t *testing.T) {
RAM: "65536 MB",
Disk: "2x 240 GB SSD",
MainIP: "203.0.113.10",
CPUCount: 1,
CPUs: 1,
Location: "New Jersey",
RegionID: 1,
DefaultPassword: "ab81u!ryranq",
Expand Down Expand Up @@ -324,7 +324,7 @@ func TestBareMetalServerServiceHandler_ListByLabel(t *testing.T) {
RAM: "65536 MB",
Disk: "2x 240 GB SSD",
MainIP: "203.0.113.10",
CPUCount: 1,
CPUs: 1,
Location: "New Jersey",
RegionID: 1,
DefaultPassword: "ab81u!ryranq",
Expand Down Expand Up @@ -404,7 +404,7 @@ func TestBareMetalServerServiceHandler_ListByMainIP(t *testing.T) {
RAM: "65536 MB",
Disk: "2x 240 GB SSD",
MainIP: "203.0.113.10",
CPUCount: 1,
CPUs: 1,
Location: "New Jersey",
RegionID: 1,
DefaultPassword: "ab81u!ryranq",
Expand Down Expand Up @@ -484,7 +484,7 @@ func TestBareMetalServerServiceHandler_ListByTag(t *testing.T) {
RAM: "65536 MB",
Disk: "2x 240 GB SSD",
MainIP: "203.0.113.10",
CPUCount: 1,
CPUs: 1,
Location: "New Jersey",
RegionID: 1,
DefaultPassword: "ab81u!ryranq",
Expand Down Expand Up @@ -561,7 +561,7 @@ func TestBareMetalServerServiceHandler_GetServer(t *testing.T) {
RAM: "65536 MB",
Disk: "2x 240 GB SSD",
MainIP: "203.0.113.10",
CPUCount: 1,
CPUs: 1,
Location: "New Jersey",
RegionID: 1,
DefaultPassword: "ab81u!ryranq",
Expand Down
10 changes: 5 additions & 5 deletions firewall_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
type FireWallRuleService interface {
Create(ctx context.Context, groupID, protocol, port, network, notes string) (*FirewallRule, error)
Delete(ctx context.Context, groupID, ruleID string) error
List(ctx context.Context, groupID, ipType string) ([]FirewallRule, error)
GetAll(ctx context.Context, groupID string) ([]FirewallRule, error)
ListByIPType(ctx context.Context, groupID, ipType string) ([]FirewallRule, error)
List(ctx context.Context, groupID string) ([]FirewallRule, error)
}

// FireWallRuleServiceHandler handles interaction with the firewall rule methods for the Vultr API
Expand Down Expand Up @@ -188,7 +188,7 @@ func (f *FireWallRuleServiceHandler) Delete(ctx context.Context, groupID, ruleID

// List will list the current firewall rules in a firewall group.
// ipType values that can be passed in are "v4", "v6"
func (f *FireWallRuleServiceHandler) List(ctx context.Context, groupID, ipType string) ([]FirewallRule, error) {
func (f *FireWallRuleServiceHandler) ListByIPType(ctx context.Context, groupID, ipType string) ([]FirewallRule, error) {

uri := "/v1/firewall/rule_list"

Expand Down Expand Up @@ -219,8 +219,8 @@ func (f *FireWallRuleServiceHandler) List(ctx context.Context, groupID, ipType s
return firewallRule, nil
}

// GetAll will return both ipv4 an ipv6 firewall rules that are defined within a firewall group
func (f *FireWallRuleServiceHandler) GetAll(ctx context.Context, groupID string) ([]FirewallRule, error) {
// List will return both ipv4 an ipv6 firewall rules that are defined within a firewall group
func (f *FireWallRuleServiceHandler) List(ctx context.Context, groupID string) ([]FirewallRule, error) {
uri := "/v1/firewall/rule_list"

req, err := f.client.NewRequest(ctx, http.MethodGet, uri, nil)
Expand Down
18 changes: 9 additions & 9 deletions firewall_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ func TestFireWallRuleServiceHandler_GetAll(t *testing.T) {
fmt.Fprint(writer, response)
})

firewallRule, err := client.FirewallRule.List(ctx, "12345", "v4")
firewallRule, err := client.FirewallRule.ListByIPType(ctx, "12345", "v4")
if err != nil {
t.Errorf("FirewallRule.List returned error: %v", err)
t.Errorf("FirewallRule.ListByIPType returned error: %v", err)
}

expected := []FirewallRule{
Expand All @@ -83,12 +83,12 @@ func TestFireWallRuleServiceHandler_GetAll(t *testing.T) {
}

if !reflect.DeepEqual(firewallRule, expected) {
t.Errorf("FirewallRule.List returned %+v, expected %+v", firewallRule, expected)
t.Errorf("FirewallRule.ListByIPType returned %+v, expected %+v", firewallRule, expected)
}

firewallRule, err = client.FirewallRule.List(ctx, "12345", "v6")
firewallRule, err = client.FirewallRule.ListByIPType(ctx, "12345", "v6")
if err != nil {
t.Errorf("FirewallRule.List returned error: %v", err)
t.Errorf("FirewallRule.ListByIPType returned error: %v", err)
}

expected = []FirewallRule{
Expand All @@ -101,7 +101,7 @@ func TestFireWallRuleServiceHandler_GetAll(t *testing.T) {
}

if !reflect.DeepEqual(firewallRule, expected) {
t.Errorf("FirewallRule.List returned %+v, expected %+v", firewallRule, expected)
t.Errorf("FirewallRule.ListByIPType returned %+v, expected %+v", firewallRule, expected)
}
}

Expand All @@ -114,9 +114,9 @@ func TestFireWallRuleServiceHandler_List(t *testing.T) {
fmt.Fprint(writer, response)
})

firewallRule, err := client.FirewallRule.GetAll(ctx, "12345")
firewallRule, err := client.FirewallRule.List(ctx, "12345")
if err != nil {
t.Errorf("FirewallRule.GetAll returned error: %v", err)
t.Errorf("FirewallRule.List returned error: %v", err)
}

_, ip, _ := net.ParseCIDR("10.0.0.0/32")
Expand All @@ -131,6 +131,6 @@ func TestFireWallRuleServiceHandler_List(t *testing.T) {
}

if !reflect.DeepEqual(firewallRule, expected) {
t.Errorf("FirewallRule.GetAll returned %+v, expected %+v", firewallRule, expected)
t.Errorf("FirewallRule.List returned %+v, expected %+v", firewallRule, expected)
}
}
34 changes: 30 additions & 4 deletions plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type PlanService interface {
GetBareMetalList(ctx context.Context) ([]BareMetalPlan, error)
GetVc2List(ctx context.Context) ([]VCPlan, error)
GetVdc2List(ctx context.Context) ([]VCPlan, error)
GetVc2zList(ctx context.Context) ([]VCPlan, error)
}

// PlanServiceHandler handles interaction with the Plans methods for the Vultr API
Expand All @@ -23,7 +24,7 @@ type PlanServiceHandler struct {
type Plan struct {
VpsID int `json:"VPSPLANID,string"`
Name string `json:"name"`
VCPUCount int `json:"vcpu_count,string"`
VCPUs int `json:"vcpu_count,string"`
RAM string `json:"ram"`
Disk string `json:"disk"`
Bandwidth string `json:"bandwidth"`
Expand All @@ -39,7 +40,7 @@ type Plan struct {
type BareMetalPlan struct {
BareMetalID string `json:"METALPLANID"`
Name string `json:"name"`
CPUCount int `json:"cpu_count"`
CPUs int `json:"cpu_count"`
CPUModel string `json:"cpu_model"`
RAM int `json:"ram"`
Disk string `json:"disk"`
Expand All @@ -54,12 +55,12 @@ type BareMetalPlan struct {
type VCPlan struct {
VpsID string `json:"VPSPLANID"`
Name string `json:"name"`
VCPUCount string `json:"vcpu_count"`
VCPUs string `json:"vcpu_count"`
RAM string `json:"ram"`
Disk string `json:"disk"`
Bandwidth string `json:"bandwidth"`
BandwidthGB string `json:"bandwidth_gb"`
Cost string `json:"price_per_month"`
Price string `json:"price_per_month"`
PlanType string `json:"plan_type"`
}

Expand Down Expand Up @@ -171,3 +172,28 @@ func (p *PlanServiceHandler) GetVdc2List(ctx context.Context) ([]VCPlan, error)

return vdc2, nil
}

// GetVc2zList Retrieve a list of all active vc2z plans (high frequency)
func (p *PlanServiceHandler) GetVc2zList(ctx context.Context) ([]VCPlan, error) {
uri := "/v1/plans/list_vc2z"

req, err := p.Client.NewRequest(ctx, http.MethodGet, uri, nil)

if err != nil {
return nil, err
}

var vc2zMap map[string]VCPlan
err = p.Client.DoWithContext(ctx, req, &vc2zMap)

if err != nil {
return nil, err
}

var vc2z []VCPlan
for _, p := range vc2zMap {
vc2z = append(vc2z, p)
}

return vc2z, nil
}
45 changes: 39 additions & 6 deletions plans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestPlanServiceHandler_List(t *testing.T) {
expected := []Plan{{
VpsID: 201,
Name: "1024 MB RAM,25 GB SSD,1.00 TB BW",
VCPUCount: 1,
VCPUs: 1,
RAM: "1024",
Disk: "25",
Price: "5.00",
Expand Down Expand Up @@ -60,7 +60,7 @@ func TestPlanServiceHandler_GetBareMetalList(t *testing.T) {
{
BareMetalID: "99",
Name: "32768 MB RAM,4x 240 GB SSD,1.00 TB BW",
CPUCount: 12,
CPUs: 12,
CPUModel: "E-2186G",
RAM: 32768,
Disk: "4x 240 GB SSD",
Expand Down Expand Up @@ -96,12 +96,12 @@ func TestPlanServiceHandler_GetVc2List(t *testing.T) {
{
VpsID: "201",
Name: "1024 MB RAM,25 GB SSD,1.00 TB BW",
VCPUCount: "1",
VCPUs: "1",
RAM: "1024",
Disk: "25",
Bandwidth: "1.00",
BandwidthGB: "1024",
Cost: "5.00",
Price: "5.00",
PlanType: "SSD",
},
}
Expand Down Expand Up @@ -129,12 +129,12 @@ func TestPlanServiceHandler_GetVdc2List(t *testing.T) {
{
VpsID: "115",
Name: "8192 MB RAM,110 GB SSD,10.00 TB BW",
VCPUCount: "2",
VCPUs: "2",
RAM: "8192",
Disk: "110",
Bandwidth: "10.00",
BandwidthGB: "10240",
Cost: "60.00",
Price: "60.00",
PlanType: "DEDICATED",
},
}
Expand All @@ -143,3 +143,36 @@ func TestPlanServiceHandler_GetVdc2List(t *testing.T) {
t.Errorf("Plan.GetVdc2List returned %+v, expected %+v", vdc2, expected)
}
}

func TestPlanServiceHandler_GetVc2zList(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/v1/plans/list_vc2z", func(writer http.ResponseWriter, request *http.Request) {
response := `{ "401": {"VPSPLANID": "401","name": "2048 MB RAM,64 GB SSD,2.00 TB BW","vcpu_count": "1","ram": "2048","disk": "64","bandwidth": "2.00","price_per_month": "12.00","plan_type": "HIGHFREQUENCY"}}`
fmt.Fprint(writer, response)
})

vc2z, err := client.Plan.GetVc2zList(ctx)

if err != nil {
t.Errorf("Plan.GetVc2zList returned %+v", err)
}

expected := []VCPlan{
{
VpsID: "401",
Name: "2048 MB RAM,64 GB SSD,2.00 TB BW",
VCPUs: "1",
RAM: "2048",
Disk: "64",
Bandwidth: "2.00",
Price: "12.00",
PlanType: "HIGHFREQUENCY",
},
}

if !reflect.DeepEqual(vc2z, expected) {
t.Errorf("Plan.GetVc2zList returned %+v, expected %+v", vc2z, expected)
}
}

0 comments on commit 04b4a42

Please sign in to comment.