github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/elb/healthcheck/requests.go (about) 1 package healthcheck 2 3 import ( 4 "log" 5 6 "github.com/huaweicloud/golangsdk" 7 ) 8 9 // CreateOptsBuilder is the interface options structs have to satisfy in order 10 // to be used in the main Create operation in this package. Since many 11 // extensions decorate or modify the common logic, it is useful for them to 12 // satisfy a basic interface in order for them to be used. 13 type CreateOptsBuilder interface { 14 ToHealthCheckCreateMap() (map[string]interface{}, error) 15 } 16 17 // CreateOpts is the common options struct used in this package's Create 18 // operation. 19 type CreateOpts struct { 20 ListenerID string `json:"listener_id" required:"true"` 21 HealthcheckProtocol string `json:"healthcheck_protocol,omitempty"` 22 HealthcheckUri string `json:"healthcheck_uri,omitempty"` 23 HealthcheckConnectPort int `json:"healthcheck_connect_port,omitempty"` 24 HealthyThreshold int `json:"healthy_threshold,omitempty"` 25 UnhealthyThreshold int `json:"unhealthy_threshold,omitempty"` 26 HealthcheckTimeout int `json:"healthcheck_timeout,omitempty"` 27 HealthcheckInterval int `json:"healthcheck_interval,omitempty"` 28 } 29 30 // ToHealthCheckCreateMap casts a CreateOpts struct to a map. 31 func (opts CreateOpts) ToHealthCheckCreateMap() (map[string]interface{}, error) { 32 return golangsdk.BuildRequestBody(opts, "") 33 } 34 35 // Create is an operation which provisions a new loadbalancer based on the 36 // configuration defined in the CreateOpts struct. Once the request is 37 // validated and progress has started on the provisioning process, a 38 // CreateResult will be returned. 39 // 40 // Users with an admin role can create loadbalancers on behalf of other tenants by 41 // specifying a TenantID attribute different than their own. 42 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 43 b, err := opts.ToHealthCheckCreateMap() 44 if err != nil { 45 r.Err = err 46 return 47 } 48 log.Printf("[DEBUG] create ELB-HealthCheck url:%q, body=%#v", rootURL(c), b) 49 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 50 _, r.Err = c.Post(rootURL(c), b, &r.Body, reqOpt) 51 return 52 } 53 54 // Get retrieves a particular Loadbalancer based on its unique ID. 55 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 56 _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) 57 return 58 } 59 60 // UpdateOptsBuilder is the interface options structs have to satisfy in order 61 // to be used in the main Update operation in this package. Since many 62 // extensions decorate or modify the common logic, it is useful for them to 63 // satisfy a basic interface in order for them to be used. 64 type UpdateOptsBuilder interface { 65 ToHealthCheckUpdateMap() (map[string]interface{}, error) 66 } 67 68 // UpdateOpts is the common options struct used in this package's Update 69 // operation. 70 type UpdateOpts struct { 71 HealthcheckProtocol string `json:"healthcheck_protocol,omitempty"` 72 HealthcheckUri string `json:"healthcheck_uri,omitempty"` 73 HealthcheckConnectPort int `json:"healthcheck_connect_port,omitempty"` 74 HealthyThreshold int `json:"healthy_threshold,omitempty"` 75 UnhealthyThreshold int `json:"unhealthy_threshold,omitempty"` 76 HealthcheckTimeout int `json:"healthcheck_timeout,omitempty"` 77 HealthcheckInterval int `json:"healthcheck_interval,omitempty"` 78 } 79 80 func (u UpdateOpts) IsNeedUpdate() (bool, error) { 81 d, e := u.ToHealthCheckUpdateMap() 82 if e == nil { 83 return len(d) != 0, nil 84 } 85 return false, e 86 } 87 88 // ToHealthCheckUpdateMap casts a UpdateOpts struct to a map. 89 func (opts UpdateOpts) ToHealthCheckUpdateMap() (map[string]interface{}, error) { 90 return golangsdk.BuildRequestBody(opts, "") 91 } 92 93 // Update is an operation which modifies the attributes of the specified HealthCheck. 94 func Update(c *golangsdk.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) { 95 b, err := opts.ToHealthCheckUpdateMap() 96 if err != nil { 97 r.Err = err 98 return 99 } 100 _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &golangsdk.RequestOpts{ 101 OkCodes: []int{200}, 102 }) 103 return 104 } 105 106 // Delete will permanently delete a particular HealthCheck based on its unique ID. 107 func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { 108 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{204}} 109 _, r.Err = c.Delete(resourceURL(c, id), reqOpt) 110 return 111 }