github.com/gophercloud/gophercloud@v1.11.0/openstack/loadbalancer/v2/amphorae/results.go (about) 1 package amphorae 2 3 import ( 4 "encoding/json" 5 "time" 6 7 "github.com/gophercloud/gophercloud" 8 "github.com/gophercloud/gophercloud/pagination" 9 ) 10 11 // Amphora is virtual machine, container, dedicated hardware, appliance or device that actually performs the task of 12 // load balancing in the Octavia system. 13 type Amphora struct { 14 // The unique ID for the Amphora. 15 ID string `json:"id"` 16 17 // The ID of the load balancer. 18 LoadbalancerID string `json:"loadbalancer_id"` 19 20 // The management IP of the amphora. 21 LBNetworkIP string `json:"lb_network_ip"` 22 23 // The ID of the amphora resource in the compute system. 24 ComputeID string `json:"compute_id"` 25 26 // The IP address of the Virtual IP (VIP). 27 HAIP string `json:"ha_ip"` 28 29 // The ID of the Virtual IP (VIP) port. 30 HAPortID string `json:"ha_port_id"` 31 32 // The date the certificate for the amphora expires. 33 CertExpiration time.Time `json:"-"` 34 35 // Whether the certificate is in the process of being replaced. 36 CertBusy bool `json:"cert_busy"` 37 38 // The role of the amphora. One of STANDALONE, MASTER, BACKUP. 39 Role string `json:"role"` 40 41 // The status of the amphora. One of: BOOTING, ALLOCATED, READY, PENDING_CREATE, PENDING_DELETE, DELETED, ERROR. 42 Status string `json:"status"` 43 44 // The vrrp port’s ID in the networking system. 45 VRRPPortID string `json:"vrrp_port_id"` 46 47 // The address of the vrrp port on the amphora. 48 VRRPIP string `json:"vrrp_ip"` 49 50 // The bound interface name of the vrrp port on the amphora. 51 VRRPInterface string `json:"vrrp_interface"` 52 53 // The vrrp group’s ID for the amphora. 54 VRRPID int `json:"vrrp_id"` 55 56 // The priority of the amphora in the vrrp group. 57 VRRPPriority int `json:"vrrp_priority"` 58 59 // The availability zone of a compute instance, cached at create time. This is not guaranteed to be current. May be 60 // an empty-string if the compute service does not use zones. 61 CachedZone string `json:"cached_zone"` 62 63 // The ID of the glance image used for the amphora. 64 ImageID string `json:"image_id"` 65 66 // The UTC date and timestamp when the resource was created. 67 CreatedAt time.Time `json:"-"` 68 69 // The UTC date and timestamp when the resource was last updated. 70 UpdatedAt time.Time `json:"-"` 71 } 72 73 func (a *Amphora) UnmarshalJSON(b []byte) error { 74 type tmp Amphora 75 var s struct { 76 tmp 77 CertExpiration gophercloud.JSONRFC3339NoZ `json:"cert_expiration"` 78 CreatedAt gophercloud.JSONRFC3339NoZ `json:"created_at"` 79 UpdatedAt gophercloud.JSONRFC3339NoZ `json:"updated_at"` 80 } 81 err := json.Unmarshal(b, &s) 82 if err != nil { 83 return err 84 } 85 *a = Amphora(s.tmp) 86 87 a.CreatedAt = time.Time(s.CreatedAt) 88 a.UpdatedAt = time.Time(s.UpdatedAt) 89 a.CertExpiration = time.Time(s.CertExpiration) 90 91 return nil 92 } 93 94 // AmphoraPage is the page returned by a pager when traversing over a 95 // collection of amphorae. 96 type AmphoraPage struct { 97 pagination.LinkedPageBase 98 } 99 100 // NextPageURL is invoked when a paginated collection of amphoraes has 101 // reached the end of a page and the pager seeks to traverse over a new one. 102 // In order to do this, it needs to construct the next page's URL. 103 func (r AmphoraPage) NextPageURL() (string, error) { 104 var s struct { 105 Links []gophercloud.Link `json:"amphorae_links"` 106 } 107 err := r.ExtractInto(&s) 108 if err != nil { 109 return "", err 110 } 111 return gophercloud.ExtractNextURL(s.Links) 112 } 113 114 // IsEmpty checks whether a AmphoraPage struct is empty. 115 func (r AmphoraPage) IsEmpty() (bool, error) { 116 if r.StatusCode == 204 { 117 return true, nil 118 } 119 120 is, err := ExtractAmphorae(r) 121 return len(is) == 0, err 122 } 123 124 // ExtractAmphorae accepts a Page struct, specifically a AmphoraPage 125 // struct, and extracts the elements into a slice of Amphora structs. In 126 // other words, a generic collection is mapped into a relevant slice. 127 func ExtractAmphorae(r pagination.Page) ([]Amphora, error) { 128 var s struct { 129 Amphorae []Amphora `json:"amphorae"` 130 } 131 err := (r.(AmphoraPage)).ExtractInto(&s) 132 return s.Amphorae, err 133 } 134 135 type commonResult struct { 136 gophercloud.Result 137 } 138 139 // Extract is a function that accepts a result and extracts an amphora. 140 func (r commonResult) Extract() (*Amphora, error) { 141 var s struct { 142 Amphora *Amphora `json:"amphora"` 143 } 144 err := r.ExtractInto(&s) 145 return s.Amphora, err 146 } 147 148 // GetResult represents the result of a get operation. Call its Extract 149 // method to interpret it as an amphora. 150 type GetResult struct { 151 commonResult 152 } 153 154 // FailoverResult represents the result of a failover operation. Call its 155 // ExtractErr method to determine if the request succeeded or failed. 156 type FailoverResult struct { 157 gophercloud.ErrResult 158 }