github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/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  )
    14  
    15  // PrecheckInstance verifies that the provided series and constraints
    16  // are valid for use in creating an instance in this environment.
    17  func (env *environ) PrecheckInstance(series string, cons constraints.Value, placement string) error {
    18  	if _, err := env.parsePlacement(placement); err != nil {
    19  		return errors.Trace(err)
    20  	}
    21  
    22  	if cons.HasInstanceType() {
    23  		return errors.Errorf("LXD does not support instance types (got %q)", *cons.InstanceType)
    24  	}
    25  
    26  	return nil
    27  }
    28  
    29  var unsupportedConstraints = []string{
    30  	constraints.Cores,
    31  	constraints.CpuPower,
    32  	//TODO(ericsnow) Add constraints.Mem as unsupported?
    33  	constraints.InstanceType,
    34  	constraints.Tags,
    35  	constraints.VirtType,
    36  }
    37  
    38  // ConstraintsValidator returns a Validator value which is used to
    39  // validate and merge constraints.
    40  func (env *environ) ConstraintsValidator() (constraints.Validator, error) {
    41  	validator := constraints.NewValidator()
    42  
    43  	// Register conflicts.
    44  
    45  	// We don't have any conflicts to register.
    46  
    47  	// Register unsupported constraints.
    48  
    49  	validator.RegisterUnsupported(unsupportedConstraints)
    50  
    51  	// Register the constraints vocab.
    52  
    53  	// TODO(natefinch): This is only correct so long as the lxd is running on
    54  	// the local machine.  If/when we support a remote lxd environment, we'll
    55  	// need to change this to match the arch of the remote machine.
    56  	validator.RegisterVocabulary(constraints.Arch, []string{arch.HostArch()})
    57  
    58  	// TODO(ericsnow) Get this working...
    59  	//validator.RegisterVocabulary(constraints.Container, supportedContainerTypes)
    60  
    61  	return validator, nil
    62  }
    63  
    64  // SupportNetworks returns whether the environment has support to
    65  // specify networks for applications and machines.
    66  func (env *environ) SupportNetworks() bool {
    67  	return false
    68  }