1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
package nodegroups
import (
"time"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
type commonResult struct {
gophercloud.Result
}
func (r commonResult) Extract() (*NodeGroup, error) {
var s NodeGroup
err := r.ExtractInto(&s)
return &s, err
}
// GetResult is the response from a Get request.
// Use the Extract method to retrieve the NodeGroup itself.
type GetResult struct {
commonResult
}
// CreateResult is the response from a Create request.
// Use the Extract method to retrieve the created node group.
type CreateResult struct {
commonResult
}
// UpdateResult is the response from an Update request.
// Use the Extract method to retrieve the updated node group.
type UpdateResult struct {
commonResult
}
// DeleteResult is the response from a Delete request.
// Use the ExtractErr method to extract the error from the result.
type DeleteResult struct {
gophercloud.ErrResult
}
// NodeGroup is the API representation of a Magnum node group.
type NodeGroup struct {
ID int `json:"id"`
UUID string `json:"uuid"`
Name string `json:"name"`
ClusterID string `json:"cluster_id"`
ProjectID string `json:"project_id"`
DockerVolumeSize *int `json:"docker_volume_size"`
Labels map[string]string `json:"labels"`
LabelsAdded map[string]string `json:"labels_added"`
LabelsOverridden map[string]string `json:"labels_overridden"`
LabelsSkipped map[string]string `json:"labels_skipped"`
Links []gophercloud.Link `json:"links"`
FlavorID string `json:"flavor_id"`
ImageID string `json:"image_id"`
NodeAddresses []string `json:"node_addresses"`
NodeCount int `json:"node_count"`
Role string `json:"role"`
MinNodeCount int `json:"min_node_count"`
MaxNodeCount *int `json:"max_node_count"`
IsDefault bool `json:"is_default"`
StackID string `json:"stack_id"`
Status string `json:"status"`
StatusReason string `json:"status_reason"`
Version string `json:"version"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type NodeGroupPage struct {
pagination.LinkedPageBase
}
func (r NodeGroupPage) NextPageURL() (string, error) {
var s struct {
Next string `json:"next"`
}
err := r.ExtractInto(&s)
if err != nil {
return "", err
}
return s.Next, nil
}
func (r NodeGroupPage) IsEmpty() (bool, error) {
if r.StatusCode == 204 {
return true, nil
}
s, err := ExtractNodeGroups(r)
return len(s) == 0, err
}
// ExtractNodeGroups takes a Page of node groups as returned from List
// or from AllPages and extracts it as a slice of NodeGroups.
func ExtractNodeGroups(r pagination.Page) ([]NodeGroup, error) {
var s struct {
NodeGroups []NodeGroup `json:"nodegroups"`
}
err := (r.(NodeGroupPage)).ExtractInto(&s)
return s.NodeGroups, err
}
|