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