github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/availabilityzones/results.go (about) 1 package availabilityzones 2 3 import ( 4 "encoding/json" 5 "time" 6 7 "github.com/huaweicloud/golangsdk" 8 "github.com/huaweicloud/golangsdk/pagination" 9 ) 10 11 // ServerAvailabilityZoneExt is an extension to the base Server object. 12 type ServerAvailabilityZoneExt struct { 13 // AvailabilityZone is the availabilty zone the server is in. 14 AvailabilityZone string `json:"OS-EXT-AZ:availability_zone"` 15 } 16 17 // ServiceState represents the state of a service in an AvailabilityZone. 18 type ServiceState struct { 19 Active bool `json:"active"` 20 Available bool `json:"available"` 21 UpdatedAt time.Time `json:"-"` 22 } 23 24 // UnmarshalJSON to override default 25 func (r *ServiceState) UnmarshalJSON(b []byte) error { 26 type tmp ServiceState 27 var s struct { 28 tmp 29 UpdatedAt golangsdk.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 39 return nil 40 } 41 42 // Services is a map of services contained in an AvailabilityZone. 43 type Services map[string]ServiceState 44 45 // Hosts is map of hosts/nodes contained in an AvailabilityZone. 46 // Each host can have multiple services. 47 type Hosts map[string]Services 48 49 // ZoneState represents the current state of the availability zone. 50 type 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. 57 type AvailabilityZone struct { 58 Hosts Hosts `json:"hosts"` 59 // The availability zone name 60 ZoneName string `json:"zoneName"` 61 ZoneState ZoneState `json:"zoneState"` 62 } 63 64 type AvailabilityZonePage struct { 65 pagination.SinglePageBase 66 } 67 68 // ExtractAvailabilityZones returns a slice of AvailabilityZones contained in a 69 // single page of results. 70 func 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 }