예제 #1
0
파일: rm.go 프로젝트: RaulKite/machine
func removeLocalMachine(hostName string, api libmachine.API) error {
	exist, _ := api.Exists(hostName)
	if !exist {
		return errors.New(hostName + " does not exist.")
	}
	return api.Remove(hostName)
}
예제 #2
0
// Remove removes a Docker Machine
func Remove(api libmachine.API, args map[string]string, form map[string][]string) (interface{}, error) {
	name, present := args["name"]
	if !present {
		return nil, errRequireMachineName
	}

	exist, _ := api.Exists(name)
	if !exist {
		return Success{"removed", name}, nil
	}

	currentHost, err := api.Load(name)
	if err != nil {
		return nil, err
	}

	if err := currentHost.Driver.Remove(); err != nil {
		return nil, err
	}

	if err := api.Remove(name); err != nil {
		return nil, err
	}

	return Success{"removed", name}, nil
}
예제 #3
0
파일: rm.go 프로젝트: ksasi/machine
func cmdRm(c CommandLine, api libmachine.API) error {
	if len(c.Args()) == 0 {
		c.ShowHelp()
		return errors.New("You must specify a machine name")
	}

	force := c.Bool("force")

	for _, hostName := range c.Args() {
		h, err := api.Load(hostName)
		if err != nil {
			return fmt.Errorf("Error removing host %q: %s", hostName, err)
		}

		if err := h.Driver.Remove(); err != nil {
			if !force {
				log.Errorf("Provider error removing machine %q: %s", hostName, err)
				continue
			}
		}

		if err := api.Remove(hostName); err != nil {
			log.Errorf("Error removing machine %q from store: %s", hostName, err)
		} else {
			log.Infof("Successfully removed %s", hostName)
		}
	}

	return nil
}
예제 #4
0
// DeleteHost deletes the host VM.
func DeleteHost(api libmachine.API) error {
	host, err := api.Load(constants.MachineName)
	if err != nil {
		return errors.Wrapf(err, "Error deleting host: %s", constants.MachineName)
	}
	m := util.MultiError{}
	m.Collect(host.Driver.Remove())
	m.Collect(api.Remove(constants.MachineName))
	return m.ToError()
}
예제 #5
0
파일: cluster.go 프로젝트: tmrts/minikube
// DeleteHost deletes the host VM.
func DeleteHost(api libmachine.API) error {
	host, err := api.Load(constants.MachineName)
	if err != nil {
		return err
	}
	m := multiError{}
	m.Collect(host.Driver.Remove())
	m.Collect(api.Remove(constants.MachineName))
	return m.ToError()
}
예제 #6
0
func cmdRm(c CommandLine, api libmachine.API) error {
	if len(c.Args()) == 0 {
		c.ShowHelp()
		return ErrNoMachineSpecified
	}

	force := c.Bool("force")
	confirm := c.Bool("y")

	for _, hostName := range c.Args() {
		h, loaderr := api.Load(hostName)
		if loaderr != nil {
			// On --force, continue to remove on-disk files/dir
			if !force {
				return fmt.Errorf("Error removing host %q: %s", hostName, loaderr)
			}
			log.Errorf("Error removing host %q: %s. Continuing on `-f`, host instance may by running", hostName, loaderr)
		}

		if !confirm && !force {
			userinput, err := confirmInput(fmt.Sprintf("Do you really want to remove %q?", hostName))
			if !userinput {
				return err
			}
		}

		if loaderr == nil {
			if err := h.Driver.Remove(); err != nil {
				if !force {
					log.Errorf("Provider error removing machine %q: %s", hostName, err)
					continue
				}
			}
		}

		if err := api.Remove(hostName); err != nil {
			log.Errorf("Error removing machine %q from store: %s", hostName, err)
		} else {
			log.Infof("Successfully removed %s", hostName)
		}
	}

	return nil
}
예제 #7
0
파일: rm.go 프로젝트: MerlinDMC/machine
func cmdRm(c CommandLine, api libmachine.API) error {
	if len(c.Args()) == 0 {
		c.ShowHelp()
		return ErrNoMachineSpecified
	}

	log.Info(fmt.Sprintf("About to remove %s", strings.Join(c.Args(), ",")))

	force := c.Bool("force")
	confirm := c.Bool("y")
	var errorOccured string

	if !userConfirm(confirm, force) {
		return nil
	}

	for _, hostName := range c.Args() {
		err := removeRemoteMachine(hostName, api)
		if err != nil {
			errorOccured = fmt.Sprintf("Error removing host %q: %s", hostName, err)
			log.Errorf(errorOccured)
		}

		if err == nil || force {
			removeErr := api.Remove(hostName)
			if removeErr != nil {
				log.Errorf("Error removing machine %q from store: %s", hostName, removeErr)
			} else {
				log.Infof("Successfully removed %s", hostName)
			}
		}
	}
	if errorOccured != "" {
		return errors.New(errorOccured)
	}
	return nil
}