blob: 504bd11186f8f779bfc1a9a2b80eb9e8b32f8765 [file] [log] [blame]
Jamie Hannaforded7f4532015-02-17 14:56:30 +01001package configurations
2
3import (
Jamie Hannaforde65ad952015-11-16 14:05:11 +01004 "time"
5
Krzysztof Szukiełojć3f41d082017-05-07 14:43:06 +02006 "gerrit.mcp.mirantis.net/debian/gophercloud.git"
Krzysztof Szukiełojć24a29ce2017-05-07 14:24:02 +02007 "gerrit.mcp.mirantis.net/debian/gophercloud.git/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.
Jon Perritt31b66462016-02-25 22:25:30 -060035func ExtractConfigs(r pagination.Page) ([]Config, error) {
Jon Perritt12395212016-02-24 10:41:17 -060036 var s struct {
37 Configs []Config `json:"configurations"`
Jamie Hannaforded7f4532015-02-17 14:56:30 +010038 }
Jon Perritt31b66462016-02-25 22:25:30 -060039 err := (r.(ConfigPage)).ExtractInto(&s)
Jon Perritt12395212016-02-24 10:41:17 -060040 return s.Configs, err
Jamie Hannaforded7f4532015-02-17 14:56:30 +010041}
42
43type commonResult struct {
44 gophercloud.Result
45}
46
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010047// Extract will retrieve a Config resource from an operation result.
Jamie Hannaforded7f4532015-02-17 14:56:30 +010048func (r commonResult) Extract() (*Config, error) {
Jon Perritt12395212016-02-24 10:41:17 -060049 var s struct {
50 Config *Config `json:"configuration"`
Jamie Hannaforded7f4532015-02-17 14:56:30 +010051 }
Jon Perritt12395212016-02-24 10:41:17 -060052 err := r.ExtractInto(&s)
53 return s.Config, err
Jamie Hannaforded7f4532015-02-17 14:56:30 +010054}
55
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010056// GetResult represents the result of a Get operation.
Jamie Hannaforded7f4532015-02-17 14:56:30 +010057type GetResult struct {
58 commonResult
59}
60
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010061// CreateResult represents the result of a Create operation.
Jamie Hannaforded7f4532015-02-17 14:56:30 +010062type CreateResult struct {
63 commonResult
64}
65
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010066// UpdateResult represents the result of an Update operation.
Jamie Hannaforded7f4532015-02-17 14:56:30 +010067type UpdateResult struct {
68 gophercloud.ErrResult
69}
70
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010071// ReplaceResult represents the result of a Replace operation.
Jamie Hannaforded7f4532015-02-17 14:56:30 +010072type ReplaceResult struct {
73 gophercloud.ErrResult
74}
75
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010076// DeleteResult represents the result of a Delete operation.
Jamie Hannaforded7f4532015-02-17 14:56:30 +010077type DeleteResult struct {
78 gophercloud.ErrResult
79}
Jamie Hannaford23867bb2015-02-17 15:56:48 +010080
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010081// Param represents a configuration parameter API resource.
Jamie Hannaford23867bb2015-02-17 15:56:48 +010082type Param struct {
Jon Perritt12395212016-02-24 10:41:17 -060083 Max float64
84 Min float64
Jamie Hannaford23867bb2015-02-17 15:56:48 +010085 Name string
Jon Perritt12395212016-02-24 10:41:17 -060086 RestartRequired bool `json:"restart_required"`
Jamie Hannaford23867bb2015-02-17 15:56:48 +010087 Type string
88}
89
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010090// ParamPage contains a page of Param resources in a paginated collection.
Jamie Hannaford23867bb2015-02-17 15:56:48 +010091type ParamPage struct {
92 pagination.SinglePageBase
93}
94
Jamie Hannafordb0d267b2015-02-19 11:59:53 +010095// IsEmpty indicates whether a ParamPage is empty.
Jamie Hannaford23867bb2015-02-17 15:56:48 +010096func (r ParamPage) IsEmpty() (bool, error) {
97 is, err := ExtractParams(r)
Jon Perritt12395212016-02-24 10:41:17 -060098 return len(is) == 0, err
Jamie Hannaford23867bb2015-02-17 15:56:48 +010099}
100
Jamie Hannafordb0d267b2015-02-19 11:59:53 +0100101// ExtractParams will retrieve a slice of Param structs from a page.
Jon Perritt31b66462016-02-25 22:25:30 -0600102func ExtractParams(r pagination.Page) ([]Param, error) {
Jon Perritt12395212016-02-24 10:41:17 -0600103 var s struct {
104 Params []Param `json:"configuration-parameters"`
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100105 }
Jon Perritt31b66462016-02-25 22:25:30 -0600106 err := (r.(ParamPage)).ExtractInto(&s)
Jon Perritt12395212016-02-24 10:41:17 -0600107 return s.Params, err
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100108}
109
Jamie Hannafordb0d267b2015-02-19 11:59:53 +0100110// ParamResult represents the result of an operation which retrieves details
111// about a particular configuration param.
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100112type ParamResult struct {
113 gophercloud.Result
114}
115
Jamie Hannafordb0d267b2015-02-19 11:59:53 +0100116// Extract will retrieve a param from an operation result.
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100117func (r ParamResult) Extract() (*Param, error) {
Jon Perritt31b66462016-02-25 22:25:30 -0600118 var s *Param
Jon Perritt12395212016-02-24 10:41:17 -0600119 err := r.ExtractInto(&s)
Jon Perritt31b66462016-02-25 22:25:30 -0600120 return s, err
Jamie Hannaford23867bb2015-02-17 15:56:48 +0100121}