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