blob: 5c960b892d9a7d821a089a2ad3f4ade9e1ac95b9 [file] [log] [blame]
Jamie Hannaforded7f4532015-02-17 14:56:30 +01001package configurations
2
3import (
4 "github.com/mitchellh/mapstructure"
5 "github.com/rackspace/gophercloud"
6 "github.com/rackspace/gophercloud/pagination"
7)
8
9type Config struct {
10 Created string
11 Updated string
12 DatastoreName string `mapstructure:"datastore_name"`
13 DatastoreVersionID string `mapstructure:"datastore_version_id"`
14 DatastoreVersionName string `mapstructure:"datastore_version_name"`
15 Description string
16 ID string
17 Name string
18 Values map[string]interface{}
19}
20
21type ConfigPage struct {
22 pagination.SinglePageBase
23}
24
25func (r ConfigPage) IsEmpty() (bool, error) {
26 is, err := ExtractConfigs(r)
27 if err != nil {
28 return true, err
29 }
30 return len(is) == 0, nil
31}
32
33func ExtractConfigs(page pagination.Page) ([]Config, error) {
34 casted := page.(ConfigPage).Body
35
36 var resp struct {
37 Configs []Config `mapstructure:"configurations" json:"configurations"`
38 }
39
40 err := mapstructure.Decode(casted, &resp)
41 return resp.Configs, err
42}
43
44type commonResult struct {
45 gophercloud.Result
46}
47
48func (r commonResult) Extract() (*Config, error) {
49 if r.Err != nil {
50 return nil, r.Err
51 }
52
53 var response struct {
54 Config Config `mapstructure:"configuration"`
55 }
56
57 err := mapstructure.Decode(r.Body, &response)
58 return &response.Config, err
59}
60
61type GetResult struct {
62 commonResult
63}
64
65type CreateResult struct {
66 commonResult
67}
68
69type UpdateResult struct {
70 gophercloud.ErrResult
71}
72
73type ReplaceResult struct {
74 gophercloud.ErrResult
75}
76
77type DeleteResult struct {
78 gophercloud.ErrResult
79}
Jamie Hannaford23867bb2015-02-17 15:56:48 +010080
81type Param struct {
82 Max int
83 Min int
84 Name string
85 RestartRequired bool `mapstructure:"restart_required" json:"restart_required"`
86 Type string
87}
88
89type ParamPage struct {
90 pagination.SinglePageBase
91}
92
93func (r ParamPage) IsEmpty() (bool, error) {
94 is, err := ExtractParams(r)
95 if err != nil {
96 return true, err
97 }
98 return len(is) == 0, nil
99}
100
101func ExtractParams(page pagination.Page) ([]Param, error) {
102 casted := page.(ParamPage).Body
103
104 var resp struct {
105 Params []Param `mapstructure:"configuration-parameters" json:"configuration-parameters"`
106 }
107
108 err := mapstructure.Decode(casted, &resp)
109 return resp.Params, err
110}
111
112type ParamResult struct {
113 gophercloud.Result
114}
115
116func (r ParamResult) Extract() (*Param, error) {
117 if r.Err != nil {
118 return nil, r.Err
119 }
120
121 var param Param
122
123 err := mapstructure.Decode(r.Body, &param)
124 return &param, err
125}