Enable root user
diff --git a/openstack/db/v1/instances/fixtures.go b/openstack/db/v1/instances/fixtures.go
index 16b4006..9cbcb3a 100644
--- a/openstack/db/v1/instances/fixtures.go
+++ b/openstack/db/v1/instances/fixtures.go
@@ -154,3 +154,13 @@
w.WriteHeader(http.StatusAccepted)
})
}
+
+func HandleEnableRootUserSuccessfully(t *testing.T, id string) {
+ th.Mux.HandleFunc("/instances/"+id+"/root", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "POST")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+
+ w.WriteHeader(http.StatusOK)
+ fmt.Fprintf(w, `{"user":{"name":"root","password":"secretsecret"}}`)
+ })
+}
diff --git a/openstack/db/v1/instances/requests.go b/openstack/db/v1/instances/requests.go
index 6fe423b..b54b9fa 100644
--- a/openstack/db/v1/instances/requests.go
+++ b/openstack/db/v1/instances/requests.go
@@ -226,3 +226,18 @@
return res
}
+
+func EnableRootUser(client *gophercloud.ServiceClient, id string) UserRootResult {
+ var res UserRootResult
+
+ resp, err := perigee.Request("POST", userRootURL(client, id), perigee.Options{
+ MoreHeaders: client.AuthenticatedHeaders(),
+ Results: &res.Body,
+ OkCodes: []int{200},
+ })
+
+ res.Header = resp.HttpResponse.Header
+ res.Err = err
+
+ return res
+}
diff --git a/openstack/db/v1/instances/requests_test.go b/openstack/db/v1/instances/requests_test.go
index 5e5dcaa..0845e0c 100644
--- a/openstack/db/v1/instances/requests_test.go
+++ b/openstack/db/v1/instances/requests_test.go
@@ -130,3 +130,16 @@
res := Delete(fake.ServiceClient(), instanceID)
th.AssertNoErr(t, res.Err)
}
+
+func TestEnableRootUser(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ HandleEnableRootUserSuccessfully(t, instanceID)
+
+ expected := &User{Name: "root", Password: "secretsecret"}
+
+ user, err := EnableRootUser(fake.ServiceClient(), instanceID).Extract()
+ th.AssertNoErr(t, err)
+ th.AssertDeepEquals(t, expected, user)
+}
diff --git a/openstack/db/v1/instances/results.go b/openstack/db/v1/instances/results.go
index d2ea794..60f0c04 100644
--- a/openstack/db/v1/instances/results.go
+++ b/openstack/db/v1/instances/results.go
@@ -27,6 +27,11 @@
Volume Volume
}
+type User struct {
+ Name string
+ Password string
+}
+
type commonResult struct {
gophercloud.Result
}
@@ -95,3 +100,21 @@
return response.Instances, err
}
+
+type UserRootResult struct {
+ gophercloud.Result
+}
+
+func (r UserRootResult) Extract() (*User, error) {
+ if r.Err != nil {
+ return nil, r.Err
+ }
+
+ var response struct {
+ User User `mapstructure:"user"`
+ }
+
+ err := mapstructure.Decode(r.Body, &response)
+
+ return &response.User, err
+}
diff --git a/openstack/db/v1/instances/urls.go b/openstack/db/v1/instances/urls.go
index d30e762..a50da96 100644
--- a/openstack/db/v1/instances/urls.go
+++ b/openstack/db/v1/instances/urls.go
@@ -9,3 +9,7 @@
func resourceURL(c *gophercloud.ServiceClient, id string) string {
return c.ServiceURL("instances", id)
}
+
+func userRootURL(c *gophercloud.ServiceClient, id string) string {
+ return c.ServiceURL("instances", id, "root")
+}