-
Notifications
You must be signed in to change notification settings - Fork 14
/
cloud_database_flavors.go
82 lines (64 loc) · 2.19 KB
/
cloud_database_flavors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// This file is part of gobizfly
package gobizfly
import (
"context"
"encoding/json"
"net/http"
)
const (
cloudDatabaseFlavorsResourcePath = "/flavors"
)
type cloudDatabaseFlavors struct {
client *Client
}
// CloudDatabaseFlavor contains detail about a datastore.
type CloudDatabaseFlavor struct {
Category string `json:"category"`
Datastore string `json:"datastore"`
DatastoreID string `json:"datastore_id"`
DatastoreVersionID string `json:"datastore_version_id"`
Version string `json:"version"`
Flavors []string `json:"flavors"`
LimitVolumesSize map[string]interface{} `json:"limit_volumes_size"`
}
func (flv *cloudDatabaseService) Flavors() *cloudDatabaseFlavors {
return &cloudDatabaseFlavors{client: flv.client}
}
// CloudDatabase Flavor Resource Path
func (flv *cloudDatabaseFlavors) resourcePath(datastore string, datastoreVersion string) string {
return cloudDatabaseFlavorsResourcePath + "/" + datastore + "/versions/" + datastoreVersion
}
// List all database flavor.
func (flv *cloudDatabaseFlavors) List(ctx context.Context) ([]*CloudDatabaseFlavor, error) {
req, err := flv.client.NewRequest(ctx, http.MethodGet, databaseServiceName, cloudDatabaseFlavorsResourcePath, nil)
if err != nil {
return nil, err
}
resp, err := flv.client.Do(ctx, req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var flavors []*CloudDatabaseFlavor
if err := json.NewDecoder(resp.Body).Decode(&flavors); err != nil {
return nil, err
}
return flavors, nil
}
// Get a database flavor parameters.
func (flv *cloudDatabaseFlavors) Get(ctx context.Context, datastore string, datastoreVersion string) ([]*CloudDatabaseFlavor, error) {
req, err := flv.client.NewRequest(ctx, http.MethodGet, databaseServiceName, flv.resourcePath(datastore, datastoreVersion), nil)
if err != nil {
return nil, err
}
resp, err := flv.client.Do(ctx, req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var flavors []*CloudDatabaseFlavor
if err := json.NewDecoder(resp.Body).Decode(&flavors); err != nil {
return nil, err
}
return flavors, nil
}