blob: 104314cbf16be70d7f5542633a49fedd55b847b5 [file] [log] [blame]
ehdouc2b8dcd2017-01-11 06:01:00 +02001package availabilityzones
2
3import (
4 "encoding/json"
5 "time"
6
Krzysztof Szukiełojć3f41d082017-05-07 14:43:06 +02007 "gerrit.mcp.mirantis.net/debian/gophercloud.git"
Krzysztof Szukiełojć24a29ce2017-05-07 14:24:02 +02008 "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination"
ehdouc2b8dcd2017-01-11 06:01:00 +02009)
10
11// AvailabilityZone contains all the information associated with an OpenStack
12// AvailabilityZone.
13type 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
24type commonResult struct {
25 gophercloud.Result
26}
27
28// ListResult contains the response body and error from a List request.
29type AvailabilityZonePage struct {
30 pagination.SinglePageBase
31}
32
33// ExtractAvailabilityZones will get the AvailabilityZone objects out of the shareTypeAccessResult object.
34func 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
42func (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}