github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/elbaas/backendmember/requests.go (about) 1 package backendmember 2 3 import ( 4 //"fmt" 5 "github.com/huaweicloud/golangsdk" 6 //"github.com/huaweicloud/golangsdk/pagination" 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 AddOptsBuilder interface { 14 ToBackendAddMap() (map[string]interface{}, error) 15 } 16 17 // CreateOpts is the common options struct used in this package's Create 18 // operation. 19 type AddOpts struct { 20 // server_id 21 ServerId string `json:"server_id" required:"true"` 22 // The load balancer on which to provision this listener. 23 Address string `json:"address" required:"true"` 24 } 25 26 // ToBackendAddMap casts a CreateOpts struct to a map. 27 func (opts AddOpts) ToBackendAddMap() (map[string]interface{}, error) { 28 return golangsdk.BuildRequestBody(opts, "") 29 } 30 31 // Add is an operation which provisions a new Listeners based on the 32 // configuration defined in the AddOpts struct. Once the request is 33 // validated and progress has started on the provisioning process, a 34 // AddResult will be returned. 35 // 36 // Users with an admin role can create Listeners on behalf of other tenants by 37 // specifying a TenantID attribute different than their own. 38 func Add(c *golangsdk.ServiceClient, listener_id string, opts AddOptsBuilder) (r AddResult) { 39 b, err := opts.ToBackendAddMap() 40 // API takes an array of these... 41 a := make([]map[string]interface{}, 1) 42 a[0] = b 43 if err != nil { 44 r.Err = err 45 return 46 } 47 _, r.Err = c.Post(addURL(c, listener_id), a, &r.Body, &golangsdk.RequestOpts{ 48 OkCodes: []int{200}, 49 }) 50 return 51 } 52 53 // RemoveOptsBuilder is the interface options structs have to satisfy in order 54 // to be used in the main Remove operation in this package. Since many 55 // extensions decorate or modify the common logic, it is useful for them to 56 // satisfy a basic interface in order for them to be used. 57 type RemoveOptsBuilder interface { 58 ToBackendRemoveMap() (map[string]interface{}, error) 59 } 60 61 type LoadBalancerID struct { 62 // backend member id to remove 63 ID string `json:"id" required:"true"` 64 } 65 66 // RemoveOpts is the common options struct used in this package's Remove 67 // operation. 68 type RemoveOpts struct { 69 RemoveMember []LoadBalancerID `json:"removeMember" required:"true"` 70 } 71 72 // ToBackendCreateMap casts a CreateOpts struct to a map. 73 func (opts RemoveOpts) ToBackendRemoveMap() (map[string]interface{}, error) { 74 return golangsdk.BuildRequestBody(opts, "") 75 } 76 77 // Remove will permanently remove a particular backend based on its unique ID. 78 func Remove(c *golangsdk.ServiceClient, listener_id string, id string) (r RemoveResult) { 79 /*lbid := LoadBalancerID{ 80 ID: id, 81 } 82 lbids := []LoadBalancerID{lbid} 83 removeOpts := RemoveOpts{ 84 removeMember: lbids, 85 } 86 fmt.Printf("removeOpts=%+v.\n", removeOpts) 87 b, err := removeOpts.ToBackendRemoveMap() */ 88 lbid := make(map[string]interface{}) 89 lbid["id"] = id 90 lbids := make([]map[string]interface{}, 1) 91 lbids[0] = lbid 92 b := make(map[string]interface{}) 93 b["removeMember"] = lbids 94 //fmt.Printf("b=%+v.\n", b) 95 /* if err != nil { 96 r.Err = err 97 return 98 } */ 99 _, r.Err = c.Post(removeURL(c, listener_id), b, &r.Body, &golangsdk.RequestOpts{ 100 OkCodes: []int{200}, 101 }) 102 return 103 } 104 105 // Get retrieves a particular Health Monitor based on its unique ID. 106 func Get(c *golangsdk.ServiceClient, listener_id, id string) (r GetResult) { 107 _, r.Err = c.Get(resourceURL(c, listener_id, id), &r.Body, nil) 108 return 109 }