github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/compute/v2/extensions/servergroups/results.go (about) 1 package servergroups 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/pagination" 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. 11 ID string `json:"id"` 12 13 // Name is the common name of the server group. 14 Name string `json:"name"` 15 16 // Polices are the group policies. 17 // 18 // Normally a single policy is applied: 19 // 20 // "affinity" will place all servers within the server group on the 21 // same compute node. 22 // 23 // "anti-affinity" will place servers within the server group on different 24 // compute nodes. 25 Policies []string `json:"policies"` 26 27 // Members are the members of the server group. 28 Members []string `json:"members"` 29 30 // Metadata includes a list of all user-specified key-value pairs attached 31 // to the Server Group. 32 Metadata map[string]interface{} 33 } 34 35 // ServerGroupPage stores a single page of all ServerGroups results from a 36 // List call. 37 type ServerGroupPage struct { 38 pagination.SinglePageBase 39 } 40 41 // IsEmpty determines whether or not a ServerGroupsPage is empty. 42 func (page ServerGroupPage) IsEmpty() (bool, error) { 43 va, err := ExtractServerGroups(page) 44 return len(va) == 0, err 45 } 46 47 // ExtractServerGroups interprets a page of results as a slice of 48 // ServerGroups. 49 func ExtractServerGroups(r pagination.Page) ([]ServerGroup, error) { 50 var s struct { 51 ServerGroups []ServerGroup `json:"server_groups"` 52 } 53 err := (r.(ServerGroupPage)).ExtractInto(&s) 54 return s.ServerGroups, err 55 } 56 57 type ServerGroupResult struct { 58 golangsdk.Result 59 } 60 61 // Extract is a method that attempts to interpret any Server Group resource 62 // response as a ServerGroup struct. 63 func (r ServerGroupResult) Extract() (*ServerGroup, error) { 64 var s struct { 65 ServerGroup *ServerGroup `json:"server_group"` 66 } 67 err := r.ExtractInto(&s) 68 return s.ServerGroup, err 69 } 70 71 // CreateResult is the response from a Create operation. Call its Extract method 72 // to interpret it as a ServerGroup. 73 type CreateResult struct { 74 ServerGroupResult 75 } 76 77 // GetResult is the response from a Get operation. Call its Extract method to 78 // interpret it as a ServerGroup. 79 type GetResult struct { 80 ServerGroupResult 81 } 82 83 // DeleteResult is the response from a Delete operation. Call its ExtractErr 84 // method to determine if the call succeeded or failed. 85 type DeleteResult struct { 86 golangsdk.ErrResult 87 }