blob: cd83d10a1c0305e97516729f4f2e7a36ed5646e1 [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}