Finalize Rackspace acceptance tests and fix various things
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()