Update instance/associate with config group
diff --git a/rackspace/db/v1/instances/fixtures.go b/rackspace/db/v1/instances/fixtures.go
index cbd18da..bbf578b 100644
--- a/rackspace/db/v1/instances/fixtures.go
+++ b/rackspace/db/v1/instances/fixtures.go
@@ -164,3 +164,16 @@
`)
})
}
+
+func HandleAssociateGroupSuccessfully(t *testing.T, id string) {
+ th.Mux.HandleFunc("/instances/"+id, func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "PUT")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+ th.TestJSONRequest(t, r, `{"instance": {"configuration": "{configGroupID}"}}`)
+
+ w.WriteHeader(http.StatusAccepted)
+ w.Header().Add("Content-Type", "application/json")
+
+ fmt.Fprintf(w, singleInstanceJson)
+ })
+}
diff --git a/rackspace/db/v1/instances/requests.go b/rackspace/db/v1/instances/requests.go
index a0ffcad..60775dd 100644
--- a/rackspace/db/v1/instances/requests.go
+++ b/rackspace/db/v1/instances/requests.go
@@ -19,3 +19,22 @@
return res
}
+
+func AssociateWithConfigGroup(client *gophercloud.ServiceClient, instanceID, configGroupID string) UpdateResult {
+ reqBody := map[string]string{
+ "configuration": configGroupID,
+ }
+
+ var res UpdateResult
+
+ resp, err := perigee.Request("PUT", resourceURL(client, instanceID), perigee.Options{
+ MoreHeaders: client.AuthenticatedHeaders(),
+ ReqBody: map[string]map[string]string{"instance": reqBody},
+ OkCodes: []int{202},
+ })
+
+ res.Header = resp.HttpResponse.Header
+ res.Err = err
+
+ return res
+}
diff --git a/rackspace/db/v1/instances/requests_test.go b/rackspace/db/v1/instances/requests_test.go
index e653c07..c746b6a 100644
--- a/rackspace/db/v1/instances/requests_test.go
+++ b/rackspace/db/v1/instances/requests_test.go
@@ -11,9 +11,9 @@
th.SetupHTTP()
defer th.TeardownHTTP()
- HandleGetConfigSuccessfully(t)
+ HandleGetConfigSuccessfully(t, instanceID)
- config, err := GetConfig(fake.ServiceClient(), opts).Extract()
+ config, err := GetDefaultConfig(fake.ServiceClient(), instanceID).Extract()
expected := map[string]string{
"basedir": "/usr",
@@ -63,3 +63,14 @@
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, expected, config)
}
+
+func TestAssociateWithConfigGroup(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ HandleAssociateGroupSuccessfully(t, instanceID)
+
+ configGroupID := "{configGroupID}"
+ res := AssociateWithConfigGroup(fake.ServiceClient(), instanceID, configGroupID)
+ th.AssertNoErr(t, res.Err)
+}
diff --git a/rackspace/db/v1/instances/results.go b/rackspace/db/v1/instances/results.go
index 2b7f4fd..c2c68e1 100644
--- a/rackspace/db/v1/instances/results.go
+++ b/rackspace/db/v1/instances/results.go
@@ -59,8 +59,8 @@
}
func (r ConfigResult) Extract() (map[string]string, error) {
- if err != nil {
- return nil, err
+ if r.Err != nil {
+ return nil, r.Err
}
var response struct {
@@ -69,6 +69,10 @@
} `mapstructure:"instance"`
}
- err = mapstructure.Decode(body, &response)
- return &response.Instance, err
+ err := mapstructure.Decode(r.Body, &response)
+ return response.Instance.Config, err
+}
+
+type UpdateResult struct {
+ gophercloud.ErrResult
}
diff --git a/rackspace/db/v1/instances/urls.go b/rackspace/db/v1/instances/urls.go
index c0c1bad..12f8d83 100644
--- a/rackspace/db/v1/instances/urls.go
+++ b/rackspace/db/v1/instances/urls.go
@@ -10,6 +10,10 @@
return baseURL(c)
}
-func configURL(c *gophercloud.ServiceClient) string {
+func resourceURL(c *gophercloud.ServiceClient, id string) string {
+ return c.ServiceURL("instances", id)
+}
+
+func configURL(c *gophercloud.ServiceClient, id string) string {
return c.ServiceURL("instances", id, "configuration")
}