Naming convention and better parsing of Location
diff --git a/openstack/compute/v2/servers/results.go b/openstack/compute/v2/servers/results.go
index 26e099a..f278709 100644
--- a/openstack/compute/v2/servers/results.go
+++ b/openstack/compute/v2/servers/results.go
@@ -2,6 +2,9 @@
import (
"reflect"
+ "fmt"
+ "path"
+ "net/url"
"github.com/mitchellh/mapstructure"
"github.com/rackspace/gophercloud"
@@ -74,11 +77,28 @@
ActionResult
}
-// RescueResult represents the result of a server rescue operation
-type CreateServerImageResult struct {
+// CreateImageResult represents the result of an image creation operation
+type CreateImageResult struct {
gophercloud.Result
}
+// ExtractImageID gets the ID of the newly created server image from the header
+func (res CreateImageResult) ExtractImageID() (string, error) {
+ if res.Err != nil {
+ return "", res.Err
+ }
+ // Get the image id from the header
+ u, err := url.ParseRequestURI(res.Header.Get("Location"))
+ if err != nil {
+ return "", fmt.Errorf("Failed to parse the image id: %s", err.Error())
+ }
+ imageId := path.Base(u.Path)
+ if imageId == "." || imageId == "/" {
+ return "", fmt.Errorf("Failed to parse the ID of newly created image: %s", u)
+ }
+ return imageId, nil
+}
+
// Extract interprets any RescueResult as an AdminPass, if possible.
func (r RescueResult) Extract() (string, error) {
if r.Err != nil {