Ejemplo n.º 1
0
func (*ConstraintsSuite) testParseStorageConstraints(c *gc.C,
	s []string,
	mustHave bool,
	expect map[string]storage.Constraints,
) {
	cons, err := storage.ParseConstraintsMap(s, mustHave)
	c.Check(err, jc.ErrorIsNil)
	c.Assert(len(cons), gc.Equals, len(expect))
	for k, v := range expect {
		c.Check(cons[k], gc.DeepEquals, v)
	}
}
Ejemplo n.º 2
0
Archivo: add.go Proyecto: pmatulis/juju
// Init implements Command.Init.
func (c *addCommand) Init(args []string) (err error) {
	if len(args) < 2 {
		return errors.New("storage add requires a unit and a storage directive")
	}

	u := args[0]
	if !names.IsValidUnit(u) {
		return errors.NotValidf("unit name %q", u)
	}
	c.unitTag = names.NewUnitTag(u).String()

	c.storageCons, err = storage.ParseConstraintsMap(args[1:], false)
	return
}
Ejemplo n.º 3
0
func (s *StorageAddCommand) Init(args []string) error {
	if len(args) < 1 {
		return errors.New("storage add requires a storage directive")
	}

	cons, err := storage.ParseConstraintsMap(args, false)
	if err != nil {
		return errors.Trace(err)
	}

	s.all = make(map[string]params.StorageConstraints, len(cons))
	for k, v := range cons {
		if v != (storage.Constraints{Count: v.Count}) {
			return errors.Errorf("only count can be specified for %q", k)
		}
		s.all[k] = params.StorageConstraints{Count: &v.Count}
	}
	return nil
}
Ejemplo n.º 4
0
func (*ConstraintsSuite) testStorageConstraintsError(c *gc.C, s []string, mustHave bool, e string) {
	_, err := storage.ParseConstraintsMap(s, mustHave)
	c.Check(err, gc.ErrorMatches, e)
}