additionally return 'error' from 'ToCreateServerMap'
diff --git a/openstack/compute/v2/servers/requests.go b/openstack/compute/v2/servers/requests.go
index c6eca11..544f816 100644
--- a/openstack/compute/v2/servers/requests.go
+++ b/openstack/compute/v2/servers/requests.go
@@ -79,7 +79,7 @@
// CreateOptsBuilder describes struct types that can be accepted by the Create call.
// The CreateOpts struct in this package does.
type CreateOptsBuilder interface {
- ToServerCreateMap() map[string]interface{}
+ ToServerCreateMap() (map[string]interface{}, error)
}
// Network is used within CreateOpts to control a new server's network attachments.
@@ -134,7 +134,7 @@
}
// ToServerCreateMap assembles a request body based on the contents of a CreateOpts.
-func (opts CreateOpts) ToServerCreateMap() map[string]interface{} {
+func (opts CreateOpts) ToServerCreateMap() (map[string]interface{}, error) {
server := make(map[string]interface{})
server["name"] = opts.Name
@@ -183,19 +183,26 @@
server["networks"] = networks
}
- return map[string]interface{}{"server": server}
+ return map[string]interface{}{"server": server}, nil
}
// Create requests a server to be provisioned to the user in the current tenant.
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) CreateResult {
- var result CreateResult
- _, result.Err = perigee.Request("POST", listURL(client), perigee.Options{
- Results: &result.Body,
- ReqBody: opts.ToServerCreateMap(),
+ var res CreateResult
+
+ reqBody, err := opts.ToServerCreateMap()
+ if err != nil {
+ res.Err = err
+ return res
+ }
+
+ _, res.Err = perigee.Request("POST", listURL(client), perigee.Options{
+ Results: &res.Body,
+ ReqBody: reqBody,
MoreHeaders: client.AuthenticatedHeaders(),
OkCodes: []int{202},
})
- return result
+ return res
}
// Delete requests that a server previously provisioned be removed from your account.