github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/lbaas/members/requests.go (about) 1 package members 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 // ListOpts allows the filtering and sorting of paginated collections through 9 // the API. Filtering is achieved by passing in struct field values that map to 10 // the floating IP attributes you want to see returned. SortKey allows you to 11 // sort by a particular network attribute. SortDir sets the direction, and is 12 // either `asc' or `desc'. Marker and Limit are used for pagination. 13 type ListOpts struct { 14 Status string `q:"status"` 15 Weight int `q:"weight"` 16 AdminStateUp *bool `q:"admin_state_up"` 17 TenantID string `q:"tenant_id"` 18 PoolID string `q:"pool_id"` 19 Address string `q:"address"` 20 ProtocolPort int `q:"protocol_port"` 21 ID string `q:"id"` 22 Limit int `q:"limit"` 23 Marker string `q:"marker"` 24 SortKey string `q:"sort_key"` 25 SortDir string `q:"sort_dir"` 26 } 27 28 // List returns a Pager which allows you to iterate over a collection of 29 // members. It accepts a ListOpts struct, which allows you to filter and sort 30 // the returned collection for greater efficiency. 31 // 32 // Default policy settings return only those members that are owned by the 33 // tenant who submits the request, unless an admin user submits the request. 34 func List(c *golangsdk.ServiceClient, opts ListOpts) pagination.Pager { 35 q, err := golangsdk.BuildQueryString(&opts) 36 if err != nil { 37 return pagination.Pager{Err: err} 38 } 39 u := rootURL(c) + q.String() 40 return pagination.NewPager(c, u, func(r pagination.PageResult) pagination.Page { 41 return MemberPage{pagination.LinkedPageBase{PageResult: r}} 42 }) 43 } 44 45 // CreateOptsBuilder allows extensions to add additional parameters to the 46 // Create request. 47 type CreateOptsBuilder interface { 48 ToLBMemberCreateMap() (map[string]interface{}, error) 49 } 50 51 // CreateOpts contains all the values needed to create a new pool member. 52 type CreateOpts struct { 53 // Address is the IP address of the member. 54 Address string `json:"address" required:"true"` 55 56 // ProtocolPort is the port on which the application is hosted. 57 ProtocolPort int `json:"protocol_port" required:"true"` 58 59 // PoolID is the pool to which this member will belong. 60 PoolID string `json:"pool_id" required:"true"` 61 62 // TenantID is only required if the caller has an admin role and wants 63 // to create a pool for another tenant. 64 TenantID string `json:"tenant_id,omitempty"` 65 } 66 67 // ToLBMemberCreateMap builds a request body from CreateOpts. 68 func (opts CreateOpts) ToLBMemberCreateMap() (map[string]interface{}, error) { 69 return golangsdk.BuildRequestBody(opts, "member") 70 } 71 72 // Create accepts a CreateOpts struct and uses the values to create a new 73 // load balancer pool member. 74 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 75 b, err := opts.ToLBMemberCreateMap() 76 if err != nil { 77 r.Err = err 78 return 79 } 80 _, r.Err = c.Post(rootURL(c), b, &r.Body, nil) 81 return 82 } 83 84 // Get retrieves a particular pool member based on its unique ID. 85 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 86 _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) 87 return 88 } 89 90 // UpdateOptsBuilder allows extensions to add additional parameters to the 91 // Update request. 92 type UpdateOptsBuilder interface { 93 ToLBMemberUpdateMap() (map[string]interface{}, error) 94 } 95 96 // UpdateOpts contains the values used when updating a pool member. 97 type UpdateOpts struct { 98 // The administrative state of the member, which is up (true) or down (false). 99 AdminStateUp *bool `json:"admin_state_up,omitempty"` 100 } 101 102 // ToLBMemberUpdateMap builds a request body from UpdateOpts. 103 func (opts UpdateOpts) ToLBMemberUpdateMap() (map[string]interface{}, error) { 104 return golangsdk.BuildRequestBody(opts, "member") 105 } 106 107 // Update allows members to be updated. 108 func Update(c *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { 109 b, err := opts.ToLBMemberUpdateMap() 110 if err != nil { 111 r.Err = err 112 return 113 } 114 _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &golangsdk.RequestOpts{ 115 OkCodes: []int{200, 201, 202}, 116 }) 117 return 118 } 119 120 // Delete will permanently delete a particular member based on its unique ID. 121 func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { 122 _, r.Err = c.Delete(resourceURL(c, id), nil) 123 return 124 }