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