File tree Expand file tree Collapse file tree
openstack/blockstorage/v3/availabilityzones Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package availabilityzones
2+
3+ import (
4+ "github.com/gophercloud/gophercloud"
5+ "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/availabilityzones"
6+ )
7+
8+ // ListAvailableAvailabilityZones is a convenience function that return a slice of available Availability Zones.
9+ func ListAvailableAvailabilityZones (client * gophercloud.ServiceClient ) ([]string , error ) {
10+ var zones []string
11+
12+ allPages , err := availabilityzones .List (client ).AllPages ()
13+ if err != nil {
14+ return nil , err
15+ }
16+
17+ availabilityZoneInfo , err := availabilityzones .ExtractAvailabilityZones (allPages )
18+ if err != nil {
19+ return nil , err
20+ }
21+
22+ // This should always return at at least two AZs. By default, Nova will
23+ // return an AZ for internal services (typically called 'internal') and AZ
24+ // for (typically called 'nova'). We can obviously configure additional AZs
25+ // and you can also configure the names of these default AZs with
26+ // '[DEFAULT] internal_service_availability_zone' and
27+ // '[DEFAULT] default_availability_zone', respectively.
28+ for _ , zone := range availabilityZoneInfo {
29+ if zone .ZoneState .Available {
30+ zones = append (zones , zone .ZoneName )
31+ }
32+ }
33+
34+ return zones , nil
35+ }
You can’t perform that action at this time.
0 commit comments