blob: ff64a7eddaa7d5a24c434b8efbf9d0de86a1e41a [file] [log] [blame]
Joe Topjianc9fb21b2015-02-22 05:55:48 +00001package servergroups
2
3import (
Jon Perritt27249f42016-02-18 10:35:59 -06004 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/pagination"
Joe Topjianc9fb21b2015-02-22 05:55:48 +00006)
7
8// A ServerGroup creates a policy for instance placement in the cloud
9type ServerGroup struct {
10 // ID is the unique ID of the Server Group.
Jon Perritt12395212016-02-24 10:41:17 -060011 ID string `json:"id"`
Joe Topjianc9fb21b2015-02-22 05:55:48 +000012
13 // Name is the common name of the server group.
Jon Perritt12395212016-02-24 10:41:17 -060014 Name string `json:"name"`
Joe Topjianc9fb21b2015-02-22 05:55:48 +000015
16 // Polices are the group policies.
Jon Perritt12395212016-02-24 10:41:17 -060017 Policies []string `json:"policies"`
Joe Topjianc9fb21b2015-02-22 05:55:48 +000018
19 // Members are the members of the server group.
Jon Perritt12395212016-02-24 10:41:17 -060020 Members []string `json:"members"`
Joe Topjianc9fb21b2015-02-22 05:55:48 +000021
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 Perritt12395212016-02-24 10:41:17 -060026// ServerGroupPage stores a single, only page of ServerGroups
Joe Topjianc9fb21b2015-02-22 05:55:48 +000027// results from a List call.
Jon Perritt12395212016-02-24 10:41:17 -060028type ServerGroupPage struct {
Joe Topjianc9fb21b2015-02-22 05:55:48 +000029 pagination.SinglePageBase
30}
31
32// IsEmpty determines whether or not a ServerGroupsPage is empty.
Jon Perritt12395212016-02-24 10:41:17 -060033func (page ServerGroupPage) IsEmpty() (bool, error) {
Joe Topjianc9fb21b2015-02-22 05:55:48 +000034 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.
40func ExtractServerGroups(page pagination.Page) ([]ServerGroup, error) {
Jon Perritt12395212016-02-24 10:41:17 -060041 r := page.(ServerGroupPage)
42 var s struct {
43 ServerGroups []ServerGroup `json:"server_groups"`
Joe Topjianc9fb21b2015-02-22 05:55:48 +000044 }
Jon Perritt12395212016-02-24 10:41:17 -060045 err := r.ExtractInto(&s)
46 return s.ServerGroups, err
Joe Topjianc9fb21b2015-02-22 05:55:48 +000047}
48
49type ServerGroupResult struct {
50 gophercloud.Result
51}
52
53// Extract is a method that attempts to interpret any Server Group resource
54// response as a ServerGroup struct.
55func (r ServerGroupResult) Extract() (*ServerGroup, error) {
Jon Perritt12395212016-02-24 10:41:17 -060056 var s struct {
57 ServerGroup *ServerGroup `json:"server_group"`
Joe Topjianc9fb21b2015-02-22 05:55:48 +000058 }
Jon Perritt12395212016-02-24 10:41:17 -060059 err := r.ExtractInto(&s)
60 return s.ServerGroup, err
Joe Topjianc9fb21b2015-02-22 05:55:48 +000061}
62
63// CreateResult is the response from a Create operation. Call its Extract method to interpret it
64// as a ServerGroup.
65type CreateResult struct {
66 ServerGroupResult
67}
68
69// GetResult is the response from a Get operation. Call its Extract method to interpret it
70// as a ServerGroup.
71type GetResult struct {
72 ServerGroupResult
73}
74
75// DeleteResult is the response from a Delete operation. Call its Extract method to determine if
76// the call succeeded or failed.
77type DeleteResult struct {
78 gophercloud.ErrResult
79}