github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/lbaas/pools/results.go (about)

     1  package pools
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  // Pool represents a logical set of devices, such as web servers, that you
     9  // group together to receive and process traffic. The load balancing function
    10  // chooses a member of the pool according to the configured load balancing
    11  // method to handle the new requests or connections received on the VIP address.
    12  // There is only one pool per virtual IP.
    13  type Pool struct {
    14  	// Status of the pool. Indicates whether the pool is operational.
    15  	Status string
    16  
    17  	// LBMethod is the load-balancer algorithm, which is round-robin,
    18  	// least-connections, and so on. This value, which must be supported, is
    19  	// dependent on the provider.
    20  	LBMethod string `json:"lb_method"`
    21  
    22  	// Protocol of the pool, which is TCP, HTTP, or HTTPS.
    23  	Protocol string
    24  
    25  	// Description for the pool.
    26  	Description string
    27  
    28  	// MonitorIDs are the IDs of associated monitors which check the health of
    29  	// the pool members.
    30  	MonitorIDs []string `json:"health_monitors"`
    31  
    32  	// SubnetID is the network on which the members of the pool will be located.
    33  	// Only members that are on this network can be added to the pool.
    34  	SubnetID string `json:"subnet_id"`
    35  
    36  	// TenantID is the owner of the pool.
    37  	TenantID string `json:"tenant_id"`
    38  
    39  	// AdminStateUp is the administrative state of the pool, which is up
    40  	// (true) or down (false).
    41  	AdminStateUp bool `json:"admin_state_up"`
    42  
    43  	// Name of the pool.
    44  	Name string
    45  
    46  	// MemberIDs is the list of member IDs that belong to the pool.
    47  	MemberIDs []string `json:"members"`
    48  
    49  	// ID is the unique ID for the pool.
    50  	ID string
    51  
    52  	// VIPID is the ID of the virtual IP associated with this pool.
    53  	VIPID string `json:"vip_id"`
    54  
    55  	// The provider.
    56  	Provider string
    57  }
    58  
    59  // PoolPage is the page returned by a pager when traversing over a
    60  // collection of pools.
    61  type PoolPage struct {
    62  	pagination.LinkedPageBase
    63  }
    64  
    65  // NextPageURL is invoked when a paginated collection of pools has reached
    66  // the end of a page and the pager seeks to traverse over a new one. In order
    67  // to do this, it needs to construct the next page's URL.
    68  func (r PoolPage) NextPageURL() (string, error) {
    69  	var s struct {
    70  		Links []gophercloud.Link `json:"pools_links"`
    71  	}
    72  	err := r.ExtractInto(&s)
    73  	if err != nil {
    74  		return "", err
    75  	}
    76  	return gophercloud.ExtractNextURL(s.Links)
    77  }
    78  
    79  // IsEmpty checks whether a PoolPage struct is empty.
    80  func (r PoolPage) IsEmpty() (bool, error) {
    81  	if r.StatusCode == 204 {
    82  		return true, nil
    83  	}
    84  
    85  	is, err := ExtractPools(r)
    86  	return len(is) == 0, err
    87  }
    88  
    89  // ExtractPools accepts a Page struct, specifically a PoolPage struct,
    90  // and extracts the elements into a slice of Router structs. In other words,
    91  // a generic collection is mapped into a relevant slice.
    92  func ExtractPools(r pagination.Page) ([]Pool, error) {
    93  	var s struct {
    94  		Pools []Pool `json:"pools"`
    95  	}
    96  	err := (r.(PoolPage)).ExtractInto(&s)
    97  	return s.Pools, err
    98  }
    99  
   100  type commonResult struct {
   101  	gophercloud.Result
   102  }
   103  
   104  // Extract is a function that accepts a result and extracts a router.
   105  func (r commonResult) Extract() (*Pool, error) {
   106  	var s struct {
   107  		Pool *Pool `json:"pool"`
   108  	}
   109  	err := r.ExtractInto(&s)
   110  	return s.Pool, err
   111  }
   112  
   113  // CreateResult represents the result of a create operation. Call its Extract
   114  // method to interpret it as a Pool.
   115  type CreateResult struct {
   116  	commonResult
   117  }
   118  
   119  // GetResult represents the result of a get operation. Call its Extract
   120  // method to interpret it as a Pool.
   121  type GetResult struct {
   122  	commonResult
   123  }
   124  
   125  // UpdateResult represents the result of an update operation. Call its Extract
   126  // method to interpret it as a Pool.
   127  type UpdateResult struct {
   128  	commonResult
   129  }
   130  
   131  // DeleteResult represents the result of a delete operation. Call its
   132  // ExtractErr method to interpret it as a Pool.
   133  type DeleteResult struct {
   134  	gophercloud.ErrResult
   135  }
   136  
   137  // AssociateResult represents the result of an association operation. Call its Extract
   138  // method to interpret it as a Pool.
   139  type AssociateResult struct {
   140  	commonResult
   141  }