github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/provider/cloudsigma/environcaps.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package cloudsigma
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  
     9  	"github.com/juju/juju/constraints"
    10  	"github.com/juju/juju/environs/imagemetadata"
    11  	"github.com/juju/juju/environs/simplestreams"
    12  	"github.com/juju/juju/provider/common"
    13  )
    14  
    15  func (env *environ) SupportedArchitectures() ([]string, error) {
    16  	env.archMutex.Lock()
    17  	defer env.archMutex.Unlock()
    18  	if env.supportedArchitectures != nil {
    19  		return env.supportedArchitectures, nil
    20  	}
    21  	logger.Debugf("Getting supported architectures from simplestream.")
    22  	cloudSpec, err := env.Region()
    23  	if err != nil {
    24  		return nil, err
    25  	}
    26  	imageConstraint := imagemetadata.NewImageConstraint(simplestreams.LookupParams{
    27  		CloudSpec: cloudSpec,
    28  		Stream:    env.Config().ImageStream(),
    29  	})
    30  	env.supportedArchitectures, err = common.SupportedArchitectures(env, imageConstraint)
    31  	logger.Debugf("Supported architectures: %v", env.supportedArchitectures)
    32  	return env.supportedArchitectures, err
    33  }
    34  
    35  var unsupportedConstraints = []string{
    36  	constraints.Container,
    37  	constraints.InstanceType,
    38  	constraints.Tags,
    39  }
    40  
    41  // ConstraintsValidator returns a Validator instance which
    42  // is used to validate and merge constraints.
    43  func (env *environ) ConstraintsValidator() (constraints.Validator, error) {
    44  	validator := constraints.NewValidator()
    45  	validator.RegisterUnsupported(unsupportedConstraints)
    46  	supportedArches, err := env.SupportedArchitectures()
    47  	if err != nil {
    48  		return nil, err
    49  	}
    50  	validator.RegisterVocabulary(constraints.Arch, supportedArches)
    51  	return validator, nil
    52  }
    53  
    54  // SupportNetworks returns whether the environment has support to
    55  // specify networks for services and machines.
    56  func (env *environ) SupportNetworks() bool {
    57  	return false
    58  }
    59  
    60  // SupportsUnitAssignment returns an error which, if non-nil, indicates
    61  // that the environment does not support unit placement. If the environment
    62  // does not support unit placement, then machines may not be created
    63  // without units, and units cannot be placed explcitly.
    64  func (env *environ) SupportsUnitPlacement() error {
    65  	return errors.NotImplementedf("SupportsUnitPlacement")
    66  }