github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/elb/v3/monitors/results.go (about)

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