Skip to content

Commit

Permalink
Support new tags from the API (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
optik-aper authored May 4, 2022
1 parent e8b1787 commit cdc2ecc
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 106 deletions.
60 changes: 33 additions & 27 deletions bare_metal_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,31 @@ type BareMetalServerServiceHandler struct {

// BareMetalServer represents a Bare Metal server on Vultr
type BareMetalServer struct {
ID string `json:"id"`
Os string `json:"os"`
RAM string `json:"ram"`
Disk string `json:"disk"`
MainIP string `json:"main_ip"`
CPUCount int `json:"cpu_count"`
Region string `json:"region"`
DefaultPassword string `json:"default_password"`
DateCreated string `json:"date_created"`
Status string `json:"status"`
NetmaskV4 string `json:"netmask_v4"`
GatewayV4 string `json:"gateway_v4"`
Plan string `json:"plan"`
V6Network string `json:"v6_network"`
V6MainIP string `json:"v6_main_ip"`
V6NetworkSize int `json:"v6_network_size"`
MacAddress int `json:"mac_address"`
Label string `json:"label"`
Tag string `json:"tag"`
OsID int `json:"os_id"`
AppID int `json:"app_id"`
ImageID string `json:"image_id"`
Features []string `json:"features"`
ID string `json:"id"`
Os string `json:"os"`
RAM string `json:"ram"`
Disk string `json:"disk"`
MainIP string `json:"main_ip"`
CPUCount int `json:"cpu_count"`
Region string `json:"region"`
DefaultPassword string `json:"default_password"`
DateCreated string `json:"date_created"`
Status string `json:"status"`
NetmaskV4 string `json:"netmask_v4"`
GatewayV4 string `json:"gateway_v4"`
Plan string `json:"plan"`
V6Network string `json:"v6_network"`
V6MainIP string `json:"v6_main_ip"`
V6NetworkSize int `json:"v6_network_size"`
MacAddress int `json:"mac_address"`
Label string `json:"label"`
// Deprecated: Tag should no longer be used. Instead, use Tags.
Tag string `json:"tag"`
OsID int `json:"os_id"`
AppID int `json:"app_id"`
ImageID string `json:"image_id"`
Features []string `json:"features"`
Tags []string `json:"tags"`
}

// BareMetalCreate represents the optional parameters that can be set when creating a Bare Metal server
Expand All @@ -85,9 +87,11 @@ type BareMetalCreate struct {
UserData string `json:"user_data,omitempty"`
ActivationEmail *bool `json:"activation_email,omitempty"`
Hostname string `json:"hostname,omitempty"`
Tag string `json:"tag,omitempty"`
ReservedIPv4 string `json:"reserved_ipv4,omitempty"`
PersistentPxe *bool `json:"persistent_pxe,omitempty"`
// Deprecated: Tag should no longer be used. Instead, use Tags.
Tag string `json:"tag,omitempty"`
ReservedIPv4 string `json:"reserved_ipv4,omitempty"`
PersistentPxe *bool `json:"persistent_pxe,omitempty"`
Tags []string `json:"tags"`
}

// BareMetalUpdate represents the optional parameters that can be set when updating a Bare Metal server
Expand All @@ -98,7 +102,9 @@ type BareMetalUpdate struct {
AppID int `json:"app_id,omitempty"`
ImageID string `json:"image_id,omitempty"`
UserData string `json:"user_data,omitempty"`
Tag string `json:"tag,omitempty"`
// Deprecated: Tag should no longer be used. Instead, use Tags.
Tag string `json:"tag,omitempty"`
Tags []string `json:"tags"`
}

// BareMetalServerBandwidth represents bandwidth information for a Bare Metal server
Expand Down
28 changes: 14 additions & 14 deletions bare_metal_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestBareMetalServerServiceHandler_GetServer(t *testing.T) {
"v6_network_size": 64,
"mac_address": 2199756823533,
"label": "my label",
"tag": "my tag",
"tags": ["my tag"],
"os_id": 127,
"app_id": 0
}
Expand Down Expand Up @@ -64,7 +64,7 @@ func TestBareMetalServerServiceHandler_GetServer(t *testing.T) {
V6NetworkSize: 64,
MacAddress: 2199756823533,
Label: "my label",
Tag: "my tag",
Tags: []string{"my tag"},
OsID: 127,
AppID: 0,
}
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestBareMetalServerServiceHandler_Create(t *testing.T) {
"v6_network_size": 64,
"mac_address": 0,
"label": "go-bm-test",
"tag": "my tag",
"tags": ["my tag"],
"os_id": 127,
"app_id": 0
}
Expand All @@ -121,7 +121,7 @@ func TestBareMetalServerServiceHandler_Create(t *testing.T) {
UserData: "echo Hello World",
ActivationEmail: BoolToBoolPtr(true),
Hostname: "test",
Tag: "go-test",
Tags: []string{"my tag"},
ReservedIPv4: "111.111.111.111",
PersistentPxe: BoolToBoolPtr(true),
}
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestBareMetalServerServiceHandler_Create(t *testing.T) {
V6MainIP: "2001:DB8:9000::100",
V6NetworkSize: 64,
Label: "go-bm-test",
Tag: "my tag",
Tags: []string{"my tag"},
MacAddress: 0,
OsID: 127,
Region: "ewr",
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestBareMetalServerServiceHandler_Update(t *testing.T) {
"v6_main_ip": "2001:DB8:9000::100",
"v6_network_size": 64,
"label": "my new label",
"tag": "my tag",
"tags": ["my tag"],
"os_id": 127,
"app_id": 0
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestBareMetalServerServiceHandler_Update(t *testing.T) {
V6MainIP: "2001:DB8:9000::100",
V6NetworkSize: 64,
Label: "my new label",
Tag: "my tag",
Tags: []string{"my tag"},
OsID: 127,
Region: "ewr",
AppID: 0,
Expand Down Expand Up @@ -272,7 +272,7 @@ func TestBareMetalServerServiceHandler_List(t *testing.T) {
"v6_network_size": 64,
"mac_address": 2199756823533,
"label": "my label",
"tag": "my tag",
"tags": ["my tag"],
"os_id": 127,
"app_id": 0
}]
Expand Down Expand Up @@ -306,7 +306,7 @@ func TestBareMetalServerServiceHandler_List(t *testing.T) {
V6NetworkSize: 64,
MacAddress: 2199756823533,
Label: "my label",
Tag: "my tag",
Tags: []string{"my tag"},
OsID: 127,
AppID: 0,
},
Expand Down Expand Up @@ -500,7 +500,7 @@ func TestBareMetalServerServiceHandler_Reinstall(t *testing.T) {
"v6_main_ip": "2001:DB8:9000::100",
"v6_network_size": 64,
"label": "go-bm-test",
"tag": "my tag",
"tags": ["my tag"],
"os_id": 127,
"app_id": 0
}
Expand Down Expand Up @@ -531,7 +531,7 @@ func TestBareMetalServerServiceHandler_Reinstall(t *testing.T) {
V6MainIP: "2001:DB8:9000::100",
V6NetworkSize: 64,
Label: "go-bm-test",
Tag: "my tag",
Tags: []string{"my tag"},
OsID: 127,
Region: "ewr",
AppID: 0,
Expand Down Expand Up @@ -733,7 +733,7 @@ func TestBareMetalServerServiceHandler_CreateMarketplaceImage(t *testing.T) {
"v6_network_size": 64,
"mac_address": 0,
"label": "go-bm-test",
"tag": "my tag",
"tags": ["my tag"],
"os_id": 127,
"app_id": 0,
"image_id": "test"
Expand All @@ -755,7 +755,7 @@ func TestBareMetalServerServiceHandler_CreateMarketplaceImage(t *testing.T) {
UserData: "echo Hello World",
ActivationEmail: BoolToBoolPtr(true),
Hostname: "test",
Tag: "go-test",
Tags: []string{"go-test"},
ReservedIPv4: "111.111.111.111",
PersistentPxe: BoolToBoolPtr(true),
ImageID: "test",
Expand Down Expand Up @@ -784,7 +784,7 @@ func TestBareMetalServerServiceHandler_CreateMarketplaceImage(t *testing.T) {
V6MainIP: "2001:DB8:9000::100",
V6NetworkSize: 64,
Label: "go-bm-test",
Tag: "my tag",
Tags: []string{"my tag"},
MacAddress: 0,
OsID: 127,
Region: "ewr",
Expand Down
106 changes: 56 additions & 50 deletions instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,35 +75,37 @@ type InstanceServiceHandler struct {

// Instance represents a VPS
type Instance struct {
ID string `json:"id"`
Os string `json:"os"`
RAM int `json:"ram"`
Disk int `json:"disk"`
Plan string `json:"plan"`
MainIP string `json:"main_ip"`
VCPUCount int `json:"vcpu_count"`
Region string `json:"region"`
DefaultPassword string `json:"default_password,omitempty"`
DateCreated string `json:"date_created"`
Status string `json:"status"`
AllowedBandwidth int `json:"allowed_bandwidth"`
NetmaskV4 string `json:"netmask_v4"`
GatewayV4 string `json:"gateway_v4"`
PowerStatus string `json:"power_status"`
ServerStatus string `json:"server_status"`
V6Network string `json:"v6_network"`
V6MainIP string `json:"v6_main_ip"`
V6NetworkSize int `json:"v6_network_size"`
Label string `json:"label"`
InternalIP string `json:"internal_ip"`
KVM string `json:"kvm"`
Tag string `json:"tag"`
OsID int `json:"os_id"`
AppID int `json:"app_id"`
ImageID string `json:"image_id"`
FirewallGroupID string `json:"firewall_group_id"`
Features []string `json:"features"`
Hostname string `json:"hostname"`
ID string `json:"id"`
Os string `json:"os"`
RAM int `json:"ram"`
Disk int `json:"disk"`
Plan string `json:"plan"`
MainIP string `json:"main_ip"`
VCPUCount int `json:"vcpu_count"`
Region string `json:"region"`
DefaultPassword string `json:"default_password,omitempty"`
DateCreated string `json:"date_created"`
Status string `json:"status"`
AllowedBandwidth int `json:"allowed_bandwidth"`
NetmaskV4 string `json:"netmask_v4"`
GatewayV4 string `json:"gateway_v4"`
PowerStatus string `json:"power_status"`
ServerStatus string `json:"server_status"`
V6Network string `json:"v6_network"`
V6MainIP string `json:"v6_main_ip"`
V6NetworkSize int `json:"v6_network_size"`
Label string `json:"label"`
InternalIP string `json:"internal_ip"`
KVM string `json:"kvm"`
// Deprecated: Tag should no longer be used. Instead, use Tags.
Tag string `json:"tag"`
OsID int `json:"os_id"`
AppID int `json:"app_id"`
ImageID string `json:"image_id"`
FirewallGroupID string `json:"firewall_group_id"`
Features []string `json:"features"`
Hostname string `json:"hostname"`
Tags []string `json:"tags"`
}

type instanceBase struct {
Expand Down Expand Up @@ -229,20 +231,22 @@ type Upgrades struct {

// InstanceCreateReq struct used to create an instance.
type InstanceCreateReq struct {
Region string `json:"region,omitempty"`
Plan string `json:"plan,omitempty"`
Label string `json:"label,omitempty"`
Tag string `json:"tag,omitempty"`
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"`
Region string `json:"region,omitempty"`
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"`
// 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.
Expand All @@ -259,13 +263,15 @@ type InstanceCreateReq struct {

// InstanceUpdateReq struct used to update an instance.
type InstanceUpdateReq struct {
Plan string `json:"plan,omitempty"`
Label string `json:"label,omitempty"`
Tag string `json:"tag,omitempty"`
OsID int `json:"os_id,omitempty"`
AppID int `json:"app_id,omitempty"`
ImageID string `json:"image_id,omitempty"`
EnableIPv6 *bool `json:"enable_ipv6,omitempty"`
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.
Expand Down
Loading

0 comments on commit cdc2ecc

Please sign in to comment.