github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/elb/v3/members/requests.go (about) 1 package members 2 3 import ( 4 golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/pagination" 6 ) 7 8 // ListOptsBuilder allows extensions to add additional parameters to the 9 // List request. 10 type ListOptsBuilder interface { 11 ToMembersListQuery() (string, error) 12 } 13 14 // ListOpts allows the filtering and sorting of paginated collections 15 // through the API. Filtering is achieved by passing in struct field values 16 // that map to the Member attributes you want to see returned. SortKey allows 17 // you to sort by a particular Member attribute. SortDir sets the direction, 18 // and is either `asc' or `desc'. Marker and Limit are used for pagination. 19 type ListOpts struct { 20 Name string `q:"name"` 21 Weight int `q:"weight"` 22 AdminStateUp *bool `q:"admin_state_up"` 23 SubnetID string `q:"subnet_sidr_id"` 24 Address string `q:"address"` 25 ProtocolPort int `q:"protocol_port"` 26 ID string `q:"id"` 27 OperatingStatus string `q:"operating_status"` 28 Limit int `q:"limit"` 29 Marker string `q:"marker"` 30 SortKey string `q:"sort_key"` 31 SortDir string `q:"sort_dir"` 32 } 33 34 // ToMembersListQuery formats a ListOpts into a query string. 35 func (opts ListOpts) ToMembersListQuery() (string, error) { 36 q, err := golangsdk.BuildQueryString(opts) 37 if err != nil { 38 return "", err 39 } 40 return q.String(), err 41 } 42 43 // List returns a Pager which allows you to iterate over a collection of 44 // members. It accepts a ListOptsBuilder, which allows you to filter and 45 // sort the returned collection for greater efficiency. 46 // 47 // Default policy settings return only those members that are owned by the 48 // tenant who submits the request, unless an admin user submits the request. 49 func List(client *golangsdk.ServiceClient, poolID string, opts ListOptsBuilder) pagination.Pager { 50 url := rootURL(client, poolID) 51 if opts != nil { 52 query, err := opts.ToMembersListQuery() 53 if err != nil { 54 return pagination.Pager{Err: err} 55 } 56 url += query 57 } 58 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 59 return MemberPage{PageWithInfo: pagination.NewPageWithInfo(r)} 60 }) 61 } 62 63 // CreateOptsBuilder allows extensions to add additional parameters to the 64 // Create request. 65 type CreateOptsBuilder interface { 66 ToMemberCreateMap() (map[string]interface{}, error) 67 } 68 69 // CreateOpts is the common options' struct used in this package's CreateMember 70 // operation. 71 type CreateOpts struct { 72 // The IP address of the member to receive traffic from the load balancer. 73 Address string `json:"address" required:"true"` 74 75 // The port on which to listen for client traffic. 76 ProtocolPort int `json:"protocol_port" required:"true"` 77 78 // Name of the Member. 79 Name string `json:"name,omitempty"` 80 81 // ProjectID is the UUID of the project who owns the Member. 82 // Only administrative users can specify a project UUID other than their own. 83 ProjectID string `json:"project_id,omitempty"` 84 85 // Specifies the weight of the backend server. 86 // 87 // Requests are routed to backend servers in the same backend server group based on their weights. 88 // 89 // If the weight is 0, the backend server will not accept new requests. 90 // 91 // This parameter is invalid when lb_algorithm is set to SOURCE_IP for the backend server group that contains the backend server. 92 Weight *int `json:"weight,omitempty"` 93 94 // If you omit this parameter, LBaaS uses the vip_subnet_id parameter value 95 // for the subnet UUID. 96 SubnetID string `json:"subnet_cidr_id,omitempty"` 97 98 // The administrative state of the Pool. A valid value is true (UP) 99 // or false (DOWN). 100 AdminStateUp *bool `json:"admin_state_up,omitempty"` 101 } 102 103 // ToMemberCreateMap builds a request body from CreateOptsBuilder. 104 func (opts CreateOpts) ToMemberCreateMap() (map[string]interface{}, error) { 105 return golangsdk.BuildRequestBody(opts, "member") 106 } 107 108 // Create will create and associate a Member with a particular Pool. 109 func Create(client *golangsdk.ServiceClient, poolID string, opts CreateOptsBuilder) (r CreateResult) { 110 b, err := opts.ToMemberCreateMap() 111 if err != nil { 112 r.Err = err 113 return 114 } 115 _, r.Err = client.Post(rootURL(client, poolID), b, &r.Body, &golangsdk.RequestOpts{ 116 OkCodes: []int{201}, 117 }) 118 return 119 } 120 121 // Get retrieves a particular Pool Member based on its unique ID. 122 func Get(client *golangsdk.ServiceClient, poolID string, memberID string) (r GetResult) { 123 _, r.Err = client.Get(resourceURL(client, poolID, memberID), &r.Body, nil) 124 return 125 } 126 127 // UpdateOptsBuilder allows extensions to add additional parameters to the 128 // List request. 129 type UpdateOptsBuilder interface { 130 ToMemberUpdateMap() (map[string]interface{}, error) 131 } 132 133 // UpdateOpts is the common options' struct used in this package's Update 134 // operation. 135 type UpdateOpts struct { 136 // Name of the Member. 137 Name *string `json:"name,omitempty"` 138 139 // A positive integer value that indicates the relative portion of traffic 140 // that this member should receive from the pool. For example, a member with 141 // a weight of 10 receives five times as much traffic as a member with a 142 // weight of 2. 143 Weight *int `json:"weight,omitempty"` 144 145 // The administrative state of the Pool. A valid value is true (UP) 146 // or false (DOWN). 147 AdminStateUp *bool `json:"admin_state_up,omitempty"` 148 } 149 150 // ToMemberUpdateMap builds a request body from UpdateOptsBuilder. 151 func (opts UpdateOpts) ToMemberUpdateMap() (map[string]interface{}, error) { 152 return golangsdk.BuildRequestBody(opts, "member") 153 } 154 155 // Update allows Member to be updated. 156 func Update(client *golangsdk.ServiceClient, poolID string, memberID string, opts UpdateOptsBuilder) (r UpdateResult) { 157 b, err := opts.ToMemberUpdateMap() 158 if err != nil { 159 r.Err = err 160 return 161 } 162 _, r.Err = client.Put(resourceURL(client, poolID, memberID), b, &r.Body, &golangsdk.RequestOpts{ 163 OkCodes: []int{200, 201, 202}, 164 }) 165 return 166 } 167 168 // Delete will remove and disassociate a Member from a particular 169 // Pool. 170 func Delete(client *golangsdk.ServiceClient, poolID string, memberID string) (r DeleteResult) { 171 _, r.Err = client.Delete(resourceURL(client, poolID, memberID), nil) 172 return 173 }