Beispiel #1
0
func (c *bootstrapCommand) parseConstraints(ctx *cmd.Context) (err error) {
	allAliases := map[string]string{}
	defer common.WarnConstraintAliases(ctx, allAliases)
	if c.ConstraintsStr != "" {
		cons, aliases, err := constraints.ParseWithAliases(c.ConstraintsStr)
		for k, v := range aliases {
			allAliases[k] = v
		}
		if err != nil {
			return err
		}
		c.Constraints = cons
	}
	if c.BootstrapConstraintsStr != "" {
		cons, aliases, err := constraints.ParseWithAliases(c.BootstrapConstraintsStr)
		for k, v := range aliases {
			allAliases[k] = v
		}
		if err != nil {
			return err
		}
		c.BootstrapConstraints = cons
	}
	return nil
}
Beispiel #2
0
func (s *ConstraintsSuite) TestParseAliases(c *gc.C) {
	v, aliases, err := constraints.ParseWithAliases("cpu-cores=5 arch=amd64")
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(v, gc.DeepEquals, constraints.Value{
		CpuCores: uint64p(5),
		Arch:     strp("amd64"),
	})
	c.Assert(aliases, gc.DeepEquals, map[string]string{
		"cpu-cores": "cores",
	})
}
Beispiel #3
0
Datei: flags.go Projekt: bac/juju
// ParseConstraints parses the given constraints and uses WarnConstraintAliases
// if any aliases were used.
func ParseConstraints(ctx *cmd.Context, cons string) (constraints.Value, error) {
	if cons == "" {
		return constraints.Value{}, nil
	}
	constraint, aliases, err := constraints.ParseWithAliases(cons)
	// we always do these, even on errors, so that the error messages have
	// context.
	for alias, canonical := range aliases {
		ctx.Infof("Warning: constraint %q is deprecated in favor of %q.\n", alias, canonical)
	}
	if err != nil {
		return constraints.Value{}, err
	}
	return constraint, nil
}