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