github.com/gophercloud/gophercloud@v1.11.0/openstack/loadbalancer/v2/listeners/results.go (about)

     1  package listeners
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/l7policies"
     6  	"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools"
     7  	"github.com/gophercloud/gophercloud/pagination"
     8  )
     9  
    10  type LoadBalancerID struct {
    11  	ID string `json:"id"`
    12  }
    13  
    14  // Listener is the primary load balancing configuration object that specifies
    15  // the loadbalancer and port on which client traffic is received, as well
    16  // as other details such as the load balancing method to be use, protocol, etc.
    17  type Listener struct {
    18  	// The unique ID for the Listener.
    19  	ID string `json:"id"`
    20  
    21  	// Owner of the Listener.
    22  	ProjectID string `json:"project_id"`
    23  
    24  	// Human-readable name for the Listener. Does not have to be unique.
    25  	Name string `json:"name"`
    26  
    27  	// Human-readable description for the Listener.
    28  	Description string `json:"description"`
    29  
    30  	// The protocol to loadbalance. A valid value is TCP, SCTP, HTTP, HTTPS or TERMINATED_HTTPS.
    31  	Protocol string `json:"protocol"`
    32  
    33  	// The port on which to listen to client traffic that is associated with the
    34  	// Loadbalancer. A valid value is from 0 to 65535.
    35  	ProtocolPort int `json:"protocol_port"`
    36  
    37  	// The UUID of default pool. Must have compatible protocol with listener.
    38  	DefaultPoolID string `json:"default_pool_id"`
    39  
    40  	// The default pool with which the Listener is associated.
    41  	DefaultPool *pools.Pool `json:"default_pool"`
    42  
    43  	// A list of load balancer IDs.
    44  	Loadbalancers []LoadBalancerID `json:"loadbalancers"`
    45  
    46  	// The maximum number of connections allowed for the Loadbalancer.
    47  	// Default is -1, meaning no limit.
    48  	ConnLimit int `json:"connection_limit"`
    49  
    50  	// The list of references to TLS secrets.
    51  	SniContainerRefs []string `json:"sni_container_refs"`
    52  
    53  	// A reference to a Barbican container of TLS secrets.
    54  	DefaultTlsContainerRef string `json:"default_tls_container_ref"`
    55  
    56  	// The administrative state of the Listener. A valid value is true (UP) or false (DOWN).
    57  	AdminStateUp bool `json:"admin_state_up"`
    58  
    59  	// Pools are the pools which are part of this listener.
    60  	Pools []pools.Pool `json:"pools"`
    61  
    62  	// L7policies are the L7 policies which are part of this listener.
    63  	L7Policies []l7policies.L7Policy `json:"l7policies"`
    64  
    65  	// The provisioning status of the Listener.
    66  	// This value is ACTIVE, PENDING_* or ERROR.
    67  	ProvisioningStatus string `json:"provisioning_status"`
    68  
    69  	// Frontend client inactivity timeout in milliseconds
    70  	TimeoutClientData int `json:"timeout_client_data"`
    71  
    72  	// Backend member inactivity timeout in milliseconds
    73  	TimeoutMemberData int `json:"timeout_member_data"`
    74  
    75  	// Backend member connection timeout in milliseconds
    76  	TimeoutMemberConnect int `json:"timeout_member_connect"`
    77  
    78  	// Time, in milliseconds, to wait for additional TCP packets for content inspection
    79  	TimeoutTCPInspect int `json:"timeout_tcp_inspect"`
    80  
    81  	// A dictionary of optional headers to insert into the request before it is sent to the backend member.
    82  	InsertHeaders map[string]string `json:"insert_headers"`
    83  
    84  	// A list of IPv4, IPv6 or mix of both CIDRs
    85  	AllowedCIDRs []string `json:"allowed_cidrs"`
    86  
    87  	// List of ciphers in OpenSSL format (colon-separated). See
    88  	// https://www.openssl.org/docs/man1.1.1/man1/ciphers.html
    89  	// New in version 2.15
    90  	TLSCiphers string `json:"tls_ciphers"`
    91  
    92  	// A list of TLS protocol versions. Available from microversion 2.17
    93  	TLSVersions []string `json:"tls_versions"`
    94  
    95  	// Tags is a list of resource tags. Tags are arbitrarily defined strings
    96  	// attached to the resource. New in version 2.5
    97  	Tags []string `json:"tags"`
    98  
    99  	// A list of ALPN protocols. Available protocols: http/1.0, http/1.1, h2
   100  	// New in version 2.20
   101  	ALPNProtocols []string `json:"alpn_protocols"`
   102  
   103  	// The TLS client authentication mode. One of the options NONE, OPTIONAL or MANDATORY.
   104  	// New in version 2.8
   105  	ClientAuthentication string `json:"client_authentication"`
   106  
   107  	// The ref of the key manager service secret containing a PEM format
   108  	// client CA certificate bundle for TERMINATED_HTTPS listeners.
   109  	// New in version 2.8
   110  	ClientCATLSContainerRef string `json:"client_ca_tls_container_ref"`
   111  
   112  	// The URI of the key manager service secret containing a PEM format CA
   113  	// revocation list file for TERMINATED_HTTPS listeners.
   114  	// New in version 2.8
   115  	ClientCRLContainerRef string `json:"client_crl_container_ref"`
   116  
   117  	// The operating status of the resource
   118  	OperatingStatus string `json:"operating_status"`
   119  }
   120  
   121  type Stats struct {
   122  	// The currently active connections.
   123  	ActiveConnections int `json:"active_connections"`
   124  
   125  	// The total bytes received.
   126  	BytesIn int `json:"bytes_in"`
   127  
   128  	// The total bytes sent.
   129  	BytesOut int `json:"bytes_out"`
   130  
   131  	// The total requests that were unable to be fulfilled.
   132  	RequestErrors int `json:"request_errors"`
   133  
   134  	// The total connections handled.
   135  	TotalConnections int `json:"total_connections"`
   136  }
   137  
   138  // ListenerPage is the page returned by a pager when traversing over a
   139  // collection of listeners.
   140  type ListenerPage struct {
   141  	pagination.LinkedPageBase
   142  }
   143  
   144  // NextPageURL is invoked when a paginated collection of listeners has reached
   145  // the end of a page and the pager seeks to traverse over a new one. In order
   146  // to do this, it needs to construct the next page's URL.
   147  func (r ListenerPage) NextPageURL() (string, error) {
   148  	var s struct {
   149  		Links []gophercloud.Link `json:"listeners_links"`
   150  	}
   151  	err := r.ExtractInto(&s)
   152  	if err != nil {
   153  		return "", err
   154  	}
   155  	return gophercloud.ExtractNextURL(s.Links)
   156  }
   157  
   158  // IsEmpty checks whether a ListenerPage struct is empty.
   159  func (r ListenerPage) IsEmpty() (bool, error) {
   160  	if r.StatusCode == 204 {
   161  		return true, nil
   162  	}
   163  
   164  	is, err := ExtractListeners(r)
   165  	return len(is) == 0, err
   166  }
   167  
   168  // ExtractListeners accepts a Page struct, specifically a ListenerPage struct,
   169  // and extracts the elements into a slice of Listener structs. In other words,
   170  // a generic collection is mapped into a relevant slice.
   171  func ExtractListeners(r pagination.Page) ([]Listener, error) {
   172  	var s struct {
   173  		Listeners []Listener `json:"listeners"`
   174  	}
   175  	err := (r.(ListenerPage)).ExtractInto(&s)
   176  	return s.Listeners, err
   177  }
   178  
   179  type commonResult struct {
   180  	gophercloud.Result
   181  }
   182  
   183  // Extract is a function that accepts a result and extracts a listener.
   184  func (r commonResult) Extract() (*Listener, error) {
   185  	var s struct {
   186  		Listener *Listener `json:"listener"`
   187  	}
   188  	err := r.ExtractInto(&s)
   189  	return s.Listener, err
   190  }
   191  
   192  // CreateResult represents the result of a create operation. Call its Extract
   193  // method to interpret it as a Listener.
   194  type CreateResult struct {
   195  	commonResult
   196  }
   197  
   198  // GetResult represents the result of a get operation. Call its Extract
   199  // method to interpret it as a Listener.
   200  type GetResult struct {
   201  	commonResult
   202  }
   203  
   204  // UpdateResult represents the result of an update operation. Call its Extract
   205  // method to interpret it as a Listener.
   206  type UpdateResult struct {
   207  	commonResult
   208  }
   209  
   210  // DeleteResult represents the result of a delete operation. Call its
   211  // ExtractErr method to determine if the request succeeded or failed.
   212  type DeleteResult struct {
   213  	gophercloud.ErrResult
   214  }
   215  
   216  // StatsResult represents the result of a GetStats operation.
   217  // Call its Extract method to interpret it as a Stats.
   218  type StatsResult struct {
   219  	gophercloud.Result
   220  }
   221  
   222  // Extract is a function that accepts a result and extracts the status of
   223  // a Listener.
   224  func (r StatsResult) Extract() (*Stats, error) {
   225  	var s struct {
   226  		Stats *Stats `json:"stats"`
   227  	}
   228  	err := r.ExtractInto(&s)
   229  	return s.Stats, err
   230  }