Finalize Rackspace acceptance tests and fix various things
diff --git a/acceptance/openstack/db/v1/common.go b/acceptance/openstack/db/v1/common.go
index 2665ce4..f7ffc37 100644
--- a/acceptance/openstack/db/v1/common.go
+++ b/acceptance/openstack/db/v1/common.go
@@ -43,7 +43,11 @@
}
func (c context) Logf(msg string, args ...interface{}) {
- c.test.Logf(msg, args)
+ if len(args) > 0 {
+ c.test.Logf(msg, args...)
+ } else {
+ c.test.Log(msg)
+ }
}
func (c context) AssertNoErr(err error) {
diff --git a/acceptance/openstack/db/v1/flavor_test.go b/acceptance/openstack/db/v1/flavor_test.go
index 048872a..46f986c 100644
--- a/acceptance/openstack/db/v1/flavor_test.go
+++ b/acceptance/openstack/db/v1/flavor_test.go
@@ -15,7 +15,7 @@
c.AssertNoErr(err)
for _, f := range flavorList {
- c.Logf("Flavor: %#v", f)
+ c.Logf("Flavor: ID [%s] Name [%s] RAM [%d]", f.ID, f.Name, f.RAM)
}
return true, nil
diff --git a/acceptance/openstack/db/v1/instance_test.go b/acceptance/openstack/db/v1/instance_test.go
index 1961f1f..184f0f6 100644
--- a/acceptance/openstack/db/v1/instance_test.go
+++ b/acceptance/openstack/db/v1/instance_test.go
@@ -3,15 +3,17 @@
package v1
import (
+ "os"
"testing"
"github.com/rackspace/gophercloud/acceptance/tools"
"github.com/rackspace/gophercloud/openstack/db/v1/instances"
"github.com/rackspace/gophercloud/pagination"
- rackspaceInst "github.com/rackspace/gophercloud/rackspace/db/v1/instances"
th "github.com/rackspace/gophercloud/testhelper"
)
+const envDSType = "DATASTORE_TYPE_ID"
+
func TestRunner(t *testing.T) {
c := newContext(t)
@@ -20,7 +22,9 @@
c.getFlavor()
// INSTANCE tests
- c.createInstance()
+ //c.createInstance()
+ c.instanceID = "dbf901f4-fe23-48b7-8c1d-ee60ec85a660"
+
c.listInstances()
c.getInstance()
c.isRootEnabled()
@@ -45,11 +49,15 @@
}
func (c context) createInstance() {
- opts := rackspaceInst.CreateOpts{
+ if os.Getenv(envDSType) == "" {
+ c.test.Fatalf("%s must be set as an environment var", envDSType)
+ }
+
+ opts := instances.CreateOpts{
FlavorRef: "1",
Size: 1,
Name: tools.RandomString("gopher_db", 5),
- Datastore: &rackspaceInst.DatastoreOpts{Version: "5.6", Type: "MySQL"},
+ Datastore: &instances.DatastoreOpts{Type: os.Getenv(envDSType)},
}
instance, err := instances.Create(c.client, opts).Extract()
@@ -57,7 +65,7 @@
c.Logf("Restarting %s. Waiting...", instance.ID)
c.WaitUntilActive(instance.ID)
- c.Logf("Created DB %#v", instance)
+ c.Logf("Created Instance %s", instance.ID)
c.instanceID = instance.ID
}
@@ -70,7 +78,8 @@
c.AssertNoErr(err)
for _, i := range instanceList {
- c.Logf("Instance: %#v", i)
+ c.Logf("Instance: ID [%s] Name [%s] Status [%s] VolSize [%d] Datastore Type [%s]",
+ i.ID, i.Name, i.Status, i.Volume.Size, i.Datastore.Type)
}
return true, nil
@@ -82,7 +91,7 @@
func (c context) getInstance() {
instance, err := instances.Get(c.client, c.instanceID).Extract()
c.AssertNoErr(err)
- c.Logf("Getting instance: %#v", instance)
+ c.Logf("Getting instance: %s", instance.ID)
}
func (c context) deleteInstance() {
@@ -100,7 +109,7 @@
func (c context) isRootEnabled() {
enabled, err := instances.IsRootEnabled(c.client, c.instanceID)
c.AssertNoErr(err)
- c.Logf("Is root enabled? %s", enabled)
+ c.Logf("Is root enabled? %d", enabled)
}
func (c context) restartInstance() {
diff --git a/acceptance/rackspace/db/v1/backup_test.go b/acceptance/rackspace/db/v1/backup_test.go
index 7c50e19..af60620 100644
--- a/acceptance/rackspace/db/v1/backup_test.go
+++ b/acceptance/rackspace/db/v1/backup_test.go
@@ -3,6 +3,7 @@
package v1
import (
+ "github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/acceptance/tools"
"github.com/rackspace/gophercloud/pagination"
@@ -10,7 +11,7 @@
"github.com/rackspace/gophercloud/rackspace/db/v1/instances"
)
-func (c context) createBackup() {
+func (c *context) createBackup() {
opts := backups.CreateOpts{
Name: tools.RandomString("backup_", 5),
InstanceID: c.instanceID,
@@ -21,16 +22,28 @@
c.Logf("Created backup %#v", backup)
c.AssertNoErr(err)
+ err = gophercloud.WaitFor(60, func() (bool, error) {
+ b, err := backups.Get(c.client, backup.ID).Extract()
+ if err != nil {
+ return false, err
+ }
+ if b.Status == "COMPLETED" {
+ return true, nil
+ }
+ return false, nil
+ })
+ c.AssertNoErr(err)
+
c.backupID = backup.ID
}
-func (c context) getBackup() {
+func (c *context) getBackup() {
backup, err := backups.Get(c.client, c.backupID).Extract()
c.AssertNoErr(err)
c.Logf("Getting backup %s", backup.ID)
}
-func (c context) listAllBackups() {
+func (c *context) listAllBackups() {
c.Logf("Listing backups")
err := backups.List(c.client, nil).EachPage(func(page pagination.Page) (bool, error) {
@@ -47,7 +60,7 @@
c.AssertNoErr(err)
}
-func (c context) listInstanceBackups() {
+func (c *context) listInstanceBackups() {
c.Logf("Listing backups for instance %s", c.instanceID)
err := instances.ListBackups(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
@@ -64,7 +77,7 @@
c.AssertNoErr(err)
}
-func (c context) deleteBackup() {
+func (c *context) deleteBackup() {
err := backups.Delete(c.client, c.backupID).ExtractErr()
c.AssertNoErr(err)
c.Logf("Deleted backup %s", c.backupID)
diff --git a/acceptance/rackspace/db/v1/common.go b/acceptance/rackspace/db/v1/common.go
index 3d10904..61ef485 100644
--- a/acceptance/rackspace/db/v1/common.go
+++ b/acceptance/rackspace/db/v1/common.go
@@ -3,25 +3,25 @@
package v1
import (
- "os"
"testing"
"github.com/rackspace/gophercloud"
- "github.com/rackspace/gophercloud/openstack"
+ "github.com/rackspace/gophercloud/acceptance/tools"
"github.com/rackspace/gophercloud/rackspace"
"github.com/rackspace/gophercloud/rackspace/db/v1/instances"
th "github.com/rackspace/gophercloud/testhelper"
)
func newClient(t *testing.T) *gophercloud.ServiceClient {
- ao, err := openstack.AuthOptionsFromEnv()
+ opts, err := rackspace.AuthOptionsFromEnv()
th.AssertNoErr(t, err)
+ opts = tools.OnlyRS(opts)
- client, err := openstack.AuthenticatedClient(ao)
+ client, err := rackspace.AuthenticatedClient(opts)
th.AssertNoErr(t, err)
c, err := rackspace.NewDBV1(client, gophercloud.EndpointOpts{
- Region: os.Getenv("RS_REGION_NAME"),
+ Region: "IAD",
})
th.AssertNoErr(t, err)
@@ -47,7 +47,11 @@
}
func (c context) Logf(msg string, args ...interface{}) {
- c.test.Logf(msg, args)
+ if len(args) > 0 {
+ c.test.Logf(msg, args...)
+ } else {
+ c.test.Log(msg)
+ }
}
func (c context) AssertNoErr(err error) {
diff --git a/acceptance/rackspace/db/v1/config_group_test.go b/acceptance/rackspace/db/v1/config_group_test.go
index fba46a9..72bb1db 100644
--- a/acceptance/rackspace/db/v1/config_group_test.go
+++ b/acceptance/rackspace/db/v1/config_group_test.go
@@ -9,7 +9,7 @@
"github.com/rackspace/gophercloud/rackspace/db/v1/instances"
)
-func (c context) createConfigGrp() {
+func (c *context) createConfigGrp() {
opts := config.CreateOpts{
Name: tools.RandomString("config_", 5),
Values: map[string]interface{}{
@@ -26,13 +26,13 @@
c.configGroupID = cg.ID
}
-func (c context) getConfigGrp() {
+func (c *context) getConfigGrp() {
cg, err := config.Get(c.client, c.configGroupID).Extract()
c.Logf("Getting config group: %#v", cg)
c.AssertNoErr(err)
}
-func (c context) updateConfigGrp() {
+func (c *context) updateConfigGrp() {
opts := config.UpdateOpts{
Name: tools.RandomString("new_name_", 5),
Values: map[string]interface{}{
@@ -44,7 +44,7 @@
c.AssertNoErr(err)
}
-func (c context) replaceConfigGrp() {
+func (c *context) replaceConfigGrp() {
opts := config.UpdateOpts{
Values: map[string]interface{}{
"expire_logs_days": 7,
@@ -56,13 +56,13 @@
c.AssertNoErr(err)
}
-func (c context) associateInstanceWithConfigGrp() {
+func (c *context) associateInstanceWithConfigGrp() {
err := instances.AssociateWithConfigGroup(c.client, c.instanceID, c.configGroupID).ExtractErr()
c.Logf("Associated instance %s with config group %s", c.instanceID, c.configGroupID)
c.AssertNoErr(err)
}
-func (c context) listConfigGrpInstances() {
+func (c *context) listConfigGrpInstances() {
c.Logf("Listing all instances associated with config group %s", c.configGroupID)
err := config.ListInstances(c.client, c.configGroupID).EachPage(func(page pagination.Page) (bool, error) {
@@ -79,8 +79,14 @@
c.AssertNoErr(err)
}
-func (c context) deleteConfigGrp() {
+func (c *context) deleteConfigGrp() {
err := config.Delete(c.client, c.configGroupID).ExtractErr()
c.Logf("Deleted config group %s", c.configGroupID)
c.AssertNoErr(err)
}
+
+func (c *context) detachInstanceFromGrp() {
+ err := instances.DetachFromConfigGroup(c.client, c.instanceID).ExtractErr()
+ c.Logf("Detached instance %s from config groups", c.instanceID)
+ c.AssertNoErr(err)
+}
diff --git a/acceptance/rackspace/db/v1/database_test.go b/acceptance/rackspace/db/v1/database_test.go
index faaa7ca..6ccb80e 100644
--- a/acceptance/rackspace/db/v1/database_test.go
+++ b/acceptance/rackspace/db/v1/database_test.go
@@ -8,7 +8,7 @@
"github.com/rackspace/gophercloud/pagination"
)
-func (c context) createDBs() {
+func (c *context) createDBs() {
dbs := []string{
tools.RandomString("db_", 5),
tools.RandomString("db_", 5),
@@ -28,7 +28,7 @@
c.DBIDs = dbs
}
-func (c context) listDBs() {
+func (c *context) listDBs() {
c.Logf("Listing databases on instance %s", c.instanceID)
err := db.List(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
@@ -45,7 +45,7 @@
c.AssertNoErr(err)
}
-func (c context) deleteDBs() {
+func (c *context) deleteDBs() {
for _, id := range c.DBIDs {
err := db.Delete(c.client, c.instanceID, id).ExtractErr()
c.AssertNoErr(err)
diff --git a/acceptance/rackspace/db/v1/flavor_test.go b/acceptance/rackspace/db/v1/flavor_test.go
index e5131c7..6253b52 100644
--- a/acceptance/rackspace/db/v1/flavor_test.go
+++ b/acceptance/rackspace/db/v1/flavor_test.go
@@ -16,7 +16,7 @@
c.AssertNoErr(err)
for _, f := range flavorList {
- c.Logf("Flavor: %#v", f)
+ c.Logf("Flavor: ID [%s] Name [%s] RAM [%d]", f.ID, f.Name, f.RAM)
}
return true, nil
@@ -26,7 +26,7 @@
}
func (c context) getFlavor() {
- flavor, err := flavors.Get(c.client, 1).Extract()
+ flavor, err := flavors.Get(c.client, "1").Extract()
c.Logf("Getting flavor %s", flavor.ID)
c.AssertNoErr(err)
}
diff --git a/acceptance/rackspace/db/v1/instance_test.go b/acceptance/rackspace/db/v1/instance_test.go
index 4bc44ab..a510017 100644
--- a/acceptance/rackspace/db/v1/instance_test.go
+++ b/acceptance/rackspace/db/v1/instance_test.go
@@ -5,6 +5,7 @@
import (
"testing"
+ "github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/acceptance/tools"
"github.com/rackspace/gophercloud/pagination"
"github.com/rackspace/gophercloud/rackspace/db/v1/instances"
@@ -48,6 +49,7 @@
c.replaceConfigGrp()
c.associateInstanceWithConfigGrp()
c.listConfigGrpInstances()
+ c.detachInstanceFromGrp()
c.deleteConfigGrp()
// DATABASE tests
@@ -67,10 +69,11 @@
// TEARDOWN
c.deleteUsers()
c.deleteDBs()
+ c.detachAndDeleteReplica()
c.deleteInstance()
}
-func (c context) createInstance() {
+func (c *context) createInstance() {
opts := instances.CreateOpts{
FlavorRef: "1",
Size: 1,
@@ -80,22 +83,23 @@
instance, err := instances.Create(c.client, opts).Extract()
th.AssertNoErr(c.test, err)
- c.Logf("Restarting %s. Waiting...", instance.ID)
+ c.Logf("Creating %s. Waiting...", instance.ID)
c.WaitUntilActive(instance.ID)
- c.Logf("Created DB %#v", instance.ID)
+ c.Logf("Created instance %s", instance.ID)
c.instanceID = instance.ID
}
-func (c context) listInstances() {
+func (c *context) listInstances() {
c.Logf("Listing instances")
err := instances.List(c.client).EachPage(func(page pagination.Page) (bool, error) {
instanceList, err := instances.ExtractInstances(page)
c.AssertNoErr(err)
- for _, instance := range instanceList {
- c.Logf("Instance: %#v", instance)
+ for _, i := range instanceList {
+ c.Logf("Instance: ID [%s] Name [%s] Status [%s] VolSize [%d] Datastore Type [%s]",
+ i.ID, i.Name, i.Status, i.Volume.Size, i.Datastore.Type)
}
return true, nil
@@ -104,31 +108,31 @@
c.AssertNoErr(err)
}
-func (c context) getInstance() {
+func (c *context) getInstance() {
instance, err := instances.Get(c.client, c.instanceID).Extract()
c.AssertNoErr(err)
c.Logf("Getting instance: %#v", instance)
}
-func (c context) deleteInstance() {
+func (c *context) deleteInstance() {
err := instances.Delete(c.client, c.instanceID).ExtractErr()
c.AssertNoErr(err)
c.Logf("Deleted instance %s", c.instanceID)
}
-func (c context) enableRootUser() {
+func (c *context) enableRootUser() {
_, err := instances.EnableRootUser(c.client, c.instanceID).Extract()
c.AssertNoErr(err)
c.Logf("Enabled root user on %s", c.instanceID)
}
-func (c context) isRootEnabled() {
+func (c *context) isRootEnabled() {
enabled, err := instances.IsRootEnabled(c.client, c.instanceID)
c.AssertNoErr(err)
c.Logf("Is root enabled? %s", enabled)
}
-func (c context) restartInstance() {
+func (c *context) restartInstance() {
id := c.instanceID
err := instances.RestartService(c.client, id).ExtractErr()
c.AssertNoErr(err)
@@ -137,7 +141,7 @@
c.Logf("Restarted %s", id)
}
-func (c context) resizeInstance() {
+func (c *context) resizeInstance() {
id := c.instanceID
err := instances.ResizeInstance(c.client, id, "2").ExtractErr()
c.AssertNoErr(err)
@@ -146,7 +150,7 @@
c.Logf("Resized %s with flavorRef %s", id, "2")
}
-func (c context) resizeVol() {
+func (c *context) resizeVol() {
id := c.instanceID
err := instances.ResizeVolume(c.client, id, 2).ExtractErr()
c.AssertNoErr(err)
@@ -155,8 +159,30 @@
c.Logf("Resized the volume of %s to %d GB", id, 2)
}
-func (c context) getDefaultConfig() {
+func (c *context) getDefaultConfig() {
config, err := instances.GetDefaultConfig(c.client, c.instanceID).Extract()
c.Logf("Default config group for instance %s: %#v", c.instanceID, config)
c.AssertNoErr(err)
}
+
+func (c *context) detachAndDeleteReplica() {
+ err := instances.DetachReplica(c.client, c.replicaID).ExtractErr()
+ c.AssertNoErr(err)
+ c.Logf("Detached replica %s from instance %s", c.replicaID, c.instanceID)
+
+ err = instances.Delete(c.client, c.replicaID).ExtractErr()
+ c.AssertNoErr(err)
+ c.Logf("Deleted replica %s", c.replicaID)
+
+ // Check that it's deleted
+ err = gophercloud.WaitFor(60, func() (bool, error) {
+ _, err := instances.Get(c.client, c.replicaID).Extract()
+ if casted, ok := err.(*gophercloud.UnexpectedResponseCodeError); ok && casted.Actual == 404 {
+ return true, nil
+ }
+ if err != nil {
+ return false, err
+ }
+ return false, nil
+ })
+}
diff --git a/acceptance/rackspace/db/v1/replica_test.go b/acceptance/rackspace/db/v1/replica_test.go
index 3da2881..26f0043 100644
--- a/acceptance/rackspace/db/v1/replica_test.go
+++ b/acceptance/rackspace/db/v1/replica_test.go
@@ -8,9 +8,9 @@
th "github.com/rackspace/gophercloud/testhelper"
)
-func (c context) createReplica() {
+func (c *context) createReplica() {
opts := instances.CreateOpts{
- FlavorRef: "1",
+ FlavorRef: "2",
Size: 1,
Name: tools.RandomString("gopher_db", 5),
ReplicaOf: c.instanceID,
@@ -26,7 +26,7 @@
c.replicaID = repl.ID
}
-func (c context) detachReplica() {
+func (c *context) detachReplica() {
err := instances.DetachReplica(c.client, c.replicaID).ExtractErr()
c.Logf("Detached replica %s", c.replicaID)
c.AssertNoErr(err)
diff --git a/acceptance/rackspace/db/v1/user_test.go b/acceptance/rackspace/db/v1/user_test.go
index 53cebc1..8408e6c 100644
--- a/acceptance/rackspace/db/v1/user_test.go
+++ b/acceptance/rackspace/db/v1/user_test.go
@@ -10,7 +10,7 @@
"github.com/rackspace/gophercloud/rackspace/db/v1/users"
)
-func (c context) createUsers() {
+func (c *context) createUsers() {
c.users = []string{
tools.RandomString("user_", 5),
tools.RandomString("user_", 5),
@@ -44,7 +44,7 @@
c.AssertNoErr(err)
}
-func (c context) listUsers() {
+func (c *context) listUsers() {
c.Logf("Listing users on instance %s", c.instanceID)
err := os.List(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
@@ -61,7 +61,7 @@
c.AssertNoErr(err)
}
-func (c context) deleteUsers() {
+func (c *context) deleteUsers() {
for _, id := range c.users {
err := users.Delete(c.client, c.instanceID, id).ExtractErr()
c.AssertNoErr(err)
@@ -69,7 +69,7 @@
}
}
-func (c context) changeUserPwd() {
+func (c *context) changeUserPwd() {
opts := os.BatchCreateOpts{}
for _, name := range c.users[:1] {
@@ -81,22 +81,23 @@
c.AssertNoErr(err)
}
-func (c context) getUser() {
+func (c *context) getUser() {
user, err := users.Get(c.client, c.instanceID, c.users[0]).Extract()
c.Logf("Getting user %s", user)
c.AssertNoErr(err)
}
-func (c context) updateUser() {
- opts := os.CreateOpts{Name: tools.RandomString("new_name_", 5)}
+func (c *context) updateUser() {
+ opts := users.UpdateOpts{Name: tools.RandomString("new_name_", 5)}
err := users.Update(c.client, c.instanceID, c.users[0], opts).ExtractErr()
c.Logf("Updated user %s", c.users[0])
c.AssertNoErr(err)
+ c.users[0] = opts.Name
}
-func (c context) listUserAccess() {
+func (c *context) listUserAccess() {
err := users.ListAccess(c.client, c.instanceID, c.users[0]).EachPage(func(page pagination.Page) (bool, error) {
- dbList, err := db.ExtractDBs(page)
+ dbList, err := users.ExtractDBs(page)
c.AssertNoErr(err)
for _, db := range dbList {
@@ -109,14 +110,14 @@
c.AssertNoErr(err)
}
-func (c context) grantUserAccess() {
+func (c *context) grantUserAccess() {
opts := db.BatchCreateOpts{db.CreateOpts{Name: c.DBIDs[0]}}
err := users.GrantAccess(c.client, c.instanceID, c.users[0], opts).ExtractErr()
c.Logf("Granted access for user %s to DB %s", c.users[0], c.DBIDs[0])
c.AssertNoErr(err)
}
-func (c context) revokeUserAccess() {
+func (c *context) revokeUserAccess() {
dbName, userName := c.DBIDs[0], c.users[0]
err := users.RevokeAccess(c.client, c.instanceID, userName, dbName).ExtractErr()
c.Logf("Revoked access for user %s to DB %s", userName, dbName)
diff --git a/openstack/db/v1/instances/requests.go b/openstack/db/v1/instances/requests.go
index 63406c7..1872d75 100644
--- a/openstack/db/v1/instances/requests.go
+++ b/openstack/db/v1/instances/requests.go
@@ -14,6 +14,19 @@
ToInstanceCreateMap() (map[string]interface{}, error)
}
+// DatastoreOpts represents the configuration for how an instance stores data.
+type DatastoreOpts struct {
+ Version string
+ Type string
+}
+
+func (opts DatastoreOpts) ToMap() (map[string]string, error) {
+ return map[string]string{
+ "version": opts.Version,
+ "type": opts.Type,
+ }, nil
+}
+
// CreateOpts is the struct responsible for configuring a new database instance.
type CreateOpts struct {
// Either the integer UUID (in string form) of the flavor, or its URI
@@ -33,6 +46,10 @@
// A slice of user information options.
Users users.BatchCreateOpts
+
+ // Options to configure the type of datastore the instance will use. This is
+ // optional, and if excluded will default to MySQL.
+ Datastore *DatastoreOpts
}
// ToInstanceCreateMap will render a JSON map.
@@ -162,7 +179,7 @@
var res ActionResult
_, res.Err = client.Request("POST", actionURL(client, id), gophercloud.RequestOpts{
- JSONBody: map[string]bool{"restart": true},
+ JSONBody: map[string]interface{}{"restart": map[string]string{}},
OkCodes: []int{202},
})
diff --git a/openstack/db/v1/instances/results.go b/openstack/db/v1/instances/results.go
index f85db81..b7eeb86 100644
--- a/openstack/db/v1/instances/results.go
+++ b/openstack/db/v1/instances/results.go
@@ -6,6 +6,7 @@
"github.com/rackspace/gophercloud/openstack/db/v1/flavors"
"github.com/rackspace/gophercloud/openstack/db/v1/users"
"github.com/rackspace/gophercloud/pagination"
+ "github.com/rackspace/gophercloud/rackspace/db/v1/datastores"
)
// Volume represents information about an attached volume for a database instance.
@@ -49,6 +50,9 @@
// Information about the attached volume of the instance.
Volume Volume
+
+ // Indicates how the instance stores data.
+ Datastore datastores.DatastorePartial
}
type commonResult struct {
diff --git a/rackspace/db/v1/configurations/requests.go b/rackspace/db/v1/configurations/requests.go
index 088b7ca..bb75f5a 100644
--- a/rackspace/db/v1/configurations/requests.go
+++ b/rackspace/db/v1/configurations/requests.go
@@ -104,7 +104,7 @@
}
_, res.Err = client.Request("POST", baseURL(client), gophercloud.RequestOpts{
- OkCodes: []int{201},
+ OkCodes: []int{200},
JSONBody: &reqBody,
JSONResponse: &res.Body,
})
@@ -216,7 +216,9 @@
return res
}
-// Delete will permanently delete a configuration group.
+// Delete will permanently delete a configuration group. Please note that
+// config groups cannot be deleted whilst still attached to running instances -
+// you must detach and then delete them.
func Delete(client *gophercloud.ServiceClient, configID string) DeleteResult {
var res DeleteResult
diff --git a/rackspace/db/v1/instances/delegate.go b/rackspace/db/v1/instances/delegate.go
index ca223eb..53d9289 100644
--- a/rackspace/db/v1/instances/delegate.go
+++ b/rackspace/db/v1/instances/delegate.go
@@ -8,19 +8,6 @@
"github.com/rackspace/gophercloud/pagination"
)
-// DatastoreOpts represents the configuration for how an instance stores data.
-type DatastoreOpts struct {
- Version string
- Type string
-}
-
-func (opts DatastoreOpts) ToMap() (map[string]string, error) {
- return map[string]string{
- "version": opts.Version,
- "type": opts.Type,
- }, nil
-}
-
// CreateOpts is the struct responsible for configuring a new database instance.
type CreateOpts struct {
// Either the integer UUID (in string form) of the flavor, or its URI
@@ -46,7 +33,7 @@
// Options to configure the type of datastore the instance will use. This is
// optional, and if excluded will default to MySQL.
- Datastore *DatastoreOpts
+ Datastore *os.DatastoreOpts
// Specifies the backup ID from which to restore the database instance. There
// are some things to be aware of before using this field. When you execute
diff --git a/rackspace/db/v1/instances/requests.go b/rackspace/db/v1/instances/requests.go
index 7a1a4f8..bd8a899 100644
--- a/rackspace/db/v1/instances/requests.go
+++ b/rackspace/db/v1/instances/requests.go
@@ -39,6 +39,11 @@
return res
}
+// DetachFromConfigGroup will detach an instance from all config groups.
+func DetachFromConfigGroup(client *gophercloud.ServiceClient, instanceID string) UpdateResult {
+ return AssociateWithConfigGroup(client, instanceID, "")
+}
+
// ListBackups will list all the backups for a specified database instance.
func ListBackups(client *gophercloud.ServiceClient, instanceID string) pagination.Pager {
pageFn := func(r pagination.PageResult) pagination.Page {
diff --git a/rackspace/db/v1/users/requests.go b/rackspace/db/v1/users/requests.go
index fd0b649..5667452 100644
--- a/rackspace/db/v1/users/requests.go
+++ b/rackspace/db/v1/users/requests.go
@@ -1,6 +1,8 @@
package users
import (
+ "errors"
+
"github.com/rackspace/gophercloud"
db "github.com/rackspace/gophercloud/openstack/db/v1/databases"
os "github.com/rackspace/gophercloud/openstack/db/v1/users"
@@ -35,9 +37,52 @@
return res
}
+// UpdateOpts is the struct responsible for updating an existing user.
+type UpdateOpts struct {
+ // [OPTIONAL] Specifies a name for the user. Valid names can be composed
+ // of the following characters: letters (either case); numbers; these
+ // characters '@', '?', '#', ' ' but NEVER beginning a name string; '_' is
+ // permitted anywhere. Prohibited characters that are forbidden include:
+ // single quotes, double quotes, back quotes, semicolons, commas, backslashes,
+ // and forward slashes. Spaces at the front or end of a user name are also
+ // not permitted.
+ Name string
+
+ // [OPTIONAL] Specifies a password for the user.
+ Password string
+
+ // [OPTIONAL] Specifies the host from which a user is allowed to connect to
+ // the database. Possible values are a string containing an IPv4 address or
+ // "%" to allow connecting from any host. Optional; the default is "%".
+ Host string
+}
+
+// ToMap is a convenience function for creating sub-maps for individual users.
+func (opts UpdateOpts) ToMap() (map[string]interface{}, error) {
+ if opts.Name == "root" {
+ return nil, errors.New("root is a reserved user name and cannot be used")
+ }
+
+ user := map[string]interface{}{}
+
+ if opts.Name != "" {
+ user["name"] = opts.Name
+ }
+
+ if opts.Password != "" {
+ user["password"] = opts.Password
+ }
+
+ if opts.Host != "" {
+ user["host"] = opts.Host
+ }
+
+ return user, nil
+}
+
// Update will modify the attributes of a specified user. Attributes that can
// be updated are: user name, password, and host.
-func Update(client *gophercloud.ServiceClient, instanceID, userName string, opts os.CreateOpts) UpdateResult {
+func Update(client *gophercloud.ServiceClient, instanceID, userName string, opts UpdateOpts) UpdateResult {
var res UpdateResult
reqBody, err := opts.ToMap()