github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/lbaas_v2/loadbalancers/results.go (about) 1 package loadbalancers 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners" 6 "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools" 7 "github.com/gophercloud/gophercloud/pagination" 8 ) 9 10 // LoadBalancer is the primary load balancing configuration object that 11 // specifies the virtual IP address on which client traffic is received, as well 12 // as other details such as the load balancing method to be use, protocol, etc. 13 type LoadBalancer struct { 14 // Human-readable description for the Loadbalancer. 15 Description string `json:"description"` 16 17 // The administrative state of the Loadbalancer. 18 // A valid value is true (UP) or false (DOWN). 19 AdminStateUp bool `json:"admin_state_up"` 20 21 // Owner of the LoadBalancer. 22 TenantID string `json:"tenant_id"` 23 24 // The provisioning status of the LoadBalancer. 25 // This value is ACTIVE, PENDING_CREATE or ERROR. 26 ProvisioningStatus string `json:"provisioning_status"` 27 28 // The IP address of the Loadbalancer. 29 VipAddress string `json:"vip_address"` 30 31 // The UUID of the port associated with the IP address. 32 VipPortID string `json:"vip_port_id"` 33 34 // The UUID of the subnet on which to allocate the virtual IP for the 35 // Loadbalancer address. 36 VipSubnetID string `json:"vip_subnet_id"` 37 38 // The unique ID for the LoadBalancer. 39 ID string `json:"id"` 40 41 // The operating status of the LoadBalancer. This value is ONLINE or OFFLINE. 42 OperatingStatus string `json:"operating_status"` 43 44 // Human-readable name for the LoadBalancer. Does not have to be unique. 45 Name string `json:"name"` 46 47 // The UUID of a flavor if set. 48 FlavorID string `json:"flavor_id"` 49 50 // The name of the provider. 51 Provider string `json:"provider"` 52 53 // Listeners are the listeners related to this Loadbalancer. 54 Listeners []listeners.Listener `json:"listeners"` 55 56 // Pools are the pools related to this Loadbalancer. 57 Pools []pools.Pool `json:"pools"` 58 } 59 60 // StatusTree represents the status of a loadbalancer. 61 type StatusTree struct { 62 Loadbalancer *LoadBalancer `json:"loadbalancer"` 63 } 64 65 type Stats struct { 66 // The currently active connections. 67 ActiveConnections int `json:"active_connections"` 68 69 // The total bytes received. 70 BytesIn int `json:"bytes_in"` 71 72 // The total bytes sent. 73 BytesOut int `json:"bytes_out"` 74 75 // The total requests that were unable to be fulfilled. 76 RequestErrors int `json:"request_errors"` 77 78 // The total connections handled. 79 TotalConnections int `json:"total_connections"` 80 } 81 82 // LoadBalancerPage is the page returned by a pager when traversing over a 83 // collection of load balancers. 84 type LoadBalancerPage struct { 85 pagination.LinkedPageBase 86 } 87 88 // NextPageURL is invoked when a paginated collection of load balancers has 89 // reached the end of a page and the pager seeks to traverse over a new one. 90 // In order to do this, it needs to construct the next page's URL. 91 func (r LoadBalancerPage) NextPageURL() (string, error) { 92 var s struct { 93 Links []gophercloud.Link `json:"loadbalancers_links"` 94 } 95 err := r.ExtractInto(&s) 96 if err != nil { 97 return "", err 98 } 99 return gophercloud.ExtractNextURL(s.Links) 100 } 101 102 // IsEmpty checks whether a LoadBalancerPage struct is empty. 103 func (r LoadBalancerPage) IsEmpty() (bool, error) { 104 if r.StatusCode == 204 { 105 return true, nil 106 } 107 108 is, err := ExtractLoadBalancers(r) 109 return len(is) == 0, err 110 } 111 112 // ExtractLoadBalancers accepts a Page struct, specifically a LoadbalancerPage 113 // struct, and extracts the elements into a slice of LoadBalancer structs. In 114 // other words, a generic collection is mapped into a relevant slice. 115 func ExtractLoadBalancers(r pagination.Page) ([]LoadBalancer, error) { 116 var s struct { 117 LoadBalancers []LoadBalancer `json:"loadbalancers"` 118 } 119 err := (r.(LoadBalancerPage)).ExtractInto(&s) 120 return s.LoadBalancers, err 121 } 122 123 type commonResult struct { 124 gophercloud.Result 125 } 126 127 // Extract is a function that accepts a result and extracts a loadbalancer. 128 func (r commonResult) Extract() (*LoadBalancer, error) { 129 var s struct { 130 LoadBalancer *LoadBalancer `json:"loadbalancer"` 131 } 132 err := r.ExtractInto(&s) 133 return s.LoadBalancer, err 134 } 135 136 // GetStatusesResult represents the result of a GetStatuses operation. 137 // Call its Extract method to interpret it as a StatusTree. 138 type GetStatusesResult struct { 139 gophercloud.Result 140 } 141 142 // Extract is a function that accepts a result and extracts the status of 143 // a Loadbalancer. 144 func (r GetStatusesResult) Extract() (*StatusTree, error) { 145 var s struct { 146 Statuses *StatusTree `json:"statuses"` 147 } 148 err := r.ExtractInto(&s) 149 return s.Statuses, err 150 } 151 152 // StatsResult represents the result of a GetStats operation. 153 // Call its Extract method to interpret it as a Stats. 154 type StatsResult struct { 155 gophercloud.Result 156 } 157 158 // Extract is a function that accepts a result and extracts the status of 159 // a Loadbalancer. 160 func (r StatsResult) Extract() (*Stats, error) { 161 var s struct { 162 Stats *Stats `json:"stats"` 163 } 164 err := r.ExtractInto(&s) 165 return s.Stats, err 166 } 167 168 // CreateResult represents the result of a create operation. Call its Extract 169 // method to interpret it as a LoadBalancer. 170 type CreateResult struct { 171 commonResult 172 } 173 174 // GetResult represents the result of a get operation. Call its Extract 175 // method to interpret it as a LoadBalancer. 176 type GetResult struct { 177 commonResult 178 } 179 180 // UpdateResult represents the result of an update operation. Call its Extract 181 // method to interpret it as a LoadBalancer. 182 type UpdateResult struct { 183 commonResult 184 } 185 186 // DeleteResult represents the result of a delete operation. Call its 187 // ExtractErr method to determine if the request succeeded or failed. 188 type DeleteResult struct { 189 gophercloud.ErrResult 190 }