Merge pull request #488 from trumant/allowed_address_pairs

Allowed address pairs support for Neutron Port
diff --git a/openstack/db/v1/configurations/results.go b/openstack/db/v1/configurations/results.go
index 37a77ad..d0d1d6e 100644
--- a/openstack/db/v1/configurations/results.go
+++ b/openstack/db/v1/configurations/results.go
@@ -1,6 +1,8 @@
 package configurations
 
 import (
+	"fmt"
+	"reflect"
 	"time"
 
 	"github.com/mitchellh/mapstructure"
@@ -43,12 +45,18 @@
 		Configs []Config `mapstructure:"configurations" json:"configurations"`
 	}
 
-	err := mapstructure.Decode(casted, &resp)
+	if err := mapstructure.Decode(casted, &resp); err != nil {
+		return nil, err
+	}
 
 	var vals []interface{}
-	switch (casted).(type) {
-	case interface{}:
+	switch casted.(type) {
+	case map[string]interface{}:
 		vals = casted.(map[string]interface{})["configurations"].([]interface{})
+	case map[string][]interface{}:
+		vals = casted.(map[string][]interface{})["configurations"]
+	default:
+		return resp.Configs, fmt.Errorf("Unknown type: %v", reflect.TypeOf(casted))
 	}
 
 	for i, v := range vals {
@@ -71,7 +79,7 @@
 		}
 	}
 
-	return resp.Configs, err
+	return resp.Configs, nil
 }
 
 type commonResult struct {
diff --git a/openstack/db/v1/instances/results.go b/openstack/db/v1/instances/results.go
index 9a49510..95aed16 100644
--- a/openstack/db/v1/instances/results.go
+++ b/openstack/db/v1/instances/results.go
@@ -1,6 +1,8 @@
 package instances
 
 import (
+	"fmt"
+	"reflect"
 	"time"
 
 	"github.com/mitchellh/mapstructure"
@@ -142,16 +144,22 @@
 func ExtractInstances(page pagination.Page) ([]Instance, error) {
 	casted := page.(InstancePage).Body
 
-	var response struct {
+	var resp struct {
 		Instances []Instance `mapstructure:"instances"`
 	}
 
-	err := mapstructure.Decode(casted, &response)
+	if err := mapstructure.Decode(casted, &resp); err != nil {
+		return nil, err
+	}
 
 	var vals []interface{}
-	switch (casted).(type) {
-	case interface{}:
+	switch casted.(type) {
+	case map[string]interface{}:
 		vals = casted.(map[string]interface{})["instances"].([]interface{})
+	case map[string][]interface{}:
+		vals = casted.(map[string][]interface{})["instances"]
+	default:
+		return resp.Instances, fmt.Errorf("Unknown type: %v", reflect.TypeOf(casted))
 	}
 
 	for i, v := range vals {
@@ -160,21 +168,21 @@
 		if t, ok := val["created"].(string); ok && t != "" {
 			creationTime, err := time.Parse(time.RFC3339, t)
 			if err != nil {
-				return response.Instances, err
+				return resp.Instances, err
 			}
-			response.Instances[i].Created = creationTime
+			resp.Instances[i].Created = creationTime
 		}
 
 		if t, ok := val["updated"].(string); ok && t != "" {
 			updatedTime, err := time.Parse(time.RFC3339, t)
 			if err != nil {
-				return response.Instances, err
+				return resp.Instances, err
 			}
-			response.Instances[i].Updated = updatedTime
+			resp.Instances[i].Updated = updatedTime
 		}
 	}
 
-	return response.Instances, err
+	return resp.Instances, nil
 }
 
 // UserRootResult represents the result of an operation to enable the root user.
diff --git a/rackspace/db/v1/backups/results.go b/rackspace/db/v1/backups/results.go
index 82b551d..04faf32 100644
--- a/rackspace/db/v1/backups/results.go
+++ b/rackspace/db/v1/backups/results.go
@@ -1,6 +1,8 @@
 package backups
 
 import (
+	"fmt"
+	"reflect"
 	"time"
 
 	"github.com/mitchellh/mapstructure"
@@ -109,12 +111,18 @@
 		Backups []Backup `mapstructure:"backups" json:"backups"`
 	}
 
-	err := mapstructure.Decode(casted, &resp)
+	if err := mapstructure.Decode(casted, &resp); err != nil {
+		return nil, err
+	}
 
 	var vals []interface{}
-	switch (casted).(type) {
-	case interface{}:
+	switch casted.(type) {
+	case map[string]interface{}:
 		vals = casted.(map[string]interface{})["backups"].([]interface{})
+	case map[string][]interface{}:
+		vals = casted.(map[string][]interface{})["backups"]
+	default:
+		return resp.Backups, fmt.Errorf("Unknown type: %v", reflect.TypeOf(casted))
 	}
 
 	for i, v := range vals {
@@ -137,5 +145,5 @@
 		}
 	}
 
-	return resp.Backups, err
+	return resp.Backups, nil
 }
diff --git a/rackspace/db/v1/instances/results.go b/rackspace/db/v1/instances/results.go
index 4b1317e..cdcc9c7 100644
--- a/rackspace/db/v1/instances/results.go
+++ b/rackspace/db/v1/instances/results.go
@@ -1,6 +1,8 @@
 package instances
 
 import (
+	"fmt"
+	"reflect"
 	"time"
 
 	"github.com/mitchellh/mapstructure"
@@ -147,16 +149,22 @@
 func ExtractInstances(page pagination.Page) ([]Instance, error) {
 	casted := page.(os.InstancePage).Body
 
-	var response struct {
+	var resp struct {
 		Instances []Instance `mapstructure:"instances"`
 	}
 
-	err := mapstructure.Decode(casted, &response)
+	if err := mapstructure.Decode(casted, &resp); err != nil {
+		return nil, err
+	}
 
 	var vals []interface{}
-	switch (casted).(type) {
-	case interface{}:
+	switch casted.(type) {
+	case map[string]interface{}:
 		vals = casted.(map[string]interface{})["instances"].([]interface{})
+	case map[string][]interface{}:
+		vals = casted.(map[string][]interface{})["instances"]
+	default:
+		return resp.Instances, fmt.Errorf("Unknown type: %v", reflect.TypeOf(casted))
 	}
 
 	for i, v := range vals {
@@ -165,19 +173,19 @@
 		if t, ok := val["created"].(string); ok && t != "" {
 			creationTime, err := time.Parse(time.RFC3339, t)
 			if err != nil {
-				return response.Instances, err
+				return resp.Instances, err
 			}
-			response.Instances[i].Created = creationTime
+			resp.Instances[i].Created = creationTime
 		}
 
 		if t, ok := val["updated"].(string); ok && t != "" {
 			updatedTime, err := time.Parse(time.RFC3339, t)
 			if err != nil {
-				return response.Instances, err
+				return resp.Instances, err
 			}
-			response.Instances[i].Updated = updatedTime
+			resp.Instances[i].Updated = updatedTime
 		}
 	}
 
-	return response.Instances, err
+	return resp.Instances, nil
 }