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