github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/loadbalancer/v2/pools/results.go (about) 1 package pools 2 3 import ( 4 "encoding/json" 5 "time" 6 7 "github.com/vnpaycloud-console/gophercloud/v2" 8 "github.com/vnpaycloud-console/gophercloud/v2/openstack/loadbalancer/v2/monitors" 9 "github.com/vnpaycloud-console/gophercloud/v2/pagination" 10 ) 11 12 // SessionPersistence represents the session persistence feature of the load 13 // balancing service. It attempts to force connections or requests in the same 14 // session to be processed by the same member as long as it is ative. Three 15 // types of persistence are supported: 16 // 17 // SOURCE_IP: With this mode, all connections originating from the same source 18 // 19 // IP address, will be handled by the same Member of the Pool. 20 // 21 // HTTP_COOKIE: With this persistence mode, the load balancing function will 22 // 23 // create a cookie on the first request from a client. Subsequent 24 // requests containing the same cookie value will be handled by 25 // the same Member of the Pool. 26 // 27 // APP_COOKIE: With this persistence mode, the load balancing function will 28 // 29 // rely on a cookie established by the backend application. All 30 // requests carrying the same cookie value will be handled by the 31 // same Member of the Pool. 32 type SessionPersistence struct { 33 // The type of persistence mode. 34 Type string `json:"type"` 35 36 // Name of cookie if persistence mode is set appropriately. 37 CookieName string `json:"cookie_name,omitempty"` 38 } 39 40 // LoadBalancerID represents a load balancer. 41 type LoadBalancerID struct { 42 ID string `json:"id"` 43 } 44 45 // ListenerID represents a listener. 46 type ListenerID struct { 47 ID string `json:"id"` 48 } 49 50 // Pool represents a logical set of devices, such as web servers, that you 51 // group together to receive and process traffic. The load balancing function 52 // chooses a Member of the Pool according to the configured load balancing 53 // method to handle the new requests or connections received on the VIP address. 54 type Pool struct { 55 // The load-balancer algorithm, which is round-robin, least-connections, and 56 // so on. This value, which must be supported, is dependent on the provider. 57 // Round-robin must be supported. 58 LBMethod string `json:"lb_algorithm"` 59 60 // The protocol of the Pool, which is TCP, HTTP, or HTTPS. 61 Protocol string `json:"protocol"` 62 63 // Description for the Pool. 64 Description string `json:"description"` 65 66 // A list of listeners objects IDs. 67 Listeners []ListenerID `json:"listeners"` //[]map[string]any 68 69 // A list of member objects IDs. 70 Members []Member `json:"members"` 71 72 // The ID of associated health monitor. 73 MonitorID string `json:"healthmonitor_id"` 74 75 // The network on which the members of the Pool will be located. Only members 76 // that are on this network can be added to the Pool. 77 SubnetID string `json:"subnet_id"` 78 79 // Owner of the Pool. 80 ProjectID string `json:"project_id"` 81 82 // The administrative state of the Pool, which is up (true) or down (false). 83 AdminStateUp bool `json:"admin_state_up"` 84 85 // Pool name. Does not have to be unique. 86 Name string `json:"name"` 87 88 // The unique ID for the Pool. 89 ID string `json:"id"` 90 91 // A list of load balancer objects IDs. 92 Loadbalancers []LoadBalancerID `json:"loadbalancers"` 93 94 // Indicates whether connections in the same session will be processed by the 95 // same Pool member or not. 96 Persistence SessionPersistence `json:"session_persistence"` 97 98 // A list of ALPN protocols. Available protocols: http/1.0, http/1.1, 99 // h2. Available from microversion 2.24. 100 ALPNProtocols []string `json:"alpn_protocols"` 101 102 // The reference of the key manager service secret containing a PEM 103 // format CA certificate bundle for tls_enabled pools. Available from 104 // microversion 2.8. 105 CATLSContainerRef string `json:"ca_tls_container_ref"` 106 107 // The reference of the key manager service secret containing a PEM 108 // format CA revocation list file for tls_enabled pools. Available from 109 // microversion 2.8. 110 CRLContainerRef string `json:"crl_container_ref"` 111 112 // When true connections to backend member servers will use TLS 113 // encryption. Default is false. Available from microversion 2.8. 114 TLSEnabled bool `json:"tls_enabled"` 115 116 // List of ciphers in OpenSSL format (colon-separated). Available from 117 // microversion 2.15. 118 TLSCiphers string `json:"tls_ciphers"` 119 120 // The reference to the key manager service secret containing a PKCS12 121 // format certificate/key bundle for tls_enabled pools for TLS client 122 // authentication to the member servers. Available from microversion 2.8. 123 TLSContainerRef string `json:"tls_container_ref"` 124 125 // A list of TLS protocol versions. Available versions: SSLv3, TLSv1, 126 // TLSv1.1, TLSv1.2, TLSv1.3. Available from microversion 2.17. 127 TLSVersions []string `json:"tls_versions"` 128 129 // The load balancer provider. 130 Provider string `json:"provider"` 131 132 // The Monitor associated with this Pool. 133 Monitor monitors.Monitor `json:"healthmonitor"` 134 135 // The provisioning status of the pool. 136 // This value is ACTIVE, PENDING_* or ERROR. 137 ProvisioningStatus string `json:"provisioning_status"` 138 139 // The operating status of the pool. 140 OperatingStatus string `json:"operating_status"` 141 142 // Tags is a list of resource tags. Tags are arbitrarily defined strings 143 // attached to the resource. New in version 2.5 144 Tags []string `json:"tags"` 145 } 146 147 // PoolPage is the page returned by a pager when traversing over a 148 // collection of pools. 149 type PoolPage struct { 150 pagination.LinkedPageBase 151 } 152 153 // NextPageURL is invoked when a paginated collection of pools has reached 154 // the end of a page and the pager seeks to traverse over a new one. In order 155 // to do this, it needs to construct the next page's URL. 156 func (r PoolPage) NextPageURL() (string, error) { 157 var s struct { 158 Links []gophercloud.Link `json:"pools_links"` 159 } 160 err := r.ExtractInto(&s) 161 if err != nil { 162 return "", err 163 } 164 return gophercloud.ExtractNextURL(s.Links) 165 } 166 167 // IsEmpty checks whether a PoolPage struct is empty. 168 func (r PoolPage) IsEmpty() (bool, error) { 169 if r.StatusCode == 204 { 170 return true, nil 171 } 172 173 is, err := ExtractPools(r) 174 return len(is) == 0, err 175 } 176 177 // ExtractPools accepts a Page struct, specifically a PoolPage struct, 178 // and extracts the elements into a slice of Pool structs. In other words, 179 // a generic collection is mapped into a relevant slice. 180 func ExtractPools(r pagination.Page) ([]Pool, error) { 181 var s struct { 182 Pools []Pool `json:"pools"` 183 } 184 err := (r.(PoolPage)).ExtractInto(&s) 185 return s.Pools, err 186 } 187 188 type commonResult struct { 189 gophercloud.Result 190 } 191 192 // Extract is a function that accepts a result and extracts a pool. 193 func (r commonResult) Extract() (*Pool, error) { 194 var s struct { 195 Pool *Pool `json:"pool"` 196 } 197 err := r.ExtractInto(&s) 198 return s.Pool, err 199 } 200 201 // CreateResult represents the result of a Create operation. Call its Extract 202 // method to interpret the result as a Pool. 203 type CreateResult struct { 204 commonResult 205 } 206 207 // GetResult represents the result of a Get operation. Call its Extract 208 // method to interpret the result as a Pool. 209 type GetResult struct { 210 commonResult 211 } 212 213 // UpdateResult represents the result of an Update operation. Call its Extract 214 // method to interpret the result as a Pool. 215 type UpdateResult struct { 216 commonResult 217 } 218 219 // DeleteResult represents the result of a Delete operation. Call its 220 // ExtractErr method to determine if the request succeeded or failed. 221 type DeleteResult struct { 222 gophercloud.ErrResult 223 } 224 225 // Member represents the application running on a backend server. 226 type Member struct { 227 // Name of the Member. 228 Name string `json:"name"` 229 230 // Weight of Member. 231 Weight int `json:"weight"` 232 233 // The administrative state of the member, which is up (true) or down (false). 234 AdminStateUp bool `json:"admin_state_up"` 235 236 // Owner of the Member. 237 ProjectID string `json:"project_id"` 238 239 // Parameter value for the subnet UUID. 240 SubnetID string `json:"subnet_id"` 241 242 // The Pool to which the Member belongs. 243 PoolID string `json:"pool_id"` 244 245 // The IP address of the Member. 246 Address string `json:"address"` 247 248 // The port on which the application is hosted. 249 ProtocolPort int `json:"protocol_port"` 250 251 // The unique ID for the Member. 252 ID string `json:"id"` 253 254 // The provisioning status of the pool. 255 // This value is ACTIVE, PENDING_* or ERROR. 256 ProvisioningStatus string `json:"provisioning_status"` 257 258 // DateTime when the member was created 259 CreatedAt time.Time `json:"-"` 260 261 // DateTime when the member was updated 262 UpdatedAt time.Time `json:"-"` 263 264 // The operating status of the member 265 OperatingStatus string `json:"operating_status"` 266 267 // Is the member a backup? Backup members only receive traffic when all non-backup members are down. 268 Backup bool `json:"backup"` 269 270 // An alternate IP address used for health monitoring a backend member. 271 MonitorAddress string `json:"monitor_address"` 272 273 // An alternate protocol port used for health monitoring a backend member. 274 MonitorPort int `json:"monitor_port"` 275 276 // A list of simple strings assigned to the resource. 277 // Requires microversion 2.5 or later. 278 Tags []string `json:"tags"` 279 } 280 281 // MemberPage is the page returned by a pager when traversing over a 282 // collection of Members in a Pool. 283 type MemberPage struct { 284 pagination.LinkedPageBase 285 } 286 287 // NextPageURL is invoked when a paginated collection of members has reached 288 // the end of a page and the pager seeks to traverse over a new one. In order 289 // to do this, it needs to construct the next page's URL. 290 func (r MemberPage) NextPageURL() (string, error) { 291 var s struct { 292 Links []gophercloud.Link `json:"members_links"` 293 } 294 err := r.ExtractInto(&s) 295 if err != nil { 296 return "", err 297 } 298 return gophercloud.ExtractNextURL(s.Links) 299 } 300 301 // IsEmpty checks whether a MemberPage struct is empty. 302 func (r MemberPage) IsEmpty() (bool, error) { 303 if r.StatusCode == 204 { 304 return true, nil 305 } 306 307 is, err := ExtractMembers(r) 308 return len(is) == 0, err 309 } 310 311 // ExtractMembers accepts a Page struct, specifically a MemberPage struct, 312 // and extracts the elements into a slice of Members structs. In other words, 313 // a generic collection is mapped into a relevant slice. 314 func ExtractMembers(r pagination.Page) ([]Member, error) { 315 var s struct { 316 Members []Member `json:"members"` 317 } 318 err := (r.(MemberPage)).ExtractInto(&s) 319 return s.Members, err 320 } 321 322 type commonMemberResult struct { 323 gophercloud.Result 324 } 325 326 func (r *Member) UnmarshalJSON(b []byte) error { 327 type tmp Member 328 var s struct { 329 tmp 330 CreatedAt gophercloud.JSONRFC3339NoZ `json:"created_at"` 331 UpdatedAt gophercloud.JSONRFC3339NoZ `json:"updated_at"` 332 } 333 err := json.Unmarshal(b, &s) 334 if err != nil { 335 return err 336 } 337 *r = Member(s.tmp) 338 r.CreatedAt = time.Time(s.CreatedAt) 339 r.UpdatedAt = time.Time(s.UpdatedAt) 340 return nil 341 } 342 343 // ExtractMember is a function that accepts a result and extracts a member. 344 func (r commonMemberResult) Extract() (*Member, error) { 345 var s struct { 346 Member *Member `json:"member"` 347 } 348 err := r.ExtractInto(&s) 349 return s.Member, err 350 } 351 352 // CreateMemberResult represents the result of a CreateMember operation. 353 // Call its Extract method to interpret it as a Member. 354 type CreateMemberResult struct { 355 commonMemberResult 356 } 357 358 // GetMemberResult represents the result of a GetMember operation. 359 // Call its Extract method to interpret it as a Member. 360 type GetMemberResult struct { 361 commonMemberResult 362 } 363 364 // UpdateMemberResult represents the result of an UpdateMember operation. 365 // Call its Extract method to interpret it as a Member. 366 type UpdateMemberResult struct { 367 commonMemberResult 368 } 369 370 // UpdateMembersResult represents the result of an UpdateMembers operation. 371 // Call its ExtractErr method to determine if the request succeeded or failed. 372 type UpdateMembersResult struct { 373 gophercloud.ErrResult 374 } 375 376 // DeleteMemberResult represents the result of a DeleteMember operation. 377 // Call its ExtractErr method to determine if the request succeeded or failed. 378 type DeleteMemberResult struct { 379 gophercloud.ErrResult 380 }