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) {
diff --git a/openstack/networking/v2/extensions/provider/testing/results_test.go b/openstack/networking/v2/extensions/provider/testing/results_test.go
index 3b6a6fd..f6b321a 100644
--- a/openstack/networking/v2/extensions/provider/testing/results_test.go
+++ b/openstack/networking/v2/extensions/provider/testing/results_test.go
@@ -51,7 +51,7 @@
"tenant_id": "26a7980765d0414dbc1fc1f88cdb7e6e",
"shared": true,
"id": "db193ab3-96e3-4cb3-8fc5-05f4296d0324",
- "provider:segmentation_id": "1234567890",
+ "provider:segmentation_id": 1234567890,
"provider:physical_network": null,
"provider:network_type": "local"
}