Ensure returned segmentation_id is a string (#70)
diff --git a/openstack/networking/v2/extensions/provider/results.go b/openstack/networking/v2/extensions/provider/results.go
old mode 100755
new mode 100644
index 229013b..37142e8
--- a/openstack/networking/v2/extensions/provider/results.go
+++ b/openstack/networking/v2/extensions/provider/results.go
@@ -1,6 +1,9 @@
package provider
import (
+ "encoding/json"
+ "strconv"
+
"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
"github.com/gophercloud/gophercloud/pagination"
)
@@ -48,6 +51,29 @@
SegmentationID string `json:"provider:segmentation_id"`
}
+func (n *NetworkExtAttrs) UnmarshalJSON(b []byte) error {
+ type tmp NetworkExtAttrs
+ var networkExtAttrs *struct {
+ tmp
+ SegmentationID interface{} `json:"provider:segmentation_id"`
+ }
+
+ if err := json.Unmarshal(b, &networkExtAttrs); err != nil {
+ return err
+ }
+
+ *n = NetworkExtAttrs(networkExtAttrs.tmp)
+
+ switch t := networkExtAttrs.SegmentationID.(type) {
+ case float64:
+ n.SegmentationID = strconv.FormatFloat(t, 'f', -1, 64)
+ case string:
+ n.SegmentationID = string(t)
+ }
+
+ return nil
+}
+
// ExtractGet decorates a GetResult struct returned from a networks.Get()
// function with extended attributes.
func ExtractGet(r networks.GetResult) (*NetworkExtAttrs, error) {