Exemplo n.º 1
0
func (d *Driver) Start() error {
	s, err := d.GetState()
	if err != nil {
		return err
	}

	if s == state.Stopped {
		// check network to re-create if needed
		if err := d.setupHostOnlyNetwork(d.MachineName); err != nil {
			return fmt.Errorf("Error setting up host only network on machine start: %s", err)
		}
	}

	switch s {
	case state.Stopped, state.Saved:
		d.SSHPort, err = setPortForwarding(d.MachineName, 1, "ssh", "tcp", 22, d.SSHPort)
		if err != nil {
			return err
		}
		if err := vbm("startvm", d.MachineName, "--type", "headless"); err != nil {
			return err
		}
		log.Infof("Starting VM...")
	case state.Paused:
		if err := vbm("controlvm", d.MachineName, "resume", "--type", "headless"); err != nil {
			return err
		}
		log.Infof("Resuming VM ...")
	default:
		log.Infof("VM not in restartable state")
	}

	// Wait for SSH over NAT to be available before returning to user
	if err := drivers.WaitForSSH(d); err != nil {
		return err
	}

	// Bail if we don't get an IP from DHCP after a given number of seconds.
	if err := utils.WaitForSpecific(d.hostOnlyIpAvailable, 5, 4*time.Second); err != nil {
		return err
	}

	d.IPAddress, err = d.GetIP()

	return err
}
Exemplo n.º 2
0
func (d *Driver) Remove() error {
	log.Info("Deleting...")

	if d.InstanceId == "" {
		// Instance id is empty due to some errors while creating,
		log.Warn("InstanceId is empty, assuming it has already bean removed from aliyun.")
		return nil
	}

	// If instance is running, kill it
	if st, _ := d.GetState(); st == state.Running {
		err := d.Kill()
		if err != nil {
			return err
		}
	}
	// Wait for instance to stop
	utils.WaitForSpecific(d.waitToStopInstance, 10, 6*time.Second)

	_, err := d.getClient().Instance.DeleteInstance(map[string]string{
		"InstanceId": d.InstanceId,
	})
	return err
}