github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/lbaas_v2/pools/results.go (about) 1 package pools 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors" 6 "github.com/gophercloud/gophercloud/pagination" 7 ) 8 9 // SessionPersistence represents the session persistence feature of the load 10 // balancing service. It attempts to force connections or requests in the same 11 // session to be processed by the same member as long as it is ative. Three 12 // types of persistence are supported: 13 // 14 // SOURCE_IP: With this mode, all connections originating from the same source 15 // 16 // IP address, will be handled by the same Member of the Pool. 17 // 18 // HTTP_COOKIE: With this persistence mode, the load balancing function will 19 // 20 // create a cookie on the first request from a client. Subsequent 21 // requests containing the same cookie value will be handled by 22 // the same Member of the Pool. 23 // 24 // APP_COOKIE: With this persistence mode, the load balancing function will 25 // 26 // rely on a cookie established by the backend application. All 27 // requests carrying the same cookie value will be handled by the 28 // same Member of the Pool. 29 type SessionPersistence struct { 30 // The type of persistence mode. 31 Type string `json:"type"` 32 33 // Name of cookie if persistence mode is set appropriately. 34 CookieName string `json:"cookie_name,omitempty"` 35 } 36 37 // LoadBalancerID represents a load balancer. 38 type LoadBalancerID struct { 39 ID string `json:"id"` 40 } 41 42 // ListenerID represents a listener. 43 type ListenerID struct { 44 ID string `json:"id"` 45 } 46 47 // Pool represents a logical set of devices, such as web servers, that you 48 // group together to receive and process traffic. The load balancing function 49 // chooses a Member of the Pool according to the configured load balancing 50 // method to handle the new requests or connections received on the VIP address. 51 type Pool struct { 52 // The load-balancer algorithm, which is round-robin, least-connections, and 53 // so on. This value, which must be supported, is dependent on the provider. 54 // Round-robin must be supported. 55 LBMethod string `json:"lb_algorithm"` 56 57 // The protocol of the Pool, which is TCP, HTTP, or HTTPS. 58 Protocol string `json:"protocol"` 59 60 // Description for the Pool. 61 Description string `json:"description"` 62 63 // A list of listeners objects IDs. 64 Listeners []ListenerID `json:"listeners"` //[]map[string]interface{} 65 66 // A list of member objects IDs. 67 Members []Member `json:"members"` 68 69 // The ID of associated health monitor. 70 MonitorID string `json:"healthmonitor_id"` 71 72 // The network on which the members of the Pool will be located. Only members 73 // that are on this network can be added to the Pool. 74 SubnetID string `json:"subnet_id"` 75 76 // Owner of the Pool. 77 TenantID string `json:"tenant_id"` 78 79 // The administrative state of the Pool, which is up (true) or down (false). 80 AdminStateUp bool `json:"admin_state_up"` 81 82 // Pool name. Does not have to be unique. 83 Name string `json:"name"` 84 85 // The unique ID for the Pool. 86 ID string `json:"id"` 87 88 // A list of load balancer objects IDs. 89 Loadbalancers []LoadBalancerID `json:"loadbalancers"` 90 91 // Indicates whether connections in the same session will be processed by the 92 // same Pool member or not. 93 Persistence SessionPersistence `json:"session_persistence"` 94 95 // The load balancer provider. 96 Provider string `json:"provider"` 97 98 // The Monitor associated with this Pool. 99 Monitor monitors.Monitor `json:"healthmonitor"` 100 101 // The provisioning status of the pool. 102 // This value is ACTIVE, PENDING_* or ERROR. 103 ProvisioningStatus string `json:"provisioning_status"` 104 105 // The operating status of the pool. 106 // This field seems to only be returned during a call to a load balancer's /status 107 // see: https://github.com/gophercloud/gophercloud/issues/1362 108 OperatingStatus string `json:"operating_status"` 109 } 110 111 // PoolPage is the page returned by a pager when traversing over a 112 // collection of pools. 113 type PoolPage struct { 114 pagination.LinkedPageBase 115 } 116 117 // NextPageURL is invoked when a paginated collection of pools has reached 118 // the end of a page and the pager seeks to traverse over a new one. In order 119 // to do this, it needs to construct the next page's URL. 120 func (r PoolPage) NextPageURL() (string, error) { 121 var s struct { 122 Links []gophercloud.Link `json:"pools_links"` 123 } 124 err := r.ExtractInto(&s) 125 if err != nil { 126 return "", err 127 } 128 return gophercloud.ExtractNextURL(s.Links) 129 } 130 131 // IsEmpty checks whether a PoolPage struct is empty. 132 func (r PoolPage) IsEmpty() (bool, error) { 133 if r.StatusCode == 204 { 134 return true, nil 135 } 136 137 is, err := ExtractPools(r) 138 return len(is) == 0, err 139 } 140 141 // ExtractPools accepts a Page struct, specifically a PoolPage struct, 142 // and extracts the elements into a slice of Pool structs. In other words, 143 // a generic collection is mapped into a relevant slice. 144 func ExtractPools(r pagination.Page) ([]Pool, error) { 145 var s struct { 146 Pools []Pool `json:"pools"` 147 } 148 err := (r.(PoolPage)).ExtractInto(&s) 149 return s.Pools, err 150 } 151 152 type commonResult struct { 153 gophercloud.Result 154 } 155 156 // Extract is a function that accepts a result and extracts a pool. 157 func (r commonResult) Extract() (*Pool, error) { 158 var s struct { 159 Pool *Pool `json:"pool"` 160 } 161 err := r.ExtractInto(&s) 162 return s.Pool, err 163 } 164 165 // CreateResult represents the result of a Create operation. Call its Extract 166 // method to interpret the result as a Pool. 167 type CreateResult struct { 168 commonResult 169 } 170 171 // GetResult represents the result of a Get operation. Call its Extract 172 // method to interpret the result as a Pool. 173 type GetResult struct { 174 commonResult 175 } 176 177 // UpdateResult represents the result of an Update operation. Call its Extract 178 // method to interpret the result as a Pool. 179 type UpdateResult struct { 180 commonResult 181 } 182 183 // DeleteResult represents the result of a Delete operation. Call its 184 // ExtractErr method to determine if the request succeeded or failed. 185 type DeleteResult struct { 186 gophercloud.ErrResult 187 } 188 189 // Member represents the application running on a backend server. 190 type Member struct { 191 // Name of the Member. 192 Name string `json:"name"` 193 194 // Weight of Member. 195 Weight int `json:"weight"` 196 197 // The administrative state of the member, which is up (true) or down (false). 198 AdminStateUp bool `json:"admin_state_up"` 199 200 // Owner of the Member. 201 TenantID string `json:"tenant_id"` 202 203 // Parameter value for the subnet UUID. 204 SubnetID string `json:"subnet_id"` 205 206 // The Pool to which the Member belongs. 207 PoolID string `json:"pool_id"` 208 209 // The IP address of the Member. 210 Address string `json:"address"` 211 212 // The port on which the application is hosted. 213 ProtocolPort int `json:"protocol_port"` 214 215 // The unique ID for the Member. 216 ID string `json:"id"` 217 218 // The provisioning status of the member. 219 // This value is ACTIVE, PENDING_* or ERROR. 220 ProvisioningStatus string `json:"provisioning_status"` 221 222 // The operating status of the member. 223 // This field seems to only be returned during a call to a load balancer's /status 224 // see: https://github.com/gophercloud/gophercloud/issues/1362 225 OperatingStatus string `json:"operating_status"` 226 } 227 228 // MemberPage is the page returned by a pager when traversing over a 229 // collection of Members in a Pool. 230 type MemberPage struct { 231 pagination.LinkedPageBase 232 } 233 234 // NextPageURL is invoked when a paginated collection of members has reached 235 // the end of a page and the pager seeks to traverse over a new one. In order 236 // to do this, it needs to construct the next page's URL. 237 func (r MemberPage) NextPageURL() (string, error) { 238 var s struct { 239 Links []gophercloud.Link `json:"members_links"` 240 } 241 err := r.ExtractInto(&s) 242 if err != nil { 243 return "", err 244 } 245 return gophercloud.ExtractNextURL(s.Links) 246 } 247 248 // IsEmpty checks whether a MemberPage struct is empty. 249 func (r MemberPage) IsEmpty() (bool, error) { 250 if r.StatusCode == 204 { 251 return true, nil 252 } 253 254 is, err := ExtractMembers(r) 255 return len(is) == 0, err 256 } 257 258 // ExtractMembers accepts a Page struct, specifically a MemberPage struct, 259 // and extracts the elements into a slice of Members structs. In other words, 260 // a generic collection is mapped into a relevant slice. 261 func ExtractMembers(r pagination.Page) ([]Member, error) { 262 var s struct { 263 Members []Member `json:"members"` 264 } 265 err := (r.(MemberPage)).ExtractInto(&s) 266 return s.Members, err 267 } 268 269 type commonMemberResult struct { 270 gophercloud.Result 271 } 272 273 // ExtractMember is a function that accepts a result and extracts a member. 274 func (r commonMemberResult) Extract() (*Member, error) { 275 var s struct { 276 Member *Member `json:"member"` 277 } 278 err := r.ExtractInto(&s) 279 return s.Member, err 280 } 281 282 // CreateMemberResult represents the result of a CreateMember operation. 283 // Call its Extract method to interpret it as a Member. 284 type CreateMemberResult struct { 285 commonMemberResult 286 } 287 288 // GetMemberResult represents the result of a GetMember operation. 289 // Call its Extract method to interpret it as a Member. 290 type GetMemberResult struct { 291 commonMemberResult 292 } 293 294 // UpdateMemberResult represents the result of an UpdateMember operation. 295 // Call its Extract method to interpret it as a Member. 296 type UpdateMemberResult struct { 297 commonMemberResult 298 } 299 300 // DeleteMemberResult represents the result of a DeleteMember operation. 301 // Call its ExtractErr method to determine if the request succeeded or failed. 302 type DeleteMemberResult struct { 303 gophercloud.ErrResult 304 }