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 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 6 | "github.com/gophercloud/gophercloud" |
| 7 | "github.com/gophercloud/gophercloud/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. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 35 | func ExtractConfigs(page pagination.Page) ([]Config, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 36 | r := page.(ConfigPage) |
| 37 | var s struct { |
| 38 | Configs []Config `json:"configurations"` |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 39 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 40 | err := r.ExtractInto(&s) |
| 41 | return s.Configs, err |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | type commonResult struct { |
| 45 | gophercloud.Result |
| 46 | } |
| 47 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 48 | // Extract will retrieve a Config resource from an operation result. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 49 | func (r commonResult) Extract() (*Config, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 50 | var s struct { |
| 51 | Config *Config `json:"configuration"` |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 52 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 53 | err := r.ExtractInto(&s) |
| 54 | return s.Config, err |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 55 | } |
| 56 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 57 | // GetResult represents the result of a Get operation. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 58 | type GetResult struct { |
| 59 | commonResult |
| 60 | } |
| 61 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 62 | // CreateResult represents the result of a Create operation. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 63 | type CreateResult struct { |
| 64 | commonResult |
| 65 | } |
| 66 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 67 | // UpdateResult represents the result of an Update operation. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 68 | type UpdateResult struct { |
| 69 | gophercloud.ErrResult |
| 70 | } |
| 71 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 72 | // ReplaceResult represents the result of a Replace operation. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 73 | type ReplaceResult struct { |
| 74 | gophercloud.ErrResult |
| 75 | } |
| 76 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 77 | // DeleteResult represents the result of a Delete operation. |
Jamie Hannaford | ed7f453 | 2015-02-17 14:56:30 +0100 | [diff] [blame] | 78 | type DeleteResult struct { |
| 79 | gophercloud.ErrResult |
| 80 | } |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 81 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 82 | // Param represents a configuration parameter API resource. |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 83 | type Param struct { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 84 | Max float64 |
| 85 | Min float64 |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 86 | Name string |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 87 | RestartRequired bool `json:"restart_required"` |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 88 | Type string |
| 89 | } |
| 90 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 91 | // ParamPage contains a page of Param resources in a paginated collection. |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 92 | type ParamPage struct { |
| 93 | pagination.SinglePageBase |
| 94 | } |
| 95 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 96 | // IsEmpty indicates whether a ParamPage is empty. |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 97 | func (r ParamPage) IsEmpty() (bool, error) { |
| 98 | is, err := ExtractParams(r) |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 99 | return len(is) == 0, err |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 100 | } |
| 101 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 102 | // ExtractParams will retrieve a slice of Param structs from a page. |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 103 | func ExtractParams(page pagination.Page) ([]Param, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 104 | r := page.(ParamPage) |
| 105 | var s struct { |
| 106 | Params []Param `json:"configuration-parameters"` |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 107 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 108 | err := r.ExtractInto(&s) |
| 109 | return s.Params, err |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 110 | } |
| 111 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 112 | // ParamResult represents the result of an operation which retrieves details |
| 113 | // about a particular configuration param. |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 114 | type ParamResult struct { |
| 115 | gophercloud.Result |
| 116 | } |
| 117 | |
Jamie Hannaford | b0d267b | 2015-02-19 11:59:53 +0100 | [diff] [blame] | 118 | // Extract will retrieve a param from an operation result. |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 119 | func (r ParamResult) Extract() (*Param, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 120 | var s Param |
| 121 | err := r.ExtractInto(&s) |
| 122 | return &s, err |
Jamie Hannaford | 23867bb | 2015-02-17 15:56:48 +0100 | [diff] [blame] | 123 | } |