1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
9
"github.com/juju/errors"
10
"github.com/juju/utils/set"
12
"github.com/juju/juju/constraints"
13
"github.com/juju/juju/environs"
14
"github.com/juju/juju/environs/imagemetadata"
15
"github.com/juju/juju/environs/simplestreams"
16
"github.com/juju/juju/network"
19
// PrecheckInstance verifies that the provided series and constraints
20
// are valid for use in creating an instance in this environment.
21
func (env *environ) PrecheckInstance(series string, cons constraints.Value, placement string) error {
23
if _, err := env.parsePlacement(placement); err != nil {
30
// SupportedArchitectures returns the image architectures which can
31
// be hosted by this environment.
32
func (env *environ) SupportedArchitectures() ([]string, error) {
34
defer env.archLock.Unlock()
36
if env.supportedArchitectures != nil {
37
return env.supportedArchitectures, nil
40
archList, err := env.lookupArchitectures()
42
return nil, errors.Trace(err)
44
env.supportedArchitectures = archList
48
func (env *environ) lookupArchitectures() ([]string, error) {
49
// Create a filter to get all images for the
51
imageConstraint := imagemetadata.NewImageConstraint(simplestreams.LookupParams{
52
Stream: env.Config().ImageStream(),
54
sources, err := environs.ImageMetadataSources(env)
56
return nil, errors.Trace(err)
58
matchingImages, err := imageMetadataFetch(sources, imageConstraint)
60
return nil, errors.Trace(err)
63
var arches = set.NewStrings()
64
for _, im := range matchingImages {
68
return arches.Values(), nil
71
var unsupportedConstraints = []string{
76
// instanceTypeConstraints defines the fields defined on each of the
77
// instance types. See instancetypes.go.
78
var instanceConstraints = []string{
79
constraints.Arch, // Arches
85
// ConstraintsValidator returns a Validator value which is used to
86
// validate and merge constraints.
87
func (env *environ) ConstraintsValidator() (constraints.Validator, error) {
88
validator := constraints.NewValidator()
92
validator.RegisterUnsupported(unsupportedConstraints)
96
supportedArches, err := env.SupportedArchitectures()
98
return nil, errors.Trace(err)
100
validator.RegisterVocabulary(constraints.Arch, supportedArches)
102
return validator, nil
105
// SupportsUnitPlacement implement via common.SupportsUnitPlacementPolicy
107
// SupportNetworks returns whether the environment has support to
108
// specify networks for services and machines.
109
func (env *environ) SupportNetworks() bool {
113
// SupportAddressAllocation takes a network.Id and returns a bool
114
// and an error. The bool indicates whether that network supports
115
// static ip address allocation.
116
func (env *environ) SupportAddressAllocation(netID network.Id) (bool, error) {