本文整理汇总了Golang中github.com/juju/juju/constraints.NewValidator函数的典型用法代码示例。如果您正苦于以下问题:Golang NewValidator函数的具体用法?Golang NewValidator怎么用?Golang NewValidator使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewValidator函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: constraintsValidator
func (st *State) constraintsValidator() (constraints.Validator, error) {
// Default behaviour is to simply use a standard validator with
// no environment specific behaviour built in.
defaultValidator := constraints.NewValidator()
if st.policy == nil {
return defaultValidator, nil
}
cfg, err := st.EnvironConfig()
if err != nil {
return nil, err
}
validator, err := st.policy.ConstraintsValidator(
cfg,
&cloudimagemetadata.MetadataArchitectureQuerier{st.CloudImageMetadataStorage},
)
if errors.IsNotImplemented(err) {
return defaultValidator, nil
} else if err != nil {
return nil, err
}
if validator == nil {
return nil, fmt.Errorf("policy returned nil constraints validator without an error")
}
return validator, nil
}
示例2: ConstraintsValidator
// ConstraintsValidator is defined on the Environs interface.
func (env *azureEnviron) ConstraintsValidator() (constraints.Validator, error) {
instanceTypes, err := env.getInstanceTypes()
if err != nil {
return nil, err
}
instTypeNames := make([]string, 0, len(instanceTypes))
for instTypeName := range instanceTypes {
instTypeNames = append(instTypeNames, instTypeName)
}
sort.Strings(instTypeNames)
validator := constraints.NewValidator()
validator.RegisterUnsupported([]string{
constraints.CpuPower,
constraints.Tags,
})
validator.RegisterVocabulary(
constraints.Arch,
env.supportedArchitectures(),
)
validator.RegisterVocabulary(
constraints.InstanceType,
instTypeNames,
)
validator.RegisterConflicts(
[]string{constraints.InstanceType},
[]string{
constraints.Mem,
constraints.CpuCores,
constraints.Arch,
constraints.RootDisk,
},
)
return validator, nil
}
示例3: ConstraintsValidator
// ConstraintsValidator is defined on the Environs interface.
func (e *environ) ConstraintsValidator() (constraints.Validator, error) {
validator := constraints.NewValidator()
validator.RegisterUnsupported([]string{constraints.CpuPower, constraints.VirtType})
validator.RegisterConflicts([]string{constraints.InstanceType}, []string{constraints.Mem})
validator.RegisterVocabulary(constraints.Arch, []string{arch.AMD64, arch.ARM64, arch.I386, arch.PPC64EL})
return validator, nil
}
示例4: SetUpTest
func (s *ModelConfigSuite) SetUpTest(c *gc.C) {
s.ControllerInheritedConfig = map[string]interface{}{
"apt-mirror": "http://cloud-mirror",
}
s.RegionConfig = cloud.RegionConfig{
"nether-region": cloud.Attrs{
"apt-mirror": "http://nether-region-mirror",
"no-proxy": "nether-proxy",
},
"dummy-region": cloud.Attrs{
"no-proxy": "dummy-proxy",
"image-stream": "dummy-image-stream",
"whimsy-key": "whimsy-value",
},
}
s.ConnSuite.SetUpTest(c)
s.policy.GetConstraintsValidator = func() (constraints.Validator, error) {
validator := constraints.NewValidator()
validator.RegisterConflicts([]string{constraints.InstanceType}, []string{constraints.Mem})
validator.RegisterUnsupported([]string{constraints.CpuPower})
return validator, nil
}
s.policy.GetProviderConfigSchemaSource = func() (config.ConfigSchemaSource, error) {
return &statetesting.MockConfigSchemaSource{}, nil
}
}
示例5: ConstraintsValidator
// ConstraintsValidator returns a Validator value which is used to
// validate and merge constraints.
func (env *environ) ConstraintsValidator() (constraints.Validator, error) {
validator := constraints.NewValidator()
// Register conflicts.
// We don't have any conflicts to register.
// Register unsupported constraints.
validator.RegisterUnsupported(unsupportedConstraints)
// Register the constraints vocab.
// TODO(ericsnow) This depends on the targetted remote host.
supportedArches, err := env.SupportedArchitectures()
if err != nil {
return nil, errors.Trace(err)
}
validator.RegisterVocabulary(constraints.Arch, supportedArches)
// TODO(ericsnow) Get this working...
//validator.RegisterVocabulary(constraints.Container, supportedContainerTypes)
return validator, nil
}
示例6: ConstraintsValidator
// ConstraintsValidator returns a Validator value which is used to
// validate and merge constraints.
func (env *environ) ConstraintsValidator() (constraints.Validator, error) {
validator := constraints.NewValidator()
// conflicts
// TODO(ericsnow) Are these correct?
validator.RegisterConflicts(
[]string{constraints.InstanceType},
instanceTypeConstraints,
)
// unsupported
validator.RegisterUnsupported(unsupportedConstraints)
// vocab
supportedArches, err := env.SupportedArchitectures()
if err != nil {
return nil, errors.Trace(err)
}
validator.RegisterVocabulary(constraints.Arch, supportedArches)
instTypeNames := make([]string, len(allInstanceTypes))
for i, itype := range allInstanceTypes {
instTypeNames[i] = itype.Name
}
validator.RegisterVocabulary(constraints.InstanceType, instTypeNames)
validator.RegisterVocabulary(constraints.Container, []string{vtype})
return validator, nil
}
示例7: SetUpTest
func (s *constraintsValidationSuite) SetUpTest(c *gc.C) {
s.ConnSuite.SetUpTest(c)
s.policy.GetConstraintsValidator = func(*config.Config) (constraints.Validator, error) {
validator := constraints.NewValidator()
validator.RegisterConflicts([]string{constraints.InstanceType}, []string{constraints.Mem, constraints.Arch})
validator.RegisterUnsupported([]string{constraints.CpuPower})
return validator, nil
}
}
示例8: constraintsValidator
func (st *State) constraintsValidator() (constraints.Validator, error) {
// Default behaviour is to simply use a standard validator with
// no model specific behaviour built in.
var validator constraints.Validator
if st.policy != nil {
var err error
validator, err = st.policy.ConstraintsValidator()
if errors.IsNotImplemented(err) {
validator = constraints.NewValidator()
} else if err != nil {
return nil, err
} else if validator == nil {
return nil, errors.New("policy returned nil constraints validator without an error")
}
} else {
validator = constraints.NewValidator()
}
// Add supported architectures gleaned from cloud image
// metadata to the validator's vocabulary.
model, err := st.Model()
if err != nil {
return nil, errors.Annotate(err, "getting model")
}
if region := model.CloudRegion(); region != "" {
cfg, err := st.ModelConfig()
if err != nil {
return nil, errors.Trace(err)
}
arches, err := st.CloudImageMetadataStorage.SupportedArchitectures(
cloudimagemetadata.MetadataFilter{
Stream: cfg.AgentStream(),
Region: region,
},
)
if err != nil {
return nil, errors.Annotate(err, "querying supported architectures")
}
if len(arches) != 0 {
validator.UpdateVocabulary(constraints.Arch, arches)
}
}
return validator, nil
}
示例9: TestMergeError
func (s *validationSuite) TestMergeError(c *gc.C) {
validator := constraints.NewValidator()
validator.RegisterConflicts([]string{"instance-type"}, []string{"mem"})
consFallback := constraints.MustParse("instance-type=foo mem=4G")
cons := constraints.MustParse("cores=2")
_, err := validator.Merge(consFallback, cons)
c.Assert(err, gc.ErrorMatches, `ambiguous constraints: "instance-type" overlaps with "mem"`)
_, err = validator.Merge(cons, consFallback)
c.Assert(err, gc.ErrorMatches, `ambiguous constraints: "instance-type" overlaps with "mem"`)
}
示例10: ConstraintsValidator
// ConstraintsValidator returns a Validator instance which
// is used to validate and merge constraints.
func (env *environ) ConstraintsValidator() (constraints.Validator, error) {
validator := constraints.NewValidator()
validator.RegisterUnsupported(unsupportedConstraints)
supportedArches, err := env.SupportedArchitectures()
if err != nil {
return nil, err
}
validator.RegisterVocabulary(constraints.Arch, supportedArches)
return validator, nil
}
示例11: SetUpTest
func (s *applicationConstraintsSuite) SetUpTest(c *gc.C) {
s.ConnSuite.SetUpTest(c)
s.policy.GetConstraintsValidator = func() (constraints.Validator, error) {
validator := constraints.NewValidator()
validator.RegisterVocabulary(constraints.VirtType, []string{"kvm"})
return validator, nil
}
s.applicationName = "wordpress"
s.testCharm = s.AddTestingCharm(c, s.applicationName)
}
示例12: SetUpTest
func (s *ServiceSuite) SetUpTest(c *gc.C) {
s.ConnSuite.SetUpTest(c)
s.policy.GetConstraintsValidator = func(*config.Config) (constraints.Validator, error) {
validator := constraints.NewValidator()
validator.RegisterConflicts([]string{constraints.InstanceType}, []string{constraints.Mem})
validator.RegisterUnsupported([]string{constraints.CpuPower})
return validator, nil
}
s.charm = s.AddTestingCharm(c, "mysql")
s.mysql = s.AddTestingService(c, "mysql", s.charm)
}
示例13: TestMerge
func (s *validationSuite) TestMerge(c *gc.C) {
for i, t := range mergeTests {
c.Logf("test %d: %s", i, t.desc)
validator := constraints.NewValidator()
validator.RegisterConflicts(t.reds, t.blues)
consFallback := constraints.MustParse(t.consFallback)
cons := constraints.MustParse(t.cons)
merged, err := validator.Merge(consFallback, cons)
c.Assert(err, jc.ErrorIsNil)
expected := constraints.MustParse(t.expected)
c.Check(merged, gc.DeepEquals, expected)
}
}
示例14: ConstraintsValidator
// ConstraintsValidator is defined on the Environs interface.
func (env *joyentEnviron) ConstraintsValidator() (constraints.Validator, error) {
validator := constraints.NewValidator()
validator.RegisterUnsupported(unsupportedConstraints)
packages, err := env.compute.cloudapi.ListPackages(nil)
if err != nil {
return nil, err
}
instTypeNames := make([]string, len(packages))
for i, pkg := range packages {
instTypeNames[i] = pkg.Name
}
validator.RegisterVocabulary(constraints.InstanceType, instTypeNames)
return validator, nil
}
示例15: ConstraintsValidator
// ConstraintsValidator is defined on the Environs interface.
func (e *manualEnviron) ConstraintsValidator() (constraints.Validator, error) {
validator := constraints.NewValidator()
validator.RegisterUnsupported(unsupportedConstraints)
if isRunningController() {
validator.UpdateVocabulary(constraints.Arch, []string{arch.HostArch()})
} else {
// We're running outside of the Juju controller, so we must
// SSH to the machine and detect its architecture.
hw, _, err := e.seriesAndHardwareCharacteristics()
if err != nil {
return nil, errors.Trace(err)
}
validator.UpdateVocabulary(constraints.Arch, []string{*hw.Arch})
}
return validator, nil
}