github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/provider/vsphere/environ_policy.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 // +build !gccgo 5 6 package vsphere 7 8 import ( 9 "github.com/juju/errors" 10 "github.com/juju/utils/set" 11 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" 17 ) 18 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 { 22 if placement != "" { 23 if _, err := env.parsePlacement(placement); err != nil { 24 return err 25 } 26 } 27 return nil 28 } 29 30 // SupportedArchitectures returns the image architectures which can 31 // be hosted by this environment. 32 func (env *environ) SupportedArchitectures() ([]string, error) { 33 env.archLock.Lock() 34 defer env.archLock.Unlock() 35 36 if env.supportedArchitectures != nil { 37 return env.supportedArchitectures, nil 38 } 39 40 archList, err := env.lookupArchitectures() 41 if err != nil { 42 return nil, errors.Trace(err) 43 } 44 env.supportedArchitectures = archList 45 return archList, nil 46 } 47 48 func (env *environ) lookupArchitectures() ([]string, error) { 49 // Create a filter to get all images for the 50 // correct stream. 51 imageConstraint := imagemetadata.NewImageConstraint(simplestreams.LookupParams{ 52 Stream: env.Config().ImageStream(), 53 }) 54 sources, err := environs.ImageMetadataSources(env) 55 if err != nil { 56 return nil, errors.Trace(err) 57 } 58 matchingImages, err := imageMetadataFetch(sources, imageConstraint) 59 if err != nil { 60 return nil, errors.Trace(err) 61 } 62 63 var arches = set.NewStrings() 64 for _, im := range matchingImages { 65 arches.Add(im.Arch) 66 } 67 68 return arches.Values(), nil 69 } 70 71 var unsupportedConstraints = []string{ 72 constraints.Tags, 73 constraints.VirtType, 74 } 75 76 // ConstraintsValidator returns a Validator value which is used to 77 // validate and merge constraints. 78 func (env *environ) ConstraintsValidator() (constraints.Validator, error) { 79 validator := constraints.NewValidator() 80 81 // unsupported 82 83 validator.RegisterUnsupported(unsupportedConstraints) 84 85 // vocab 86 87 supportedArches, err := env.SupportedArchitectures() 88 if err != nil { 89 return nil, errors.Trace(err) 90 } 91 validator.RegisterVocabulary(constraints.Arch, supportedArches) 92 93 return validator, nil 94 } 95 96 // SupportsUnitPlacement implement via common.SupportsUnitPlacementPolicy 97 98 // SupportNetworks returns whether the environment has support to 99 // specify networks for services and machines. 100 func (env *environ) SupportNetworks() bool { 101 return false 102 } 103 104 // SupportAddressAllocation takes a network.Id and returns a bool 105 // and an error. The bool indicates whether that network supports 106 // static ip address allocation. 107 func (env *environ) SupportAddressAllocation(netID network.Id) (bool, error) { 108 return false, nil 109 }