db v1 error types
diff --git a/openstack/db/v1/configurations/requests.go b/openstack/db/v1/configurations/requests.go
index 035ff29..abb0013 100644
--- a/openstack/db/v1/configurations/requests.go
+++ b/openstack/db/v1/configurations/requests.go
@@ -1,8 +1,6 @@
package configurations
import (
- "errors"
-
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/db/v1/instances"
"github.com/gophercloud/gophercloud/pagination"
@@ -67,10 +65,16 @@
// ToConfigCreateMap casts a CreateOpts struct into a JSON map.
func (opts CreateOpts) ToConfigCreateMap() (map[string]interface{}, error) {
if opts.Name == "" {
- return nil, errors.New("Name is a required field")
+ err := gophercloud.ErrMissingInput{}
+ err.Function = "configurations.ToConfigCreateMap"
+ err.Argument = "configurations.CreateOpts.Name"
+ return nil, err
}
if len(opts.Values) == 0 {
- return nil, errors.New("Values must be a populated map")
+ err := gophercloud.ErrMissingInput{}
+ err.Function = "configurations.ToConfigCreateMap"
+ err.Argument = "configurations.CreateOpts.Values"
+ return nil, err
}
config := map[string]interface{}{
diff --git a/openstack/db/v1/databases/requests.go b/openstack/db/v1/databases/requests.go
index ff57245..18e1af5 100644
--- a/openstack/db/v1/databases/requests.go
+++ b/openstack/db/v1/databases/requests.go
@@ -1,8 +1,6 @@
package databases
import (
- "fmt"
-
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
@@ -12,7 +10,7 @@
ToDBCreateMap() (map[string]interface{}, error)
}
-// DatabaseOpts is the struct responsible for configuring a database; often in
+// CreateOpts is the struct responsible for configuring a database; often in
// the context of an instance.
type CreateOpts struct {
// [REQUIRED] Specifies the name of the database. Valid names can be composed
@@ -39,10 +37,17 @@
// into sub-maps.
func (opts CreateOpts) ToMap() (map[string]string, error) {
if opts.Name == "" {
- return nil, fmt.Errorf("Name is a required field")
+ err := gophercloud.ErrMissingInput{}
+ err.Function = "databases.ToMap"
+ err.Argument = "databases.CreateOpts.Name"
}
if len(opts.Name) > 64 {
- return nil, fmt.Errorf("Name must be less than 64 chars long")
+ err := gophercloud.ErrInvalidInput{}
+ err.Function = "databases.ToMap"
+ err.Argument = "databases.CreateOpts.Name"
+ err.Value = opts.Name
+ err.Info = "Must be less than 64 chars long"
+ return nil, err
}
db := map[string]string{"name": opts.Name}
diff --git a/openstack/db/v1/instances/requests.go b/openstack/db/v1/instances/requests.go
index 7714a21..8e33dfe 100644
--- a/openstack/db/v1/instances/requests.go
+++ b/openstack/db/v1/instances/requests.go
@@ -1,8 +1,6 @@
package instances
import (
- "fmt"
-
"github.com/gophercloud/gophercloud"
db "github.com/gophercloud/gophercloud/openstack/db/v1/databases"
"github.com/gophercloud/gophercloud/openstack/db/v1/users"
@@ -20,6 +18,7 @@
Type string
}
+// ToMap converts a DatastoreOpts to a map[string]string (for a request body)
func (opts DatastoreOpts) ToMap() (map[string]string, error) {
return map[string]string{
"version": opts.Version,
@@ -55,10 +54,18 @@
// ToInstanceCreateMap will render a JSON map.
func (opts CreateOpts) ToInstanceCreateMap() (map[string]interface{}, error) {
if opts.Size > 300 || opts.Size < 1 {
- return nil, fmt.Errorf("Size (GB) must be between 1-300")
+ err := gophercloud.ErrInvalidInput{}
+ err.Function = "instances.ToInstanceCreateMap"
+ err.Argument = "instances.CreateOpts.Size"
+ err.Value = opts.Size
+ err.Info = "Size (GB) must be between 1-300"
+ return nil, err
}
if opts.FlavorRef == "" {
- return nil, fmt.Errorf("FlavorRef is a required field")
+ err := gophercloud.ErrMissingInput{}
+ err.Function = "instances.ToInstanceCreateMap"
+ err.Argument = "instances.CreateOpts.FlavorRef"
+ return nil, err
}
instance := map[string]interface{}{
@@ -83,6 +90,13 @@
}
instance["users"] = users["users"]
}
+ if opts.Datastore != nil {
+ datastore, err := opts.Datastore.ToMap()
+ if err != nil {
+ return nil, err
+ }
+ instance["datastore"] = datastore
+ }
return map[string]interface{}{"instance": instance}, nil
}
diff --git a/openstack/db/v1/users/requests.go b/openstack/db/v1/users/requests.go
index 8f86297..6815c1c 100644
--- a/openstack/db/v1/users/requests.go
+++ b/openstack/db/v1/users/requests.go
@@ -1,8 +1,6 @@
package users
import (
- "errors"
-
"github.com/gophercloud/gophercloud"
db "github.com/gophercloud/gophercloud/openstack/db/v1/databases"
"github.com/gophercloud/gophercloud/pagination"
@@ -42,13 +40,24 @@
func (opts CreateOpts) ToMap() (map[string]interface{}, error) {
if opts.Name == "root" {
- return nil, errors.New("root is a reserved user name and cannot be used")
+ err := gophercloud.ErrInvalidInput{}
+ err.Function = "users.ToUserCreateMap"
+ err.Argument = "users.CreateOpts.Name"
+ err.Value = "root"
+ err.Info = "root is a reserved user name and cannot be used"
+ return nil, err
}
if opts.Name == "" {
- return nil, errors.New("Name is a required field")
+ err := gophercloud.ErrMissingInput{}
+ err.Function = "users.ToUserCreateMap"
+ err.Argument = "users.CreateOpts.Name"
+ return nil, err
}
if opts.Password == "" {
- return nil, errors.New("Password is a required field")
+ err := gophercloud.ErrMissingInput{}
+ err.Function = "users.ToUserCreateMap"
+ err.Argument = "users.CreateOpts.Password"
+ return nil, err
}
user := map[string]interface{}{