Skip to content

Commit 8d99acf

Browse files
Add VX1/bootable block support and minor API updates (#440)
1 parent b2df304 commit 8d99acf

6 files changed

Lines changed: 98 additions & 61 deletions

File tree

block_storage.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,22 @@ type BlockStorageServiceHandler struct {
2828

2929
// BlockStorage represents Vultr Block-Storage
3030
type BlockStorage struct {
31-
ID string `json:"id"`
32-
Cost float32 `json:"cost"`
33-
Status string `json:"status"`
34-
SizeGB int `json:"size_gb"`
35-
Region string `json:"region"`
36-
DateCreated string `json:"date_created"`
37-
AttachedToInstance string `json:"attached_to_instance"`
38-
Label string `json:"label"`
39-
MountID string `json:"mount_id"`
40-
BlockType string `json:"block_type"`
41-
OSID int `json:"os_id"`
42-
Bootable bool `json:"bootable"`
31+
ID string `json:"id"`
32+
DateCreated string `json:"date_created"`
33+
Cost float32 `json:"cost"`
34+
PendingCharges float32 `json:"pending_charges"`
35+
Status string `json:"status"`
36+
SizeGB int `json:"size_gb"`
37+
Region string `json:"region"`
38+
AttachedToInstance string `json:"attached_to_instance"`
39+
AttachedToInstanceIP string `json:"attached_to_instance_ip"`
40+
AttachedToInstanceLabel string `json:"attached_to_instance_label"`
41+
Label string `json:"label"`
42+
MountID string `json:"mount_id"`
43+
BlockType string `json:"block_type"`
44+
OSID int `json:"os_id"`
45+
SnapshotID string `json:"snapshot_id"`
46+
Bootable bool `json:"bootable"`
4347
}
4448

4549
// BlockStorageCreate struct is used for creating Block Storage.

block_storage_test.go

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func TestBlockStorageServiceHandler_Create(t *testing.T) {
1212
defer teardown()
1313

1414
mux.HandleFunc("/v2/blocks", func(writer http.ResponseWriter, request *http.Request) {
15-
response := `{"block":{"id":"123456","cost":10,"status":"active","size_gb":100,"region":"ewr","attached_to_instance":"","date_created":"01-01-1960","label":"mylabel", "mount_id": "ewr-123abc", "block_type": "test"}}`
15+
response := `{"block":{"id":"123456","cost":10,"pending_charges":2.5,"status":"active","size_gb":100,"region":"ewr","attached_to_instance":"","attached_to_instance_ip":"","attached_to_instance_label":"","date_created":"01-01-1960","label":"mylabel", "mount_id": "ewr-123abc", "block_type": "test", "os_id": 0, "snapshot_id": "", "bootable": false}}`
1616
fmt.Fprint(writer, response)
1717
})
1818
blockReq := &BlockStorageCreate{
@@ -27,16 +27,22 @@ func TestBlockStorageServiceHandler_Create(t *testing.T) {
2727
}
2828

2929
expected := &BlockStorage{
30-
ID: "123456",
31-
Cost: 10,
32-
Status: "active",
33-
SizeGB: 100,
34-
Region: "ewr",
35-
DateCreated: "01-01-1960",
36-
AttachedToInstance: "",
37-
Label: "mylabel",
38-
MountID: "ewr-123abc",
39-
BlockType: "test",
30+
ID: "123456",
31+
Cost: 10,
32+
PendingCharges: 2.5,
33+
Status: "active",
34+
SizeGB: 100,
35+
Region: "ewr",
36+
DateCreated: "01-01-1960",
37+
AttachedToInstance: "",
38+
AttachedToInstanceIP: "",
39+
AttachedToInstanceLabel: "",
40+
Label: "mylabel",
41+
MountID: "ewr-123abc",
42+
BlockType: "test",
43+
OSID: 0,
44+
SnapshotID: "",
45+
Bootable: false,
4046
}
4147

4248
if !reflect.DeepEqual(blockStorage, expected) {
@@ -49,7 +55,7 @@ func TestBlockStorageServiceHandler_Get(t *testing.T) {
4955
defer teardown()
5056

5157
mux.HandleFunc("/v2/blocks/123456", func(writer http.ResponseWriter, request *http.Request) {
52-
response := `{"block":{"id":"123456","cost":10,"status":"active","size_gb":100,"region":"ewr","attached_to_instance":"","date_created":"01-01-1960","label":"mylabel", "mount_id": "123abc", "block_type": "test"}}`
58+
response := `{"block":{"id":"123456","cost":10,"pending_charges":2.5,"status":"active","size_gb":100,"region":"ewr","attached_to_instance":"","attached_to_instance_ip":"","attached_to_instance_label":"","date_created":"01-01-1960","label":"mylabel", "mount_id": "ewr-123abc", "block_type": "test", "os_id": 0, "snapshot_id": "", "bootable": false}}`
5359
fmt.Fprint(writer, response)
5460
})
5561

@@ -59,20 +65,26 @@ func TestBlockStorageServiceHandler_Get(t *testing.T) {
5965
}
6066

6167
expected := &BlockStorage{
62-
ID: "123456",
63-
Cost: 10,
64-
Status: "active",
65-
SizeGB: 100,
66-
Region: "ewr",
67-
DateCreated: "01-01-1960",
68-
AttachedToInstance: "",
69-
Label: "mylabel",
70-
MountID: "123abc",
71-
BlockType: "test",
68+
ID: "123456",
69+
Cost: 10,
70+
PendingCharges: 2.5,
71+
Status: "active",
72+
SizeGB: 100,
73+
Region: "ewr",
74+
DateCreated: "01-01-1960",
75+
AttachedToInstance: "",
76+
AttachedToInstanceIP: "",
77+
AttachedToInstanceLabel: "",
78+
Label: "mylabel",
79+
MountID: "ewr-123abc",
80+
BlockType: "test",
81+
OSID: 0,
82+
SnapshotID: "",
83+
Bootable: false,
7284
}
7385

7486
if !reflect.DeepEqual(blockStorage, expected) {
75-
t.Errorf("BlockStorage.Create returned %+v, expected %+v", blockStorage, expected)
87+
t.Errorf("BlockStorage.Get returned %+v, expected %+v", blockStorage, expected)
7688
}
7789
}
7890

@@ -89,7 +101,7 @@ func TestBlockStorageServiceHandler_Update(t *testing.T) {
89101
}
90102
err := client.BlockStorage.Update(ctx, "123456", blockUpdate)
91103
if err != nil {
92-
t.Errorf("BlockStorage.SetLabel returned %+v, expected %+v", err, nil)
104+
t.Errorf("BlockStorage.Update returned %+v, expected %+v", err, nil)
93105
}
94106
}
95107

@@ -112,32 +124,38 @@ func TestBlockStorageServiceHandler_List(t *testing.T) {
112124
defer teardown()
113125

114126
mux.HandleFunc("/v2/blocks", func(writer http.ResponseWriter, request *http.Request) {
115-
response := `{"blocks":[{"id":"123456","cost":10,"status":"active","size_gb":100,"region":"ewr","attached_to_instance":"","date_created":"01-01-1960","label":"mylabel", "mount_id": "123abc", "block_type": "test"}],"meta":{"total":1,"links":{"next":"thisismycusror","prev":""}}}`
127+
response := `{"blocks":[{"id":"123456","cost":10,"pending_charges":2.5,"status":"active","size_gb":100,"region":"ewr","attached_to_instance":"","attached_to_instance_ip":"","attached_to_instance_label":"","date_created":"01-01-1960","label":"mylabel", "mount_id": "ewr-123abc", "block_type": "test", "os_id": 0, "snapshot_id": "", "bootable": false}],"meta":{"total":1,"links":{"next":"thisismycusror","prev":""}}}`
116128
fmt.Fprint(writer, response)
117129
})
118130

119131
blockStorage, meta, _, err := client.BlockStorage.List(ctx, nil)
120132
if err != nil {
121-
t.Errorf("BlockStorage.Create returned error: %v", err)
133+
t.Errorf("BlockStorage.List returned error: %v", err)
122134
}
123135

124136
expected := []BlockStorage{
125137
{
126-
ID: "123456",
127-
Cost: 10,
128-
Status: "active",
129-
SizeGB: 100,
130-
Region: "ewr",
131-
DateCreated: "01-01-1960",
132-
AttachedToInstance: "",
133-
Label: "mylabel",
134-
MountID: "123abc",
135-
BlockType: "test",
138+
ID: "123456",
139+
Cost: 10,
140+
PendingCharges: 2.5,
141+
Status: "active",
142+
SizeGB: 100,
143+
Region: "ewr",
144+
DateCreated: "01-01-1960",
145+
AttachedToInstance: "",
146+
AttachedToInstanceIP: "",
147+
AttachedToInstanceLabel: "",
148+
Label: "mylabel",
149+
MountID: "ewr-123abc",
150+
BlockType: "test",
151+
OSID: 0,
152+
SnapshotID: "",
153+
Bootable: false,
136154
},
137155
}
138156

139157
if !reflect.DeepEqual(blockStorage, expected) {
140-
t.Errorf("BlockStorage.Create returned %+v, expected %+v", blockStorage, expected)
158+
t.Errorf("BlockStorage.List returned %+v, expected %+v", blockStorage, expected)
141159
}
142160

143161
expectedMeta := &Meta{
@@ -149,7 +167,7 @@ func TestBlockStorageServiceHandler_List(t *testing.T) {
149167
}
150168

151169
if !reflect.DeepEqual(meta, expectedMeta) {
152-
t.Errorf("User.List meta returned %+v, expected %+v", meta, expectedMeta)
170+
t.Errorf("BlockStorage.List meta returned %+v, expected %+v", meta, expectedMeta)
153171
}
154172
}
155173

database.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ type Database struct {
165165
Status string `json:"status"`
166166
Label string `json:"label"`
167167
Tag string `json:"tag"`
168+
PendingCharges float32 `json:"pending_charges"`
168169
DBName string `json:"dbname,omitempty"`
169170
FerretDBCredentials *FerretDBCredentials `json:"ferretdb_credentials,omitempty"`
170171
Host string `json:"host"`

database_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func TestDatabaseServiceHandler_List(t *testing.T) {
2929
"status": "Running",
3030
"label": "testy-mc-testerton-the-8th",
3131
"tag": "bing bong",
32+
"pending_charges": 12.15,
3233
"dbname": "defaultdb",
3334
"host": "vultr-prod-2db1ff4d-9d78-4baa-b52e-ec2b166107bb-vultr-prod-85e0.vultrdb.com",
3435
"public_host": "public-vultr-prod-2db1ff4d-9d78-4baa-b52e-ec2b166107bb-vultr-pr.vultrdb.com",
@@ -68,6 +69,7 @@ func TestDatabaseServiceHandler_List(t *testing.T) {
6869
"status": "Running",
6970
"label": "testy-mc-testerton-the-7th",
7071
"tag": "",
72+
"pending_charges": 12.15,
7173
"dbname": "defaultdb",
7274
"host": "vultr-prod-87086a7d-4bc8-47ca-aa88-f88138d82772-vultr-prod-85e0.vultrdb.com",
7375
"public_host": "public-vultr-prod-87086a7d-4bc8-47ca-aa88-f88138d82772-vultr-pr.vultrdb.com",
@@ -132,6 +134,7 @@ func TestDatabaseServiceHandler_List(t *testing.T) {
132134
Status: "Running",
133135
Label: "testy-mc-testerton-the-7th",
134136
Tag: "",
137+
PendingCharges: 12.15,
135138
DBName: "defaultdb",
136139
Host: "vultr-prod-87086a7d-4bc8-47ca-aa88-f88138d82772-vultr-prod-85e0.vultrdb.com",
137140
PublicHost: "public-vultr-prod-87086a7d-4bc8-47ca-aa88-f88138d82772-vultr-pr.vultrdb.com",
@@ -167,6 +170,7 @@ func TestDatabaseServiceHandler_List(t *testing.T) {
167170
Status: "Running",
168171
Label: "testy-mc-testerton-the-8th",
169172
Tag: "bing bong",
173+
PendingCharges: 12.15,
170174
DBName: "defaultdb",
171175
Host: "vultr-prod-2db1ff4d-9d78-4baa-b52e-ec2b166107bb-vultr-prod-85e0.vultrdb.com",
172176
PublicHost: "public-vultr-prod-2db1ff4d-9d78-4baa-b52e-ec2b166107bb-vultr-pr.vultrdb.com",
@@ -332,6 +336,7 @@ func TestDatabaseServiceHandler_Get(t *testing.T) {
332336
"status": "Running",
333337
"label": "testy-mc-testerton-the-8th",
334338
"tag": "bing bong",
339+
"pending_charges": 12.15,
335340
"dbname": "defaultdb",
336341
"host": "vultr-prod-2db1ff4d-9d78-4baa-b52e-ec2b166107bb-vultr-prod-85e0.vultrdb.com",
337342
"public_host": "public-vultr-prod-2db1ff4d-9d78-4baa-b52e-ec2b166107bb-vultr-pr.vultrdb.com",
@@ -371,6 +376,7 @@ func TestDatabaseServiceHandler_Get(t *testing.T) {
371376
"status": "Running",
372377
"label": "testy-mc-testerton-the-7th",
373378
"tag": "",
379+
"pending_charges": 12.15,
374380
"dbname": "defaultdb",
375381
"host": "vultr-prod-87086a7d-4bc8-47ca-aa88-f88138d82772-vultr-prod-85e0.vultrdb.com",
376382
"public_host": "public-vultr-prod-87086a7d-4bc8-47ca-aa88-f88138d82772-vultr-pr.vultrdb.com",
@@ -431,6 +437,7 @@ func TestDatabaseServiceHandler_Get(t *testing.T) {
431437
Status: "Running",
432438
Label: "testy-mc-testerton-the-7th",
433439
Tag: "",
440+
PendingCharges: 12.15,
434441
DBName: "defaultdb",
435442
Host: "vultr-prod-87086a7d-4bc8-47ca-aa88-f88138d82772-vultr-prod-85e0.vultrdb.com",
436443
PublicHost: "public-vultr-prod-87086a7d-4bc8-47ca-aa88-f88138d82772-vultr-pr.vultrdb.com",
@@ -465,6 +472,7 @@ func TestDatabaseServiceHandler_Get(t *testing.T) {
465472
Status: "Running",
466473
Label: "testy-mc-testerton-the-8th",
467474
Tag: "bing bong",
475+
PendingCharges: 12.15,
468476
DBName: "defaultdb",
469477
Host: "vultr-prod-2db1ff4d-9d78-4baa-b52e-ec2b166107bb-vultr-prod-85e0.vultrdb.com",
470478
PublicHost: "public-vultr-prod-2db1ff4d-9d78-4baa-b52e-ec2b166107bb-vultr-pr.vultrdb.com",
@@ -510,6 +518,7 @@ func TestDatabaseServiceHandler_Update(t *testing.T) {
510518
"status": "Running",
511519
"label": "testy-mc-testerton-the-8th-part-2",
512520
"tag": "bing bong updated",
521+
"pending_charges": 12.15,
513522
"dbname": "defaultdb",
514523
"host": "vultr-prod-2db1ff4d-9d78-4baa-b52e-ec2b166107bb-vultr-prod-85e0.vultrdb.com",
515524
"public_host": "public-vultr-prod-2db1ff4d-9d78-4baa-b52e-ec2b166107bb-vultr-pr.vultrdb.com",
@@ -550,6 +559,7 @@ func TestDatabaseServiceHandler_Update(t *testing.T) {
550559
"status": "Running",
551560
"label": "testy-mc-testerton-the-7th",
552561
"tag": "",
562+
"pending_charges": 12.15,
553563
"dbname": "defaultdb",
554564
"host": "vultr-prod-87086a7d-4bc8-47ca-aa88-f88138d82772-vultr-prod-85e0.vultrdb.com",
555565
"public_host": "public-vultr-prod-87086a7d-4bc8-47ca-aa88-f88138d82772-vultr-pr.vultrdb.com",
@@ -618,6 +628,7 @@ func TestDatabaseServiceHandler_Update(t *testing.T) {
618628
Status: "Running",
619629
Label: "testy-mc-testerton-the-7th",
620630
Tag: "",
631+
PendingCharges: 12.15,
621632
DBName: "defaultdb",
622633
Host: "vultr-prod-87086a7d-4bc8-47ca-aa88-f88138d82772-vultr-prod-85e0.vultrdb.com",
623634
PublicHost: "public-vultr-prod-87086a7d-4bc8-47ca-aa88-f88138d82772-vultr-pr.vultrdb.com",
@@ -653,6 +664,7 @@ func TestDatabaseServiceHandler_Update(t *testing.T) {
653664
Status: "Running",
654665
Label: "testy-mc-testerton-the-8th-part-2",
655666
Tag: "bing bong updated",
667+
PendingCharges: 12.15,
656668
DBName: "defaultdb",
657669
Host: "vultr-prod-2db1ff4d-9d78-4baa-b52e-ec2b166107bb-vultr-prod-85e0.vultrdb.com",
658670
PublicHost: "public-vultr-prod-2db1ff4d-9d78-4baa-b52e-ec2b166107bb-vultr-pr.vultrdb.com",

regions.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ type RegionServiceHandler struct {
2424

2525
// Region represents a Vultr region
2626
type Region struct {
27-
ID string `json:"id"`
28-
City string `json:"city"`
29-
Country string `json:"country"`
30-
Continent string `json:"continent,omitempty"`
31-
Options []string `json:"options"`
27+
ID string `json:"id"`
28+
City string `json:"city"`
29+
Country string `json:"country"`
30+
Continent string `json:"continent,omitempty"`
31+
Options []string `json:"options"`
32+
Connectivity []string `json:"connectivity"`
3233
}
3334

3435
type regionBase struct {

regions_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func TestRegionServiceHandler_List(t *testing.T) {
1212
defer teardown()
1313

1414
mux.HandleFunc("/v2/regions", func(writer http.ResponseWriter, request *http.Request) {
15-
response := `{"regions":[{"id":"ams","city": "test", "country":"NL","continent":"Europe","options":["ddos_protection"]}],"meta":{"total":1,"links":{"next":"","prev":""}}}`
15+
response := `{"regions":[{"id":"ams","city": "test", "country":"NL","continent":"Europe","options":["ddos_protection"],"connectivity":["public_ip","nat_gateway"]}],"meta":{"total":1,"links":{"next":"","prev":""}}}`
1616
fmt.Fprint(writer, response)
1717
})
1818

@@ -24,11 +24,12 @@ func TestRegionServiceHandler_List(t *testing.T) {
2424

2525
expectedRegion := []Region{
2626
{
27-
ID: "ams",
28-
City: "test",
29-
Country: "NL",
30-
Continent: "Europe",
31-
Options: []string{"ddos_protection"},
27+
ID: "ams",
28+
City: "test",
29+
Country: "NL",
30+
Continent: "Europe",
31+
Options: []string{"ddos_protection"},
32+
Connectivity: []string{"public_ip", "nat_gateway"},
3233
},
3334
}
3435

0 commit comments

Comments
 (0)