~wallyworld/juju-core/fast-lxc-everywhere

« back to all changes in this revision

Viewing changes to provider/joyent/environ_instance.go

  • Committer: Tarmac
  • Author(s): Ian Booth
  • Date: 2014-04-24 12:33:19 UTC
  • mfrom: (2664.1.4 constraints-vocab)
  • Revision ID: tarmac-20140424123319-iifvboa1kjuprj7l
[r=wallyworld] Support constraints vocabs

Add support to constraints validation for
vocabs for each attribute. eg arch and
instance-type can only have well defined
values for each provider. The vocab check
is part of constraints validation.

https://codereview.appspot.com/96730043/

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
}
60
60
 
61
61
// ConstraintsValidator is defined on the Environs interface.
62
 
func (env *joyentEnviron) ConstraintsValidator() constraints.Validator {
 
62
func (env *joyentEnviron) ConstraintsValidator() (constraints.Validator, error) {
63
63
        validator := constraints.NewValidator()
64
64
        validator.RegisterUnsupported(unsupportedConstraints)
65
 
        return validator
 
65
        supportedArches, err := env.SupportedArchitectures()
 
66
        if err != nil {
 
67
                return nil, err
 
68
        }
 
69
        validator.RegisterVocabulary(constraints.Arch, supportedArches)
 
70
        packages, err := env.compute.cloudapi.ListPackages(nil)
 
71
        if err != nil {
 
72
                return nil, err
 
73
        }
 
74
        instTypeNames := make([]string, len(packages))
 
75
        for i, pkg := range packages {
 
76
                instTypeNames[i] = pkg.Name
 
77
        }
 
78
        validator.RegisterVocabulary(constraints.InstanceType, instTypeNames)
 
79
        return validator, nil
66
80
}
67
81
 
68
82
func (env *joyentEnviron) StartInstance(args environs.StartInstanceParams) (instance.Instance, *instance.HardwareCharacteristics, []network.Info, error) {