github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/core/network/zone.go (about) 1 // Copyright 2020 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package network 5 6 import "github.com/juju/errors" 7 8 // AvailabilityZone describes the common methods 9 // for general interaction with an AZ. 10 // 11 //go:generate go run go.uber.org/mock/mockgen -package mocks -destination ../../provider/common/mocks/availability_zone.go github.com/juju/juju/core/network AvailabilityZone 12 type AvailabilityZone interface { 13 // Name returns the name of the availability zone. 14 Name() string 15 16 // Available reports whether the availability zone is currently available. 17 Available() bool 18 } 19 20 // AvailabilityZones is a collection of AvailabilityZone. 21 type AvailabilityZones []AvailabilityZone 22 23 // Validate checks that a zone with the input name exists and is available 24 // according to the topology represented by the receiver. 25 // An error is returned if either of these conditions are not met. 26 func (a AvailabilityZones) Validate(zoneName string) error { 27 for _, az := range a { 28 if az.Name() == zoneName { 29 if az.Available() { 30 return nil 31 } 32 return errors.Errorf("zone %q is unavailable", zoneName) 33 } 34 } 35 return errors.NotValidf("availability zone %q", zoneName) 36 }