Skip to content

Commit 102eebe

Browse files
authored
Add object storage tiers (#365)
1 parent 58b7014 commit 102eebe

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

object_storage.go

+57
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ type ObjectStorageService interface {
1919

2020
ListCluster(ctx context.Context, options *ListOptions) ([]ObjectStorageCluster, *Meta, *http.Response, error)
2121
RegenerateKeys(ctx context.Context, id string) (*S3Keys, *http.Response, error)
22+
23+
ListTiers(ctx context.Context) ([]ObjectStorageTier, *http.Response, error)
24+
ListClusterTiers(ctx context.Context, clusterID int) ([]ObjectStorageTier, *http.Response, error)
2225
}
2326

2427
// ObjectStorageServiceHandler handles interaction between the object storage service and the Vultr API.
@@ -49,10 +52,26 @@ type S3Keys struct {
4952
type ObjectStorageCluster struct {
5053
ID int `json:"id"`
5154
Region string `json:"region"`
55+
Name string `json:"name,omitempty"`
5256
Hostname string `json:"hostname"`
5357
Deploy string `json:"deploy"`
5458
}
5559

60+
// ObjectStorageTier represents the object storage tier data
61+
type ObjectStorageTier struct {
62+
ID int `json:"id"`
63+
Name string `json:"sales_name"`
64+
Description string `json:"sales_desc"`
65+
Price float32 `json:"price"`
66+
PriceBandwidthGB float32 `json:"bw_gb_price"`
67+
PriceDiskGB float32 `json:"disk_gb_price"`
68+
RateLimitBytesSec int `json:"ratelimit_ops_bytes"`
69+
RateLimitOpsSec int `json:"ratelimit_ops_secs"`
70+
Default string `json:"is_default"`
71+
Locations []ObjectStorageCluster `json:"locations,omitempty"`
72+
Slug string `json:"slug"`
73+
}
74+
5675
type objectStoragesBase struct {
5776
ObjectStorages []ObjectStorage `json:"object_storages"`
5877
Meta *Meta `json:"meta"`
@@ -67,6 +86,10 @@ type objectStorageClustersBase struct {
6786
Meta *Meta `json:"meta"`
6887
}
6988

89+
type objectStorageTiersBase struct {
90+
Tiers []ObjectStorageTier `json:"tiers"`
91+
}
92+
7093
type s3KeysBase struct {
7194
S3Credentials *S3Keys `json:"s3_credentials"`
7295
}
@@ -195,3 +218,37 @@ func (o *ObjectStorageServiceHandler) RegenerateKeys(ctx context.Context, id str
195218

196219
return s3Keys.S3Credentials, resp, nil
197220
}
221+
222+
// ListTiers retrieves all tiers for object storage deployments
223+
func (o *ObjectStorageServiceHandler) ListTiers(ctx context.Context) ([]ObjectStorageTier, *http.Response, error) {
224+
uri := "/v2/object-storage/tiers"
225+
req, err := o.client.NewRequest(ctx, http.MethodGet, uri, nil)
226+
if err != nil {
227+
return nil, nil, err
228+
}
229+
230+
tiers := new(objectStorageTiersBase)
231+
resp, err := o.client.DoWithContext(ctx, req, tiers)
232+
if err != nil {
233+
return nil, resp, err
234+
}
235+
236+
return tiers.Tiers, resp, nil
237+
}
238+
239+
// ListClusterTiers retrieves all tiers for object storage deployments on a specific cluster
240+
func (o *ObjectStorageServiceHandler) ListClusterTiers(ctx context.Context, clusterID int) ([]ObjectStorageTier, *http.Response, error) {
241+
uri := fmt.Sprintf("/v2/object-storage/clusters/%d/tiers", clusterID)
242+
req, err := o.client.NewRequest(ctx, http.MethodGet, uri, nil)
243+
if err != nil {
244+
return nil, nil, err
245+
}
246+
247+
tiers := new(objectStorageTiersBase)
248+
resp, err := o.client.DoWithContext(ctx, req, tiers)
249+
if err != nil {
250+
return nil, resp, err
251+
}
252+
253+
return tiers.Tiers, resp, nil
254+
}

0 commit comments

Comments
 (0)