github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/provider/gce/google/zone.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package google 5 6 import ( 7 "google.golang.org/api/compute/v1" 8 ) 9 10 // AvailabilityZone represents a single GCE zone. It satisfies the 11 // {provider/common}.AvailabilityZone interface. 12 type AvailabilityZone struct { 13 zone *compute.Zone 14 } 15 16 // NewZone build an availability zone from the provided name, status 17 // state, and replacement and returns it. 18 func NewZone(name, status, state, replacement string) AvailabilityZone { 19 zone := &compute.Zone{ 20 Name: name, 21 Status: status, 22 } 23 if state != "" { 24 zone.Deprecated = &compute.DeprecationStatus{ 25 State: state, 26 Replacement: replacement, 27 } 28 } 29 return AvailabilityZone{zone: zone} 30 } 31 32 // TODO(ericsnow) Add a Region getter? 33 34 // Name returns the zone's name. 35 func (z AvailabilityZone) Name() string { 36 return z.zone.Name 37 } 38 39 // Status returns the status string for the zone. It will match one of 40 // the Status* constants defined in the package. 41 func (z AvailabilityZone) Status() string { 42 return z.zone.Status 43 } 44 45 // Deprecated returns true if the zone has been deprecated. 46 func (z AvailabilityZone) Deprecated() bool { 47 deprecated := z.zone.Deprecated != nil 48 if deprecated { 49 logger.Warningf("zone %q is %q", z.Name(), z.zone.Deprecated.State) 50 if z.zone.Deprecated.Replacement != "" { 51 logger.Warningf("zone %q is the replacement for zone %q", z.zone.Deprecated.Replacement, z.Name()) 52 } 53 } 54 return deprecated 55 } 56 57 // Available returns whether or not the zone is available for provisioning. 58 func (z AvailabilityZone) Available() bool { 59 // https://cloud.google.com/compute/docs/reference/latest/zones#status 60 return z.Status() == StatusUp 61 }