Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 1 | package configurations |
| 2 | |
| 3 | import ( |
Jamie Hannaford | e65ad95 | 2015-11-16 14:05:11 +0100 | [diff] [blame] | 4 | "time" |
| 5 | |
Krzysztof Szukiełojć | 3f41d08 | 2017-05-07 14:43:06 +0200 | [diff] [blame^] | 6 | "gerrit.mcp.mirantis.net/debian/gophercloud.git" |
Krzysztof Szukiełojć | 24a29ce | 2017-05-07 14:24:02 +0200 | [diff] [blame] | 7 | "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination" |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 8 | ) |
| 9 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 10 | // Config represents a configuration group API resource. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 11 | type Config struct { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 12 | 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 Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 17 | Description string |
| 18 | ID string |
| 19 | Name string |
| 20 | Values map[string]interface{} |
| 21 | } |
| 22 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 23 | // ConfigPage contains a page of Config resources in a paginated collection. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 24 | type ConfigPage struct { |
| 25 | pagination.SinglePageBase |
| 26 | } |
| 27 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 28 | // IsEmpty indicates whether a ConfigPage is empty. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 29 | func (r ConfigPage) IsEmpty() (bool, error) { |
| 30 | is, err := ExtractConfigs(r) |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 31 | return len(is) == 0, err |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 32 | } |
| 33 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 34 | // ExtractConfigs will retrieve a slice of Config structs from a page. |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 35 | func ExtractConfigs(r pagination.Page) ([]Config, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 36 | var s struct { |
| 37 | Configs []Config `json:"configurations"` |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 38 | } |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 39 | err := (r.(ConfigPage)).ExtractInto(&s) |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 40 | return s.Configs, err |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | type commonResult struct { |
| 44 | gophercloud.Result |
| 45 | } |
| 46 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 47 | // Extract will retrieve a Config resource from an operation result. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 48 | func (r commonResult) Extract() (*Config, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 49 | var s struct { |
| 50 | Config *Config `json:"configuration"` |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 51 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 52 | err := r.ExtractInto(&s) |
| 53 | return s.Config, err |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 54 | } |
| 55 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 56 | // GetResult represents the result of a Get operation. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 57 | type GetResult struct { |
| 58 | commonResult |
| 59 | } |
| 60 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 61 | // CreateResult represents the result of a Create operation. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 62 | type CreateResult struct { |
| 63 | commonResult |
| 64 | } |
| 65 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 66 | // UpdateResult represents the result of an Update operation. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 67 | type UpdateResult struct { |
| 68 | gophercloud.ErrResult |
| 69 | } |
| 70 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 71 | // ReplaceResult represents the result of a Replace operation. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 72 | type ReplaceResult struct { |
| 73 | gophercloud.ErrResult |
| 74 | } |
| 75 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 76 | // DeleteResult represents the result of a Delete operation. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 77 | type DeleteResult struct { |
| 78 | gophercloud.ErrResult |
| 79 | } |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 80 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 81 | // Param represents a configuration parameter API resource. |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 82 | type Param struct { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 83 | Max float64 |
| 84 | Min float64 |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 85 | Name string |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 86 | RestartRequired bool `json:"restart_required"` |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 87 | Type string |
| 88 | } |
| 89 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 90 | // ParamPage contains a page of Param resources in a paginated collection. |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 91 | type ParamPage struct { |
| 92 | pagination.SinglePageBase |
| 93 | } |
| 94 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 95 | // IsEmpty indicates whether a ParamPage is empty. |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 96 | func (r ParamPage) IsEmpty() (bool, error) { |
| 97 | is, err := ExtractParams(r) |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 98 | return len(is) == 0, err |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 99 | } |
| 100 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 101 | // ExtractParams will retrieve a slice of Param structs from a page. |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 102 | func ExtractParams(r pagination.Page) ([]Param, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 103 | var s struct { |
| 104 | Params []Param `json:"configuration-parameters"` |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 105 | } |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 106 | err := (r.(ParamPage)).ExtractInto(&s) |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 107 | return s.Params, err |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 108 | } |
| 109 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 110 | // ParamResult represents the result of an operation which retrieves details |
| 111 | // about a particular configuration param. |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 112 | type ParamResult struct { |
| 113 | gophercloud.Result |
| 114 | } |
| 115 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 116 | // Extract will retrieve a param from an operation result. |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 117 | func (r ParamResult) Extract() (*Param, error) { |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 118 | var s *Param |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 119 | err := r.ExtractInto(&s) |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 120 | return s, err |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 121 | } |