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

« back to all changes in this revision

Viewing changes to provider/openstack/provider.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:
528
528
}
529
529
 
530
530
// ConstraintsValidator is defined on the Environs interface.
531
 
func (e *environ) ConstraintsValidator() constraints.Validator {
 
531
func (e *environ) ConstraintsValidator() (constraints.Validator, error) {
532
532
        validator := constraints.NewValidator()
533
533
        validator.RegisterConflicts(
534
534
                []string{constraints.InstanceType},
535
535
                []string{constraints.Mem, constraints.Arch, constraints.RootDisk, constraints.CpuCores})
536
536
        validator.RegisterUnsupported(unsupportedConstraints)
537
 
        return validator
 
537
        supportedArches, err := e.SupportedArchitectures()
 
538
        if err != nil {
 
539
                return nil, err
 
540
        }
 
541
        validator.RegisterVocabulary(constraints.Arch, supportedArches)
 
542
        novaClient := e.nova()
 
543
        flavors, err := novaClient.ListFlavorsDetail()
 
544
        if err != nil {
 
545
                return nil, err
 
546
        }
 
547
        instTypeNames := make([]string, len(flavors))
 
548
        for i, flavor := range flavors {
 
549
                instTypeNames[i] = flavor.Name
 
550
        }
 
551
        validator.RegisterVocabulary(constraints.InstanceType, instTypeNames)
 
552
        return validator, nil
538
553
}
539
554
 
540
555
// PrecheckInstance is defined on the state.Prechecker interface.