github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/lbaas/vips/results.go (about)

     1  package vips
     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  	// Type is the type of persistence mode.
    25  	Type string `json:"type"`
    26  
    27  	// CookieName is the name of cookie if persistence mode is set appropriately.
    28  	CookieName string `json:"cookie_name,omitempty"`
    29  }
    30  
    31  // VirtualIP is the primary load balancing configuration object that specifies
    32  // the virtual IP address and port on which client traffic is received, as well
    33  // as other details such as the load balancing method to be use, protocol, etc.
    34  // This entity is sometimes known in LB products under the name of a "virtual
    35  // server", a "vserver" or a "listener".
    36  type VirtualIP struct {
    37  	// ID is the unique ID for the VIP.
    38  	ID string `json:"id"`
    39  
    40  	// TenantID is the owner of the VIP.
    41  	TenantID string `json:"tenant_id"`
    42  
    43  	// Name is the human-readable name for the VIP. Does not have to be unique.
    44  	Name string `json:"name"`
    45  
    46  	// Description is the human-readable description for the VIP.
    47  	Description string `json:"description"`
    48  
    49  	// SubnetID is the ID of the subnet on which to allocate the VIP address.
    50  	SubnetID string `json:"subnet_id"`
    51  
    52  	// Address is the IP address of the VIP.
    53  	Address string `json:"address"`
    54  
    55  	// Protocol of the VIP address. A valid value is TCP, HTTP, or HTTPS.
    56  	Protocol string `json:"protocol"`
    57  
    58  	// ProtocolPort is the port on which to listen to client traffic that is
    59  	// associated with the VIP address. A valid value is from 0 to 65535.
    60  	ProtocolPort int `json:"protocol_port"`
    61  
    62  	// PoolID is the ID of the pool with which the VIP is associated.
    63  	PoolID string `json:"pool_id"`
    64  
    65  	// PortID is the ID of the port which belongs to the load balancer.
    66  	PortID string `json:"port_id"`
    67  
    68  	// Persistence indicates whether connections in the same session will be
    69  	// processed by the same pool member or not.
    70  	Persistence SessionPersistence `json:"session_persistence"`
    71  
    72  	// ConnLimit is the maximum number of connections allowed for the VIP.
    73  	// Default is -1, meaning no limit.
    74  	ConnLimit int `json:"connection_limit"`
    75  
    76  	// AdminStateUp is the administrative state of the VIP. A valid value is
    77  	// true (UP) or false (DOWN).
    78  	AdminStateUp bool `json:"admin_state_up"`
    79  
    80  	// Status is the status of the VIP. Indicates whether the VIP is operational.
    81  	Status string `json:"status"`
    82  }
    83  
    84  // VIPPage is the page returned by a pager when traversing over a
    85  // collection of virtual IPs.
    86  type VIPPage struct {
    87  	pagination.LinkedPageBase
    88  }
    89  
    90  // NextPageURL is invoked when a paginated collection of routers has reached
    91  // the end of a page and the pager seeks to traverse over a new one. In order
    92  // to do this, it needs to construct the next page's URL.
    93  func (r VIPPage) NextPageURL() (string, error) {
    94  	var s struct {
    95  		Links []golangsdk.Link `json:"vips_links"`
    96  	}
    97  	err := r.ExtractInto(&s)
    98  	if err != nil {
    99  		return "", err
   100  	}
   101  	return golangsdk.ExtractNextURL(s.Links)
   102  }
   103  
   104  // IsEmpty checks whether a VIPPage struct is empty.
   105  func (r VIPPage) IsEmpty() (bool, error) {
   106  	is, err := ExtractVIPs(r)
   107  	return len(is) == 0, err
   108  }
   109  
   110  // ExtractVIPs accepts a Page struct, specifically a VIPPage struct,
   111  // and extracts the elements into a slice of VirtualIP structs. In other words,
   112  // a generic collection is mapped into a relevant slice.
   113  func ExtractVIPs(r pagination.Page) ([]VirtualIP, error) {
   114  	var s struct {
   115  		VIPs []VirtualIP `json:"vips"`
   116  	}
   117  	err := (r.(VIPPage)).ExtractInto(&s)
   118  	return s.VIPs, err
   119  }
   120  
   121  type commonResult struct {
   122  	golangsdk.Result
   123  }
   124  
   125  // Extract is a function that accepts a result and extracts a VirtualIP.
   126  func (r commonResult) Extract() (*VirtualIP, error) {
   127  	var s struct {
   128  		VirtualIP *VirtualIP `json:"vip" json:"vip"`
   129  	}
   130  	err := r.ExtractInto(&s)
   131  	return s.VirtualIP, err
   132  }
   133  
   134  // CreateResult represents the result of a create operation. Call its Extract
   135  // method to interpret it as a VirtualIP
   136  type CreateResult struct {
   137  	commonResult
   138  }
   139  
   140  // GetResult represents the result of a get operation. Call its Extract
   141  // method to interpret it as a VirtualIP
   142  type GetResult struct {
   143  	commonResult
   144  }
   145  
   146  // UpdateResult represents the result of an update operation. Call its Extract
   147  // method to interpret it as a VirtualIP
   148  type UpdateResult struct {
   149  	commonResult
   150  }
   151  
   152  // DeleteResult represents the result of a delete operation. Call its
   153  // ExtractErr method to determine if the request succeeded or failed.
   154  type DeleteResult struct {
   155  	golangsdk.ErrResult
   156  }