github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/provider/gce/environ_policy.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package gce 5 6 import ( 7 "github.com/juju/errors" 8 9 "github.com/juju/juju/constraints" 10 ) 11 12 // PrecheckInstance verifies that the provided series and constraints 13 // are valid for use in creating an instance in this environment. 14 func (env *environ) PrecheckInstance(series string, cons constraints.Value, placement string) error { 15 if _, err := env.parsePlacement(placement); err != nil { 16 return errors.Trace(err) 17 } 18 19 if cons.HasInstanceType() { 20 if !checkInstanceType(cons) { 21 return errors.Errorf("invalid GCE instance type %q", *cons.InstanceType) 22 } 23 } 24 25 return nil 26 } 27 28 var unsupportedConstraints = []string{ 29 constraints.Tags, 30 constraints.VirtType, 31 } 32 33 // instanceTypeConstraints defines the fields defined on each of the 34 // instance types. See instancetypes.go. 35 var instanceTypeConstraints = []string{ 36 constraints.Arch, // Arches 37 constraints.Cores, 38 constraints.CpuPower, 39 constraints.Mem, 40 constraints.Container, // VirtType 41 } 42 43 // ConstraintsValidator returns a Validator value which is used to 44 // validate and merge constraints. 45 func (env *environ) ConstraintsValidator() (constraints.Validator, error) { 46 validator := constraints.NewValidator() 47 48 // conflicts 49 50 // TODO(ericsnow) Are these correct? 51 validator.RegisterConflicts( 52 []string{constraints.InstanceType}, 53 instanceTypeConstraints, 54 ) 55 56 // unsupported 57 58 validator.RegisterUnsupported(unsupportedConstraints) 59 60 // vocab 61 62 instTypeNames := make([]string, len(allInstanceTypes)) 63 for i, itype := range allInstanceTypes { 64 instTypeNames[i] = itype.Name 65 } 66 validator.RegisterVocabulary(constraints.InstanceType, instTypeNames) 67 68 validator.RegisterVocabulary(constraints.Container, []string{vtype}) 69 70 return validator, nil 71 } 72 73 // SupportNetworks returns whether the environment has support to 74 // specify networks for applications and machines. 75 func (env *environ) SupportNetworks() bool { 76 return false 77 }