-
Notifications
You must be signed in to change notification settings - Fork 180
/
gcp_zoner_hack.go
41 lines (33 loc) · 948 Bytes
/
gcp_zoner_hack.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
package config
import (
"errors"
"fmt"
"github.com/cloudfoundry/bosh-bootloader/storage"
)
type GCPZonerHack struct {
gcpAvailabilityZoneRetriever gcpAvailabilityZoneRetriever
}
type gcpAvailabilityZoneRetriever interface {
GetZones(string) ([]string, error)
}
func NewGCPZonerHack(gcpAvailabilityZoneRetriever gcpAvailabilityZoneRetriever) GCPZonerHack {
return GCPZonerHack{
gcpAvailabilityZoneRetriever: gcpAvailabilityZoneRetriever,
}
}
func (g GCPZonerHack) SetZones(state storage.State) (storage.State, error) {
if len(state.GCP.Zones) == 0 {
zones, err := g.gcpAvailabilityZoneRetriever.GetZones(state.GCP.Region)
if err != nil {
return storage.State{}, fmt.Errorf("Retrieving availability zones: %s", err)
}
if len(zones) == 0 {
return storage.State{}, errors.New("Zone list is empty")
}
state.GCP.Zones = zones
}
if state.GCP.Zone == "" {
state.GCP.Zone = state.GCP.Zones[0]
}
return state, nil
}