blob: a708abd02629b42efc46fa0c1830ea120b363a99 [file] [log] [blame]
Jamie Hannaforded7f4532015-02-17 14:56:30 +01001package configurations
2
3import (
Jamie Hannaforde65ad952015-11-16 14:05:11 +01004 "time"
5
Jon Perritt27249f42016-02-18 10:35:59 -06006 "github.com/gophercloud/gophercloud"
7 "github.com/gophercloud/gophercloud/pagination"
Jamie Hannaforded7f4532015-02-17 14:56:30 +01008)
9
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010010// Config represents a configuration group API resource.
Jamie Hannaforded7f4532015-02-17 14:56:30 +010011type Config struct {
Jon Perritt12395212016-02-24 10:41:17 -060012 Created time.Time `json:"created"`
13 Updated time.Time `json:"updated"`
14 DatastoreName string `json:"datastore_name"`
15 DatastoreVersionID string `json:"datastore_version_id"`
16 DatastoreVersionName string `json:"datastore_version_name"`
Jamie Hannaforded7f4532015-02-17 14:56:30 +010017 Description string
18 ID string
19 Name string
20 Values map[string]interface{}
21}
22
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010023// ConfigPage contains a page of Config resources in a paginated collection.
Jamie Hannaforded7f4532015-02-17 14:56:30 +010024type ConfigPage struct {
25 pagination.SinglePageBase
26}
27
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010028// IsEmpty indicates whether a ConfigPage is empty.
Jamie Hannaforded7f4532015-02-17 14:56:30 +010029func (r ConfigPage) IsEmpty() (bool, error) {
30 is, err := ExtractConfigs(r)
Jon Perritt12395212016-02-24 10:41:17 -060031 return len(is) == 0, err
Jamie Hannaforded7f4532015-02-17 14:56:30 +010032}
33
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010034// ExtractConfigs will retrieve a slice of Config structs from a page.
Jamie Hannaforded7f4532015-02-17 14:56:30 +010035func ExtractConfigs(page pagination.Page) ([]Config, error) {
Jon Perritt12395212016-02-24 10:41:17 -060036 r := page.(ConfigPage)
37 var s struct {
38 Configs []Config `json:"configurations"`
Jamie Hannaforded7f4532015-02-17 14:56:30 +010039 }
Jon Perritt12395212016-02-24 10:41:17 -060040 err := r.ExtractInto(&s)
41 return s.Configs, err
Jamie Hannaforded7f4532015-02-17 14:56:30 +010042}
43
44type commonResult struct {
45 gophercloud.Result
46}
47
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010048// Extract will retrieve a Config resource from an operation result.
Jamie Hannaforded7f4532015-02-17 14:56:30 +010049func (r commonResult) Extract() (*Config, error) {
Jon Perritt12395212016-02-24 10:41:17 -060050 var s struct {
51 Config *Config `json:"configuration"`
Jamie Hannaforded7f4532015-02-17 14:56:30 +010052 }
Jon Perritt12395212016-02-24 10:41:17 -060053 err := r.ExtractInto(&s)
54 return s.Config, err
Jamie Hannaforded7f4532015-02-17 14:56:30 +010055}
56
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010057// GetResult represents the result of a Get operation.
Jamie Hannaforded7f4532015-02-17 14:56:30 +010058type GetResult struct {
59 commonResult
60}
61
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010062// CreateResult represents the result of a Create operation.
Jamie Hannaforded7f4532015-02-17 14:56:30 +010063type CreateResult struct {
64 commonResult
65}
66
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010067// UpdateResult represents the result of an Update operation.
Jamie Hannaforded7f4532015-02-17 14:56:30 +010068type UpdateResult struct {
69 gophercloud.ErrResult
70}
71
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010072// ReplaceResult represents the result of a Replace operation.
Jamie Hannaforded7f4532015-02-17 14:56:30 +010073type ReplaceResult struct {
74 gophercloud.ErrResult
75}
76
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010077// DeleteResult represents the result of a Delete operation.
Jamie Hannaforded7f4532015-02-17 14:56:30 +010078type DeleteResult struct {
79 gophercloud.ErrResult
80}
Jamie Hannaford23867bb2015-02-17 15:56:48 +010081
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010082// Param represents a configuration parameter API resource.
Jamie Hannaford23867bb2015-02-17 15:56:48 +010083type Param struct {
Jon Perritt12395212016-02-24 10:41:17 -060084 Max float64
85 Min float64
Jamie Hannaford23867bb2015-02-17 15:56:48 +010086 Name string
Jon Perritt12395212016-02-24 10:41:17 -060087 RestartRequired bool `json:"restart_required"`
Jamie Hannaford23867bb2015-02-17 15:56:48 +010088 Type string
89}
90
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010091// ParamPage contains a page of Param resources in a paginated collection.
Jamie Hannaford23867bb2015-02-17 15:56:48 +010092type ParamPage struct {
93 pagination.SinglePageBase
94}
95
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010096// IsEmpty indicates whether a ParamPage is empty.
Jamie Hannaford23867bb2015-02-17 15:56:48 +010097func (r ParamPage) IsEmpty() (bool, error) {
98 is, err := ExtractParams(r)
Jon Perritt12395212016-02-24 10:41:17 -060099 return len(is) == 0, err
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100100}
101
Jamie Hannafordb0d267b2015-02-19 11:59:53 +0100102// ExtractParams will retrieve a slice of Param structs from a page.
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100103func ExtractParams(page pagination.Page) ([]Param, error) {
Jon Perritt12395212016-02-24 10:41:17 -0600104 r := page.(ParamPage)
105 var s struct {
106 Params []Param `json:"configuration-parameters"`
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100107 }
Jon Perritt12395212016-02-24 10:41:17 -0600108 err := r.ExtractInto(&s)
109 return s.Params, err
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100110}
111
Jamie Hannafordb0d267b2015-02-19 11:59:53 +0100112// ParamResult represents the result of an operation which retrieves details
113// about a particular configuration param.
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100114type ParamResult struct {
115 gophercloud.Result
116}
117
Jamie Hannafordb0d267b2015-02-19 11:59:53 +0100118// Extract will retrieve a param from an operation result.
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100119func (r ParamResult) Extract() (*Param, error) {
Jon Perritt12395212016-02-24 10:41:17 -0600120 var s Param
121 err := r.ExtractInto(&s)
122 return &s, err
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100123}