blob: d7cd145375ee9d9456d84ff0a0cfe1b8b929ee53 [file] [log] [blame]
Joe Topjian0f64da02017-03-09 18:59:53 -07001package availabilityzones
2
Ildar Svetlovb35f3612020-01-27 13:51:00 +04003import (
4 "encoding/json"
5 "time"
6
Ildar Svetlov82d42912020-01-27 14:47:43 +04007 "gerrit.mcp.mirantis.net/debian/gophercloud.git"
8 "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination"
Ildar Svetlovb35f3612020-01-27 13:51:00 +04009)
10
11// ServerAvailabilityZoneExt is an extension to the base Server object.
12type ServerAvailabilityZoneExt struct {
Joe Topjian0f64da02017-03-09 18:59:53 -070013 // AvailabilityZone is the availabilty zone the server is in.
14 AvailabilityZone string `json:"OS-EXT-AZ:availability_zone"`
15}
16
Ildar Svetlovb35f3612020-01-27 13:51:00 +040017// ServiceState represents the state of a service in an AvailabilityZone.
18type ServiceState struct {
19 Active bool `json:"active"`
20 Available bool `json:"available"`
21 UpdatedAt time.Time `json:"-"`
22}
23
Joe Topjian0f64da02017-03-09 18:59:53 -070024// UnmarshalJSON to override default
Ildar Svetlovb35f3612020-01-27 13:51:00 +040025func (r *ServiceState) UnmarshalJSON(b []byte) error {
26 type tmp ServiceState
27 var s struct {
28 tmp
29 UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at"`
30 }
31 err := json.Unmarshal(b, &s)
32 if err != nil {
33 return err
34 }
35 *r = ServiceState(s.tmp)
36
37 r.UpdatedAt = time.Time(s.UpdatedAt)
38
Joe Topjian0f64da02017-03-09 18:59:53 -070039 return nil
40}
Ildar Svetlovb35f3612020-01-27 13:51:00 +040041
42// Services is a map of services contained in an AvailabilityZone.
43type Services map[string]ServiceState
44
45// Hosts is map of hosts/nodes contained in an AvailabilityZone.
46// Each host can have multiple services.
47type Hosts map[string]Services
48
49// ZoneState represents the current state of the availability zone.
50type ZoneState struct {
51 // Returns true if the availability zone is available
52 Available bool `json:"available"`
53}
54
55// AvailabilityZone contains all the information associated with an OpenStack
56// AvailabilityZone.
57type AvailabilityZone struct {
58 Hosts Hosts `json:"hosts"`
59 // The availability zone name
60 ZoneName string `json:"zoneName"`
61 ZoneState ZoneState `json:"zoneState"`
62}
63
64type AvailabilityZonePage struct {
65 pagination.SinglePageBase
66}
67
68// ExtractAvailabilityZones returns a slice of AvailabilityZones contained in a
69// single page of results.
70func ExtractAvailabilityZones(r pagination.Page) ([]AvailabilityZone, error) {
71 var s struct {
72 AvailabilityZoneInfo []AvailabilityZone `json:"availabilityZoneInfo"`
73 }
74 err := (r.(AvailabilityZonePage)).ExtractInto(&s)
75 return s.AvailabilityZoneInfo, err
76}