Adding update pools operation
diff --git a/openstack/networking/v2/extensions/lbaas/pools/requests.go b/openstack/networking/v2/extensions/lbaas/pools/requests.go
index f9ac914..1bbd9fd 100644
--- a/openstack/networking/v2/extensions/lbaas/pools/requests.go
+++ b/openstack/networking/v2/extensions/lbaas/pools/requests.go
@@ -161,3 +161,41 @@
res.Err = err
return res
}
+
+// UpdateOpts contains the values used when updating a pool.
+type UpdateOpts struct {
+ // Required. Name of the pool.
+ Name string
+
+ // The algorithm used to distribute load between the members of the pool. The
+ // current specification supports LBMethodRoundRobin and
+ // LBMethodLeastConnections as valid values for this attribute.
+ LBMethod string
+}
+
+// Update allows pools to be updated.
+func Update(c *gophercloud.ServiceClient, id string, opts UpdateOpts) UpdateResult {
+ type pool struct {
+ Name string `json:"name,"`
+ LBMethod string `json:"lb_method"`
+ }
+ type request struct {
+ Pool pool `json:"pool"`
+ }
+
+ reqBody := request{Pool: pool{
+ Name: opts.Name,
+ LBMethod: opts.LBMethod,
+ }}
+
+ // Send request to API
+ var res UpdateResult
+ _, err := perigee.Request("PUT", resourceURL(c, id), perigee.Options{
+ MoreHeaders: c.Provider.AuthenticatedHeaders(),
+ ReqBody: &reqBody,
+ Results: &res.Resp,
+ OkCodes: []int{200},
+ })
+ res.Err = err
+ return res
+}
diff --git a/openstack/networking/v2/extensions/lbaas/pools/requests_test.go b/openstack/networking/v2/extensions/lbaas/pools/requests_test.go
index 0fcf0bc..eb9d68e 100644
--- a/openstack/networking/v2/extensions/lbaas/pools/requests_test.go
+++ b/openstack/networking/v2/extensions/lbaas/pools/requests_test.go
@@ -216,3 +216,57 @@
th.AssertEquals(t, n.ID, "332abe93-f488-41ba-870b-2ac66be7f853")
}
+
+func TestUpdate(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ th.Mux.HandleFunc("/v2.0/lb/pools/332abe93-f488-41ba-870b-2ac66be7f853", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", tokenID)
+ th.TestHeader(t, r, "Content-Type", "application/json")
+ th.TestHeader(t, r, "Accept", "application/json")
+ th.TestJSONRequest(t, r, `
+{
+ "pool":{
+ "name":"SuperPool",
+ "lb_method": "LEAST_CONNECTIONS"
+ }
+}
+ `)
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+
+ fmt.Fprintf(w, `
+{
+ "pool":{
+ "status":"PENDING_UPDATE",
+ "lb_method":"LEAST_CONNECTIONS",
+ "protocol":"TCP",
+ "description":"",
+ "health_monitors":[
+
+ ],
+ "subnet_id":"8032909d-47a1-4715-90af-5153ffe39861",
+ "tenant_id":"83657cfcdfe44cd5920adaf26c48ceea",
+ "admin_state_up":true,
+ "name":"SuperPool",
+ "members":[
+
+ ],
+ "id":"61b1f87a-7a21-4ad3-9dda-7f81d249944f",
+ "vip_id":null
+ }
+}
+ `)
+ })
+
+ options := UpdateOpts{Name: "SuperPool", LBMethod: LBMethodLeastConnections}
+
+ n, err := Update(serviceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", options).Extract()
+ th.AssertNoErr(t, err)
+
+ th.AssertEquals(t, "SuperPool", n.Name)
+ th.AssertDeepEquals(t, "LEAST_CONNECTIONS", n.LBMethod)
+}