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

     1  package monitors
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  // Monitor represents a load balancer health monitor. A health monitor is used
     9  // to determine whether or not back-end members of the VIP's pool are usable
    10  // for processing a request. A pool can have several health monitors associated
    11  // with it. There are different types of health monitors supported:
    12  //
    13  // PING: used to ping the members using ICMP.
    14  // TCP: used to connect to the members using TCP.
    15  // HTTP: used to send an HTTP request to the member.
    16  // HTTPS: used to send a secure HTTP request to the member.
    17  //
    18  // When a pool has several monitors associated with it, each member of the pool
    19  // is monitored by all these monitors. If any monitor declares the member as
    20  // unhealthy, then the member status is changed to INACTIVE and the member
    21  // won't participate in its pool's load balancing. In other words, ALL monitors
    22  // must declare the member to be healthy for it to stay ACTIVE.
    23  type Monitor struct {
    24  	// ID is the unique ID for the Monitor.
    25  	ID string
    26  
    27  	// Name is the monitor name. Does not have to be unique.
    28  	Name string
    29  
    30  	// TenantID is the owner of the Monitor.
    31  	TenantID string `json:"tenant_id"`
    32  
    33  	// Type is the type of probe sent by the load balancer to verify the member
    34  	// state, which is PING, TCP, HTTP, or HTTPS.
    35  	Type string
    36  
    37  	// Delay is the time, in seconds, between sending probes to members.
    38  	Delay int
    39  
    40  	// Timeout is the maximum number of seconds for a monitor to wait for a
    41  	// connection to be established before it times out. This value must be less
    42  	// than the delay value.
    43  	Timeout int
    44  
    45  	// MaxRetries is the number of allowed connection failures before changing the
    46  	// status of the member to INACTIVE. A valid value is from 1 to 10.
    47  	MaxRetries int `json:"max_retries"`
    48  
    49  	// HTTPMethod is the HTTP method that the monitor uses for requests.
    50  	HTTPMethod string `json:"http_method"`
    51  
    52  	// URLPath is the HTTP path of the request sent by the monitor to test the
    53  	// health of a member. Must be a string beginning with a forward slash (/).
    54  	URLPath string `json:"url_path"`
    55  
    56  	// ExpectedCodes is the expected HTTP codes for a passing HTTP(S) monitor.
    57  	ExpectedCodes string `json:"expected_codes"`
    58  
    59  	// AdminStateUp is the administrative state of the health monitor, which is up
    60  	// (true) or down (false).
    61  	AdminStateUp bool `json:"admin_state_up"`
    62  
    63  	// Status is the status of the health monitor. Indicates whether the health
    64  	// monitor is operational.
    65  	Status string
    66  }
    67  
    68  // MonitorPage is the page returned by a pager when traversing over a
    69  // collection of health monitors.
    70  type MonitorPage struct {
    71  	pagination.LinkedPageBase
    72  }
    73  
    74  // NextPageURL is invoked when a paginated collection of monitors has reached
    75  // the end of a page and the pager seeks to traverse over a new one. In order
    76  // to do this, it needs to construct the next page's URL.
    77  func (r MonitorPage) NextPageURL() (string, error) {
    78  	var s struct {
    79  		Links []gophercloud.Link `json:"health_monitors_links"`
    80  	}
    81  	err := r.ExtractInto(&s)
    82  	if err != nil {
    83  		return "", err
    84  	}
    85  
    86  	return gophercloud.ExtractNextURL(s.Links)
    87  }
    88  
    89  // IsEmpty checks whether a PoolPage struct is empty.
    90  func (r MonitorPage) IsEmpty() (bool, error) {
    91  	if r.StatusCode == 204 {
    92  		return true, nil
    93  	}
    94  
    95  	is, err := ExtractMonitors(r)
    96  	return len(is) == 0, err
    97  }
    98  
    99  // ExtractMonitors accepts a Page struct, specifically a MonitorPage struct,
   100  // and extracts the elements into a slice of Monitor structs. In other words,
   101  // a generic collection is mapped into a relevant slice.
   102  func ExtractMonitors(r pagination.Page) ([]Monitor, error) {
   103  	var s struct {
   104  		Monitors []Monitor `json:"health_monitors"`
   105  	}
   106  	err := (r.(MonitorPage)).ExtractInto(&s)
   107  	return s.Monitors, err
   108  }
   109  
   110  type commonResult struct {
   111  	gophercloud.Result
   112  }
   113  
   114  // Extract is a function that accepts a result and extracts a monitor.
   115  func (r commonResult) Extract() (*Monitor, error) {
   116  	var s struct {
   117  		Monitor *Monitor `json:"health_monitor"`
   118  	}
   119  	err := r.ExtractInto(&s)
   120  	return s.Monitor, err
   121  }
   122  
   123  // CreateResult represents the result of a create operation. Call its Extract
   124  // method to interpret it as a Monitor.
   125  type CreateResult struct {
   126  	commonResult
   127  }
   128  
   129  // GetResult represents the result of a get operation. Call its Extract
   130  // method to interpret it as a Monitor.
   131  type GetResult struct {
   132  	commonResult
   133  }
   134  
   135  // UpdateResult represents the result of an update operation. Call its Extract
   136  // method to interpret it as a Monitor.
   137  type UpdateResult struct {
   138  	commonResult
   139  }
   140  
   141  // DeleteResult represents the result of a delete operation. Call its Extract
   142  // method to determine if the request succeeded or failed.
   143  type DeleteResult struct {
   144  	gophercloud.ErrResult
   145  }