Exemplo n.º 1
0
func (c *UnitCommandBase) Init(args []string) error {
	if c.NumUnits < 1 {
		return errors.New("--num-units must be a positive integer")
	}
	if c.ToMachineSpec != "" {
		if c.NumUnits > 1 {
			return errors.New("cannot use --num-units > 1 with --to")
		}
		if !state.IsMachineOrNewContainer(c.ToMachineSpec) {
			return fmt.Errorf("invalid --to parameter %q", c.ToMachineSpec)
		}
	}
	return nil
}
Exemplo n.º 2
0
func (c *AddMachineCommand) Init(args []string) error {
	if c.Constraints.Container != nil {
		return fmt.Errorf("container constraint %q not allowed when adding a machine", *c.Constraints.Container)
	}
	containerSpec, err := cmd.ZeroOrOneArgs(args)
	if err != nil {
		return err
	}
	if containerSpec == "" {
		return nil
	}
	// container arg can either be 'type:machine' or 'type'
	if c.ContainerType, err = instance.ParseSupportedContainerType(containerSpec); err != nil {
		if !state.IsMachineOrNewContainer(containerSpec) {
			return fmt.Errorf("malformed container argument %q", containerSpec)
		}
		sep := strings.Index(containerSpec, ":")
		c.MachineId = containerSpec[sep+1:]
		c.ContainerType, err = instance.ParseSupportedContainerType(containerSpec[:sep])
	}
	return err
}