github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/provider/lxd/environ_policy.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 // +build go1.3 5 6 package lxd 7 8 import ( 9 "github.com/juju/errors" 10 "github.com/juju/utils/arch" 11 12 "github.com/juju/juju/constraints" 13 "github.com/juju/juju/network" 14 ) 15 16 type policyProvider interface { 17 // SupportedArchitectures returns the list of image architectures 18 // supported by this environment. 19 SupportedArchitectures() ([]string, error) 20 } 21 22 type lxdPolicyProvider struct{} 23 24 // SupportedArchitectures returns the image architectures which can 25 // be hosted by this environment. 26 func (pp *lxdPolicyProvider) SupportedArchitectures() ([]string, error) { 27 // TODO(natefinch): This is only correct so long as the lxd is running on 28 // the local machine. If/when we support a remote lxd environment, we'll 29 // need to change this to match the arch of the remote machine. 30 31 // TODO(ericsnow) Use common.SupportedArchitectures? 32 localArch := arch.HostArch() 33 return []string{localArch}, nil 34 } 35 36 // PrecheckInstance verifies that the provided series and constraints 37 // are valid for use in creating an instance in this environment. 38 func (env *environ) PrecheckInstance(series string, cons constraints.Value, placement string) error { 39 if _, err := env.parsePlacement(placement); err != nil { 40 return errors.Trace(err) 41 } 42 43 if cons.HasInstanceType() { 44 return errors.Errorf("LXD does not support instance types (got %q)", *cons.InstanceType) 45 } 46 47 return nil 48 } 49 50 // SupportedArchitectures returns the image architectures which can 51 // be hosted by this environment. 52 func (env *environ) SupportedArchitectures() ([]string, error) { 53 // TODO(ericsnow) The supported arch depends on the targetted 54 // remote. Thus we may need to support the remote as a constraint. 55 arches, err := env.raw.SupportedArchitectures() 56 if err != nil { 57 return nil, errors.Trace(err) 58 } 59 return arches, nil 60 } 61 62 var unsupportedConstraints = []string{ 63 constraints.CpuCores, 64 constraints.CpuPower, 65 //TODO(ericsnow) Add constraints.Mem as unsupported? 66 constraints.InstanceType, 67 constraints.Tags, 68 constraints.VirtType, 69 } 70 71 // ConstraintsValidator returns a Validator value which is used to 72 // validate and merge constraints. 73 func (env *environ) ConstraintsValidator() (constraints.Validator, error) { 74 validator := constraints.NewValidator() 75 76 // Register conflicts. 77 78 // We don't have any conflicts to register. 79 80 // Register unsupported constraints. 81 82 validator.RegisterUnsupported(unsupportedConstraints) 83 84 // Register the constraints vocab. 85 86 // TODO(ericsnow) This depends on the targetted remote host. 87 supportedArches, err := env.SupportedArchitectures() 88 if err != nil { 89 return nil, errors.Trace(err) 90 } 91 validator.RegisterVocabulary(constraints.Arch, supportedArches) 92 93 // TODO(ericsnow) Get this working... 94 //validator.RegisterVocabulary(constraints.Container, supportedContainerTypes) 95 96 return validator, nil 97 } 98 99 // environ provides SupportsUnitPlacement (a method of the 100 // state.EnvironCapatability interface) by embedding 101 // common.SupportsUnitPlacementPolicy. 102 103 // SupportNetworks returns whether the environment has support to 104 // specify networks for services and machines. 105 func (env *environ) SupportNetworks() bool { 106 return false 107 } 108 109 // SupportAddressAllocation takes a network.Id and returns a bool 110 // and an error. The bool indicates whether that network supports 111 // static ip address allocation. 112 func (env *environ) SupportAddressAllocation(netID network.Id) (bool, error) { 113 return false, nil 114 }