github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/elb/backendecs/requests.go (about) 1 package backendecs 2 3 import ( 4 "log" 5 6 "github.com/huaweicloud/golangsdk" 7 "github.com/huaweicloud/golangsdk/openstack/networking/v2/extensions/elb" 8 ) 9 10 // CreateOptsBuilder is the interface options structs have to satisfy in order 11 // to be used in the main Create operation in this package. Since many 12 // extensions decorate or modify the common logic, it is useful for them to 13 // satisfy a basic interface in order for them to be used. 14 type CreateOptsBuilder interface { 15 ToBackendECSCreateMap() (map[string]interface{}, error) 16 } 17 18 // CreateOpts is the common options struct used in this package's Create 19 // operation. 20 type CreateOpts struct { 21 ServerId string `json:"server_id" required:"true"` 22 Address string `json:"address" required:"true"` 23 } 24 25 // ToBackendECSCreateMap casts a CreateOpts struct to a map. 26 func (opts CreateOpts) ToBackendECSCreateMap() (map[string]interface{}, error) { 27 return golangsdk.BuildRequestBody(opts, "") 28 } 29 30 // Create is an operation which provisions a new loadbalancer based on the 31 // configuration defined in the CreateOpts struct. Once the request is 32 // validated and progress has started on the provisioning process, a 33 // CreateResult will be returned. 34 // 35 // Users with an admin role can create loadbalancers on behalf of other tenants by 36 // specifying a TenantID attribute different than their own. 37 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder, lId string) (r elb.JobResult) { 38 b, err := opts.ToBackendECSCreateMap() 39 if err != nil { 40 r.Err = err 41 return 42 } 43 44 //API takes an array of these... 45 body := []map[string]interface{}{b} 46 log.Printf("[DEBUG] create ELB-BackendECS url:%q, body=%#v", rootURL(c, lId), body) 47 48 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 49 _, r.Err = c.Post(rootURL(c, lId), body, &r.Body, reqOpt) 50 return 51 } 52 53 type GetOptsBuilder interface { 54 ToBackendECSListQuery() (string, error) 55 } 56 57 type getOpts struct { 58 ID string `q:"id"` 59 } 60 61 func (opts getOpts) ToBackendECSListQuery() (string, error) { 62 q, err := golangsdk.BuildQueryString(opts) 63 return q.String(), err 64 } 65 66 // Get retrieves a particular Loadbalancer based on its unique ID. 67 func Get(c *golangsdk.ServiceClient, lId string, backendId string) (r GetResult) { 68 url := rootURL(c, lId) 69 opts := getOpts{ID: backendId} 70 query, err := opts.ToBackendECSListQuery() 71 if err != nil { 72 r.Err = err 73 return 74 } 75 log.Printf("[DEBUG] get ELB-BackendECS opt=%#v, query=%s", opts, query) 76 url += query 77 log.Printf("[DEBUG] get ELB-BackendECS url:%q, backendId:%q", url, backendId) 78 79 _, r.Err = c.Get(url, &r.Body, nil) 80 return 81 } 82 83 // UpdateOptsBuilder is the interface options structs have to satisfy in order 84 // to be used in the main Update operation in this package. Since many 85 // extensions decorate or modify the common logic, it is useful for them to 86 // satisfy a basic interface in order for them to be used. 87 type DeleteOptsBuilder interface { 88 ToBackendECSDeleteMap() (map[string]interface{}, error) 89 } 90 91 // UpdateOpts is the common options struct used in this package's Update 92 // operation. 93 94 type RemoveMemberField struct { 95 ID string `json:"id" required:"true"` 96 } 97 98 type DeleteOpts struct { 99 RemoveMember []RemoveMemberField `json:"removeMember" required:"true"` 100 } 101 102 // ToBackendECSUpdateMap casts a UpdateOpts struct to a map. 103 func (opts DeleteOpts) ToBackendECSDeleteMap() (map[string]interface{}, error) { 104 /* 105 o, err := golangsdk.BuildRequestBody(opts, "") 106 if err != nil { 107 return nil, err 108 } 109 rm = removeMeber{RemoveMember: []map[string]string{o.([string]string)}} 110 */ 111 return golangsdk.BuildRequestBody(opts, "") 112 } 113 114 // Update is an operation which modifies the attributes of the specified BackendECS. 115 func Delete(c *golangsdk.ServiceClient, lId string, opts DeleteOpts) (r elb.JobResult) { 116 b, err := opts.ToBackendECSDeleteMap() 117 if err != nil { 118 r.Err = err 119 return 120 } 121 log.Printf("[DEBUG] deleting ELB-BackendECS, request opts=%#v", b) 122 123 _, r.Err = c.Post(actionURL(c, lId), b, &r.Body, &golangsdk.RequestOpts{ 124 OkCodes: []int{200}, 125 }) 126 return 127 }