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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
package clusters
import (
"time"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
type commonResult struct {
gophercloud.Result
}
// CreateResult is the response of a Create operations.
type CreateResult struct {
commonResult
}
// DeleteResult is the result from a Delete operation. Call its Extract or ExtractErr
// method to determine if the call succeeded or failed.
type DeleteResult struct {
gophercloud.ErrResult
}
// GetResult represents the result of a get operation.
type GetResult struct {
commonResult
}
// Extract is a function that accepts a result and extracts a cluster resource.
func (r commonResult) Extract() (*Cluster, error) {
var s *Cluster
err := r.ExtractInto(&s)
return s, err
}
// UpdateResult is the response of a Update operations.
type UpdateResult struct {
commonResult
}
// UpgradeResult is the response of a Upgrade operations.
type UpgradeResult struct {
commonResult
}
// ResizeResult is the response of a Resize operations.
type ResizeResult struct {
commonResult
}
func (r CreateResult) Extract() (string, error) {
var s struct {
UUID string
}
err := r.ExtractInto(&s)
return s.UUID, err
}
func (r UpdateResult) Extract() (string, error) {
var s struct {
UUID string
}
err := r.ExtractInto(&s)
return s.UUID, err
}
func (r UpgradeResult) Extract() (string, error) {
var s struct {
UUID string
}
err := r.ExtractInto(&s)
return s.UUID, err
}
func (r ResizeResult) Extract() (string, error) {
var s struct {
UUID string
}
err := r.ExtractInto(&s)
return s.UUID, err
}
type Cluster struct {
APIAddress string `json:"api_address"`
COEVersion string `json:"coe_version"`
ClusterTemplateID string `json:"cluster_template_id"`
ContainerVersion string `json:"container_version"`
CreateTimeout int `json:"create_timeout"`
CreatedAt time.Time `json:"created_at"`
DiscoveryURL string `json:"discovery_url"`
DockerVolumeSize int `json:"docker_volume_size"`
Faults map[string]string `json:"faults"`
FlavorID string `json:"flavor_id"`
KeyPair string `json:"keypair"`
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"`
MasterFlavorID string `json:"master_flavor_id"`
MasterAddresses []string `json:"master_addresses"`
MasterCount int `json:"master_count"`
Name string `json:"name"`
NodeAddresses []string `json:"node_addresses"`
NodeCount int `json:"node_count"`
ProjectID string `json:"project_id"`
StackID string `json:"stack_id"`
Status string `json:"status"`
StatusReason string `json:"status_reason"`
UUID string `json:"uuid"`
UpdatedAt time.Time `json:"updated_at"`
UserID string `json:"user_id"`
FloatingIPEnabled bool `json:"floating_ip_enabled"`
FixedNetwork string `json:"fixed_network"`
FixedSubnet string `json:"fixed_subnet"`
HealthStatus string `json:"health_status"`
HealthStatusReason map[string]interface{} `json:"health_status_reason"`
}
type ClusterPage struct {
pagination.LinkedPageBase
}
func (r ClusterPage) NextPageURL() (string, error) {
var s struct {
Next string `json:"next"`
}
err := r.ExtractInto(&s)
if err != nil {
return "", err
}
return s.Next, nil
}
// IsEmpty checks whether a ClusterPage struct is empty.
func (r ClusterPage) IsEmpty() (bool, error) {
if r.StatusCode == 204 {
return true, nil
}
is, err := ExtractClusters(r)
return len(is) == 0, err
}
func ExtractClusters(r pagination.Page) ([]Cluster, error) {
var s struct {
Clusters []Cluster `json:"clusters"`
}
err := (r.(ClusterPage)).ExtractInto(&s)
return s.Clusters, err
}
|