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