github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/elb/v3/monitors/results.go (about)

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