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