ehdou | c2b8dcd | 2017-01-11 06:01:00 +0200 | [diff] [blame] | 1 | package availabilityzones |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "time" |
| 6 | |
Krzysztof Szukiełojć | 3f41d08 | 2017-05-07 14:43:06 +0200 | [diff] [blame^] | 7 | "gerrit.mcp.mirantis.net/debian/gophercloud.git" |
Krzysztof Szukiełojć | 24a29ce | 2017-05-07 14:24:02 +0200 | [diff] [blame] | 8 | "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination" |
ehdou | c2b8dcd | 2017-01-11 06:01:00 +0200 | [diff] [blame] | 9 | ) |
| 10 | |
| 11 | // AvailabilityZone contains all the information associated with an OpenStack |
| 12 | // AvailabilityZone. |
| 13 | type AvailabilityZone struct { |
| 14 | // The availability zone ID. |
| 15 | ID string `json:"id"` |
| 16 | // The name of the availability zone. |
| 17 | Name string `json:"name"` |
| 18 | // The date and time stamp when the availability zone was created. |
| 19 | CreatedAt time.Time `json:"-"` |
| 20 | // The date and time stamp when the availability zone was updated. |
| 21 | UpdatedAt time.Time `json:"-"` |
| 22 | } |
| 23 | |
| 24 | type commonResult struct { |
| 25 | gophercloud.Result |
| 26 | } |
| 27 | |
| 28 | // ListResult contains the response body and error from a List request. |
| 29 | type AvailabilityZonePage struct { |
| 30 | pagination.SinglePageBase |
| 31 | } |
| 32 | |
| 33 | // ExtractAvailabilityZones will get the AvailabilityZone objects out of the shareTypeAccessResult object. |
| 34 | func ExtractAvailabilityZones(r pagination.Page) ([]AvailabilityZone, error) { |
| 35 | var a struct { |
| 36 | AvailabilityZone []AvailabilityZone `json:"availability_zones"` |
| 37 | } |
| 38 | err := (r.(AvailabilityZonePage)).ExtractInto(&a) |
| 39 | return a.AvailabilityZone, err |
| 40 | } |
| 41 | |
| 42 | func (r *AvailabilityZone) UnmarshalJSON(b []byte) error { |
| 43 | type tmp AvailabilityZone |
| 44 | var s struct { |
| 45 | tmp |
| 46 | CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at"` |
| 47 | UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at"` |
| 48 | } |
| 49 | err := json.Unmarshal(b, &s) |
| 50 | if err != nil { |
| 51 | return err |
| 52 | } |
| 53 | *r = AvailabilityZone(s.tmp) |
| 54 | |
| 55 | r.CreatedAt = time.Time(s.CreatedAt) |
| 56 | r.UpdatedAt = time.Time(s.UpdatedAt) |
| 57 | |
| 58 | return nil |
| 59 | } |