Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 1 | package servergroups |
| 2 | |
| 3 | import ( |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 4 | "github.com/gophercloud/gophercloud" |
| 5 | "github.com/gophercloud/gophercloud/pagination" |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 6 | ) |
| 7 | |
| 8 | // A ServerGroup creates a policy for instance placement in the cloud |
| 9 | type ServerGroup struct { |
| 10 | // ID is the unique ID of the Server Group. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 11 | ID string `json:"id"` |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 12 | |
| 13 | // Name is the common name of the server group. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 14 | Name string `json:"name"` |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 15 | |
| 16 | // Polices are the group policies. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 17 | Policies []string `json:"policies"` |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 18 | |
| 19 | // Members are the members of the server group. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 20 | Members []string `json:"members"` |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 21 | |
| 22 | // Metadata includes a list of all user-specified key-value pairs attached to the Server Group. |
| 23 | Metadata map[string]interface{} |
| 24 | } |
| 25 | |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 26 | // ServerGroupPage stores a single, only page of ServerGroups |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 27 | // results from a List call. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 28 | type ServerGroupPage struct { |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 29 | pagination.SinglePageBase |
| 30 | } |
| 31 | |
| 32 | // IsEmpty determines whether or not a ServerGroupsPage is empty. |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 33 | func (page ServerGroupPage) IsEmpty() (bool, error) { |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 34 | va, err := ExtractServerGroups(page) |
| 35 | return len(va) == 0, err |
| 36 | } |
| 37 | |
| 38 | // ExtractServerGroups interprets a page of results as a slice of |
| 39 | // ServerGroups. |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 40 | func ExtractServerGroups(r pagination.Page) ([]ServerGroup, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 41 | var s struct { |
| 42 | ServerGroups []ServerGroup `json:"server_groups"` |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 43 | } |
Jon Perritt | 31b6646 | 2016-02-25 22:25:30 -0600 | [diff] [blame] | 44 | err := (r.(ServerGroupPage)).ExtractInto(&s) |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 45 | return s.ServerGroups, err |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | type ServerGroupResult struct { |
| 49 | gophercloud.Result |
| 50 | } |
| 51 | |
| 52 | // Extract is a method that attempts to interpret any Server Group resource |
| 53 | // response as a ServerGroup struct. |
| 54 | func (r ServerGroupResult) Extract() (*ServerGroup, error) { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 55 | var s struct { |
| 56 | ServerGroup *ServerGroup `json:"server_group"` |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 57 | } |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 58 | err := r.ExtractInto(&s) |
| 59 | return s.ServerGroup, err |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | // CreateResult is the response from a Create operation. Call its Extract method to interpret it |
| 63 | // as a ServerGroup. |
| 64 | type CreateResult struct { |
| 65 | ServerGroupResult |
| 66 | } |
| 67 | |
| 68 | // GetResult is the response from a Get operation. Call its Extract method to interpret it |
| 69 | // as a ServerGroup. |
| 70 | type GetResult struct { |
| 71 | ServerGroupResult |
| 72 | } |
| 73 | |
| 74 | // DeleteResult is the response from a Delete operation. Call its Extract method to determine if |
| 75 | // the call succeeded or failed. |
| 76 | type DeleteResult struct { |
| 77 | gophercloud.ErrResult |
| 78 | } |