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 := mcnutils.WaitForSpecific(d.hostOnlyIpAvailable, 5, 4*time.Second); err != nil { return err } d.IPAddress, err = d.GetIP() return err }
func WaitForSSH(h *Host) error { return drivers.WaitForSSH(h.Driver) }