File tree Expand file tree Collapse file tree
openstack/networking/v2/extensions/quotas Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package quotas
22
3- import "github.com/gophercloud/gophercloud"
3+ import (
4+ "encoding/json"
5+ "fmt"
6+ "strconv"
7+
8+ "github.com/gophercloud/gophercloud"
9+ )
410
511type commonResult struct {
612 gophercloud.Result
@@ -128,3 +134,40 @@ type QuotaDetail struct {
128134 // allocated/provisioned. This is what "quota" usually refers to.
129135 Limit int `json:"limit"`
130136}
137+
138+ // UnmarshalJSON overrides the default unmarshalling function to accept
139+ // Reserved as a string.
140+ //
141+ // Due to a bug in Neutron, under some conditions Reserved is returned as a
142+ // string.
143+ //
144+ // This method is left for compatibility with unpatched versions of Neutron.
145+ //
146+ // cf. https://bugs.launchpad.net/neutron/+bug/1918565
147+ func (q * QuotaDetail ) UnmarshalJSON (b []byte ) error {
148+ type tmp QuotaDetail
149+ var s struct {
150+ tmp
151+ Reserved interface {} `json:"reserved"`
152+ }
153+
154+ err := json .Unmarshal (b , & s )
155+ if err != nil {
156+ return err
157+ }
158+
159+ * q = QuotaDetail (s .tmp )
160+
161+ switch t := s .Reserved .(type ) {
162+ case float64 :
163+ q .Reserved = int (t )
164+ case string :
165+ if q .Reserved , err = strconv .Atoi (t ); err != nil {
166+ return err
167+ }
168+ default :
169+ return fmt .Errorf ("reserved has unexpected type: %T" , t )
170+ }
171+
172+ return nil
173+ }
Original file line number Diff line number Diff line change @@ -22,6 +22,11 @@ const GetResponseRaw = `
2222`
2323
2424// GetDetailedResponseRaw is a sample response to a Get call with the detailed option.
25+ //
26+ // One "reserved" property is returned as a string to reflect a buggy behaviour
27+ // of Neutron.
28+ //
29+ // cf. https://bugs.launchpad.net/neutron/+bug/1918565
2530const GetDetailedResponseRaw = `
2631{
2732 "quota" : {
@@ -38,7 +43,7 @@ const GetDetailedResponseRaw = `
3843 "port" : {
3944 "used": 0,
4045 "limit": 25,
41- "reserved": 0
46+ "reserved": "0"
4247 },
4348 "rbac_policy" : {
4449 "used": 0,
You can’t perform that action at this time.
0 commit comments