github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/elb/v2/monitors/results.go (about)

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