blob: ab49b35a44d85066979577f612b87fff376727f3 [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.
Jon Perritt31b66462016-02-25 22:25:30 -060040func ExtractServerGroups(r pagination.Page) ([]ServerGroup, error) {
Jon Perritt12395212016-02-24 10:41:17 -060041 var s struct {
42 ServerGroups []ServerGroup `json:"server_groups"`
Joe Topjianc9fb21b2015-02-22 05:55:48 +000043 }
Jon Perritt31b66462016-02-25 22:25:30 -060044 err := (r.(ServerGroupPage)).ExtractInto(&s)
Jon Perritt12395212016-02-24 10:41:17 -060045 return s.ServerGroups, err
Joe Topjianc9fb21b2015-02-22 05:55:48 +000046}
47
48type 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.
54func (r ServerGroupResult) Extract() (*ServerGroup, error) {
Jon Perritt12395212016-02-24 10:41:17 -060055 var s struct {
56 ServerGroup *ServerGroup `json:"server_group"`
Joe Topjianc9fb21b2015-02-22 05:55:48 +000057 }
Jon Perritt12395212016-02-24 10:41:17 -060058 err := r.ExtractInto(&s)
59 return s.ServerGroup, err
Joe Topjianc9fb21b2015-02-22 05:55:48 +000060}
61
62// CreateResult is the response from a Create operation. Call its Extract method to interpret it
63// as a ServerGroup.
64type 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.
70type 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.
76type DeleteResult struct {
77 gophercloud.ErrResult
78}