func (p *Provision) GetMachineList(patterns ...string) []string { patterns = preSplit(patterns...) machineList := []string{} // if patterns is blank, get all args := []string{} if len(patterns) == 0 { for group := range p.Machines { args = append(args, group) } } else { args = append(args, patterns...) } for _, arg := range args { if details, exist := p.Machines[arg]; exist { // if it's the only instance, use arg as name if details.Instances == 0 || details.Instances == 1 { machineList = append(machineList, arg) } else { pattern := fmt.Sprintf("%s-[%d:%d]", arg, details.BaseIndex, details.Instances) machineList = append(machineList, utils.Generate(pattern)...) } } else { // assume it's a pattern machineList = append(machineList, utils.Generate(arg)...) } } return machineList }
func DoRmm(cli interface{}, args ...string) error { cmd := Cli.Subcmd("rmm", []string{"MACHINES"}, "Remove machines", false) force := cmd.Bool([]string{"f", "-force"}, false, "Force removing machines") cmd.ParseFlags(args, true) if len(cmd.Args()) == 0 { return fmt.Errorf("You must specify a machine or pattern name") } isError := false store := machine.GetDefaultStore(utils.GetBaseDir()) for _, pattern := range cmd.Args() { for _, hostName := range utils.Generate(pattern) { h, err := loadHost(store, hostName, utils.GetBaseDir()) if err != nil { isError = true log.Errorf("Error removing machine %s: %s", hostName, err) } if err := h.Driver.Remove(); err != nil { if !*force { isError = true log.Errorf("Provider error removing machine %q: %s", hostName, err) continue } } if err := store.Remove(hostName); err != nil { isError = true log.Errorf("Error removing machine %q from store: %s", hostName, err) } else { log.Infof("Successfully removed %s", hostName) } } } if isError { return fmt.Errorf("There was an error removing a machine.") } return nil }