github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/lbaas/members/requests.go (about) 1 package members 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/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 *gophercloud.ServiceClient, opts ListOpts) pagination.Pager { 35 q, err := gophercloud.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 gophercloud.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 *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 75 b, err := opts.ToLBMemberCreateMap() 76 if err != nil { 77 r.Err = err 78 return 79 } 80 resp, err := c.Post(rootURL(c), b, &r.Body, nil) 81 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 82 return 83 } 84 85 // Get retrieves a particular pool member based on its unique ID. 86 func Get(c *gophercloud.ServiceClient, id string) (r GetResult) { 87 resp, err := c.Get(resourceURL(c, id), &r.Body, nil) 88 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 89 return 90 } 91 92 // UpdateOptsBuilder allows extensions to add additional parameters to the 93 // Update request. 94 type UpdateOptsBuilder interface { 95 ToLBMemberUpdateMap() (map[string]interface{}, error) 96 } 97 98 // UpdateOpts contains the values used when updating a pool member. 99 type UpdateOpts struct { 100 // The administrative state of the member, which is up (true) or down (false). 101 AdminStateUp *bool `json:"admin_state_up,omitempty"` 102 } 103 104 // ToLBMemberUpdateMap builds a request body from UpdateOpts. 105 func (opts UpdateOpts) ToLBMemberUpdateMap() (map[string]interface{}, error) { 106 return gophercloud.BuildRequestBody(opts, "member") 107 } 108 109 // Update allows members to be updated. 110 func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { 111 b, err := opts.ToLBMemberUpdateMap() 112 if err != nil { 113 r.Err = err 114 return 115 } 116 resp, err := c.Put(resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{ 117 OkCodes: []int{200, 201, 202}, 118 }) 119 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 120 return 121 } 122 123 // Delete will permanently delete a particular member based on its unique ID. 124 func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) { 125 resp, err := c.Delete(resourceURL(c, id), nil) 126 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 127 return 128 }