github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/lbaas_v2/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  	// Expected HTTP codes for a passing HTTP(S) monitor.
    61  	ExpectedCodes string `json:"expected_codes"`
    62  
    63  	// The administrative state of the health monitor, which is up (true) or
    64  	// down (false).
    65  	AdminStateUp bool `json:"admin_state_up"`
    66  
    67  	// The Port of the Monitor.
    68  	MonitorPort int `json:"monitor_port"`
    69  
    70  	// The status of the health monitor. Indicates whether the health monitor is
    71  	// operational.
    72  	Status string `json:"status"`
    73  
    74  	// List of pools that are associated with the health monitor.
    75  	Pools []PoolID `json:"pools"`
    76  
    77  	// The provisioning status of the monitor.
    78  	// This value is ACTIVE, PENDING_* or ERROR.
    79  	ProvisioningStatus string `json:"provisioning_status"`
    80  }
    81  
    82  // MonitorPage is the page returned by a pager when traversing over a
    83  // collection of health monitors.
    84  type MonitorPage struct {
    85  	pagination.LinkedPageBase
    86  }
    87  
    88  // NextPageURL is invoked when a paginated collection of monitors has reached
    89  // the end of a page and the pager seeks to traverse over a new one. In order
    90  // to do this, it needs to construct the next page's URL.
    91  func (r MonitorPage) NextPageURL() (string, error) {
    92  	var s struct {
    93  		Links []golangsdk.Link `json:"healthmonitors_links"`
    94  	}
    95  
    96  	err := r.ExtractInto(&s)
    97  	if err != nil {
    98  		return "", err
    99  	}
   100  
   101  	return golangsdk.ExtractNextURL(s.Links)
   102  }
   103  
   104  // IsEmpty checks whether a MonitorPage struct is empty.
   105  func (r MonitorPage) IsEmpty() (bool, error) {
   106  	is, err := ExtractMonitors(r)
   107  	return len(is) == 0, err
   108  }
   109  
   110  // ExtractMonitors accepts a Page struct, specifically a MonitorPage struct,
   111  // and extracts the elements into a slice of Monitor structs. In other words,
   112  // a generic collection is mapped into a relevant slice.
   113  func ExtractMonitors(r pagination.Page) ([]Monitor, error) {
   114  	var s struct {
   115  		Monitors []Monitor `json:"healthmonitors"`
   116  	}
   117  	err := (r.(MonitorPage)).ExtractInto(&s)
   118  	return s.Monitors, err
   119  }
   120  
   121  type commonResult struct {
   122  	golangsdk.Result
   123  }
   124  
   125  // Extract is a function that accepts a result and extracts a monitor.
   126  func (r commonResult) Extract() (*Monitor, error) {
   127  	var s struct {
   128  		Monitor *Monitor `json:"healthmonitor"`
   129  	}
   130  	err := r.ExtractInto(&s)
   131  	return s.Monitor, err
   132  }
   133  
   134  // CreateResult represents the result of a create operation. Call its Extract
   135  // method to interpret it as a Monitor.
   136  type CreateResult struct {
   137  	commonResult
   138  }
   139  
   140  // GetResult represents the result of a get operation. Call its Extract
   141  // method to interpret it as a Monitor.
   142  type GetResult struct {
   143  	commonResult
   144  }
   145  
   146  // UpdateResult represents the result of an update operation. Call its Extract
   147  // method to interpret it as a Monitor.
   148  type UpdateResult struct {
   149  	commonResult
   150  }
   151  
   152  // DeleteResult represents the result of a delete operation. Call its
   153  // ExtractErr method to determine if the result succeeded or failed.
   154  type DeleteResult struct {
   155  	golangsdk.ErrResult
   156  }