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