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 153 154
|
package amphorae
import (
"encoding/json"
"time"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// Amphora is virtual machine, container, dedicated hardware, appliance or device that actually performs the task of
// load balancing in the Octavia system.
type Amphora struct {
// The unique ID for the Amphora.
ID string `json:"id"`
// The ID of the load balancer.
LoadbalancerID string `json:"loadbalancer_id"`
// The management IP of the amphora.
LBNetworkIP string `json:"lb_network_ip"`
// The ID of the amphora resource in the compute system.
ComputeID string `json:"compute_id"`
// The IP address of the Virtual IP (VIP).
HAIP string `json:"ha_ip"`
// The ID of the Virtual IP (VIP) port.
HAPortID string `json:"ha_port_id"`
// The date the certificate for the amphora expires.
CertExpiration time.Time `json:"-"`
// Whether the certificate is in the process of being replaced.
CertBusy bool `json:"cert_busy"`
// The role of the amphora. One of STANDALONE, MASTER, BACKUP.
Role string `json:"role"`
// The status of the amphora. One of: BOOTING, ALLOCATED, READY, PENDING_CREATE, PENDING_DELETE, DELETED, ERROR.
Status string `json:"status"`
// The vrrp port’s ID in the networking system.
VRRPPortID string `json:"vrrp_port_id"`
// The address of the vrrp port on the amphora.
VRRPIP string `json:"vrrp_ip"`
// The bound interface name of the vrrp port on the amphora.
VRRPInterface string `json:"vrrp_interface"`
// The vrrp group’s ID for the amphora.
VRRPID int `json:"vrrp_id"`
// The priority of the amphora in the vrrp group.
VRRPPriority int `json:"vrrp_priority"`
// The availability zone of a compute instance, cached at create time. This is not guaranteed to be current. May be
// an empty-string if the compute service does not use zones.
CachedZone string `json:"cached_zone"`
// The ID of the glance image used for the amphora.
ImageID string `json:"image_id"`
// The UTC date and timestamp when the resource was created.
CreatedAt time.Time `json:"-"`
// The UTC date and timestamp when the resource was last updated.
UpdatedAt time.Time `json:"-"`
}
func (a *Amphora) UnmarshalJSON(b []byte) error {
type tmp Amphora
var s struct {
tmp
CertExpiration gophercloud.JSONRFC3339NoZ `json:"cert_expiration"`
CreatedAt gophercloud.JSONRFC3339NoZ `json:"created_at"`
UpdatedAt gophercloud.JSONRFC3339NoZ `json:"updated_at"`
}
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
*a = Amphora(s.tmp)
a.CreatedAt = time.Time(s.CreatedAt)
a.UpdatedAt = time.Time(s.UpdatedAt)
a.CertExpiration = time.Time(s.CertExpiration)
return nil
}
// AmphoraPage is the page returned by a pager when traversing over a
// collection of amphorae.
type AmphoraPage struct {
pagination.LinkedPageBase
}
// NextPageURL is invoked when a paginated collection of amphoraes has
// reached the end of a page and the pager seeks to traverse over a new one.
// In order to do this, it needs to construct the next page's URL.
func (r AmphoraPage) NextPageURL() (string, error) {
var s struct {
Links []gophercloud.Link `json:"amphorae_links"`
}
err := r.ExtractInto(&s)
if err != nil {
return "", err
}
return gophercloud.ExtractNextURL(s.Links)
}
// IsEmpty checks whether a AmphoraPage struct is empty.
func (r AmphoraPage) IsEmpty() (bool, error) {
is, err := ExtractAmphorae(r)
return len(is) == 0, err
}
// ExtractAmphorae accepts a Page struct, specifically a AmphoraPage
// struct, and extracts the elements into a slice of Amphora structs. In
// other words, a generic collection is mapped into a relevant slice.
func ExtractAmphorae(r pagination.Page) ([]Amphora, error) {
var s struct {
Amphorae []Amphora `json:"amphorae"`
}
err := (r.(AmphoraPage)).ExtractInto(&s)
return s.Amphorae, err
}
type commonResult struct {
gophercloud.Result
}
// Extract is a function that accepts a result and extracts an amphora.
func (r commonResult) Extract() (*Amphora, error) {
var s struct {
Amphora *Amphora `json:"amphora"`
}
err := r.ExtractInto(&s)
return s.Amphora, err
}
// GetResult represents the result of a get operation. Call its Extract
// method to interpret it as an amphora.
type GetResult struct {
commonResult
}
// FailoverResult represents the result of a failover operation. Call its
// ExtractErr method to determine if the request succeeded or failed.
type FailoverResult struct {
gophercloud.ErrResult
}
|