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

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