func (m *Machine) GetState() driver.MachineState {
	return m.State
}
Get current state
package virtualbox
import (
	"archive/tar"
	"bufio"
	"bytes"
	"fmt"
	"io/ioutil"
	"net"
	"os"
	"path/filepath"
	"runtime"
	"strconv"
	"strings"
	"time"
	"github.com/boot2docker/boot2docker-cli/driver"
	flag "github.com/ogier/pflag"
)
type Flag int
const (
	F_acpi Flag = 1 << iota
	F_ioapic
	F_rtcuseutc
	F_cpuhotplug
	F_pae
	F_longmode
	F_hpet
	F_hwvirtex
	F_triplefaultreset
	F_nestedpaging
	F_largepages
	F_vtxvpid
	F_vtxux
	F_accelerate3d
)
type DriverCfg struct {
	VBM  string  
	VMDK string  
	shares shareSlice
}
var shareDefault string  
var (
	verbose bool  
	cfg     DriverCfg
)
func init() {
	if err := driver.Register("virtualbox", InitFunc); err != nil {
		fmt.Fprintf(os.Stderr, "Failed to initialize driver. Error : %s", err.Error())
		os.Exit(1)
	}
	if err := driver.RegisterConfig("virtualbox", ConfigFlags); err != nil {
		fmt.Fprintf(os.Stderr, "Failed to initialize driver config. Error : %s", err.Error())
		os.Exit(1)
	}
}
func InitFunc(mc *driver.MachineConfig) (driver.Machine, error) {
	verbose = mc.Verbose
	m, err := GetMachine(mc.VM)
	if err != nil && mc.Init {
		return CreateMachine(mc)
	}
	return m, err
}
type shareSlice map[string]string
const shareSliceSep = "="
func (s shareSlice) String() string {
	var ret []string
	for name, dir := range s {
		ret = append(ret, fmt.Sprintf("%s%s%s", dir, shareSliceSep, name))
	}
	return fmt.Sprintf("[%s]", strings.Join(ret, " "))
}
func (s *shareSlice) Set(shareDir string) error {
	var shareName string
	if i := strings.Index(shareDir, shareSliceSep); i >= 0 {
		shareName = shareDir[i+1:]
		shareDir = shareDir[:i]
	}
	if shareName == "" {
		shareName = strings.TrimLeft(shareDir, "/")
	}
	if *s == nil {
		*s = shareSlice{}
	}
	(*s)[shareName] = shareDir
	return nil
}
func ConfigFlags(B2D *driver.MachineConfig, flags *flag.FlagSet) error {
	flags.StringVar(&cfg.VMDK, "basevmdk", "", "Path to VMDK to use as base for persistent partition")
	cfg.VBM = "VBoxManage"
	if runtime.GOOS == "windows" {
		p := "C:\\Program Files\\Oracle\\VirtualBox"
		if t := os.Getenv("VBOX_INSTALL_PATH"); t != "" {
			p = t
		} else if t = os.Getenv("VBOX_MSI_INSTALL_PATH"); t != "" {
			p = t
		}
		cfg.VBM = filepath.Join(p, "VBoxManage.exe")
	}
	flags.StringVar(&cfg.VBM, "vbm", cfg.VBM, "path to VirtualBox management utility.")
	shareDefault = "disable"
	switch runtime.GOOS {
	case "darwin":
		shareDefault = "/Users" + shareSliceSep + "Users"
	case "windows":
		shareDefault = "C:\\Users" + shareSliceSep + "c/Users"
	}
	var defaultText string
	if shareDefault != "disable" {
		defaultText = "(defaults to '" + shareDefault + "' if no shares are specified; use 'disable' to explicitly prevent any shares from being created) "
	}
	flags.Var(&cfg.shares, "vbox-share", fmt.Sprintf("%sList of directories to share during 'up|start|boot' via VirtualBox Guest Additions, with optional labels", defaultText))
	return nil
}
func bool2string(b bool) string {
	if b {
		return "on"
	}
	return "off"
}
func (f Flag) Get(o Flag) string {
	return bool2string(f&o == o)
}
type Machine struct {
	Name       string
	UUID       string
	Iso        string
	State      driver.MachineState
	CPUs       uint
	Memory     uint  
	VRAM       uint  
	CfgFile    string
	BaseFolder string
	OSType     string
	Flag       Flag
	BootOrder  []string  
	DockerPort uint
	SSHPort    uint
	SerialFile string
}
func (m *Machine) Refresh() error {
	id := m.Name
	if id == "" {
		id = m.UUID
	}
	mm, err := GetMachine(id)
	if err != nil {
		return err
	}
	*m = *mm
	return nil
}
func (m *Machine) Start() error {
	switch m.State {
	case driver.Paused:
		return vbm("controlvm", m.Name, "resume")
	case driver.Poweroff, driver.Aborted:
		if err := m.setUpShares(); err != nil {
			return err
		}
		fallthrough
	case driver.Saved:
		return vbm("startvm", m.Name, "--type", "headless")
	}
	if err := m.Refresh(); err == nil {
		if m.State != driver.Running {
			return fmt.Errorf("Failed to start", m.Name)
		}
	}
	return nil
}
func (m *Machine) Save() error {
	switch m.State {
	case driver.Paused:
		if err := m.Start(); err != nil {
			return err
		}
	case driver.Poweroff, driver.Aborted, driver.Saved:
		return nil
	}
	return vbm("controlvm", m.Name, "savestate")
}
func (m *Machine) Pause() error {
	switch m.State {
	case driver.Paused, driver.Poweroff, driver.Aborted, driver.Saved:
		return nil
	}
	return vbm("controlvm", m.Name, "pause")
}
func (m *Machine) Stop() error {
	switch m.State {
	case driver.Poweroff, driver.Aborted, driver.Saved:
		return nil
	case driver.Paused:
		if err := m.Start(); err != nil {
			return err
		}
	}
	for i := 0; i < 10; i++ {
		if err := vbm("controlvm", m.Name, "acpipowerbutton"); err != nil {
			return err
		}
		time.Sleep(1 * time.Second)
		if err := m.Refresh(); err != nil {
			return err
		}
		if m.State == driver.Poweroff {
			return nil
		}
	}
	return fmt.Errorf("timed out waiting for VM to stop")
}
func (m *Machine) Poweroff() error {
	switch m.State {
	case driver.Poweroff, driver.Aborted, driver.Saved:
		return nil
	}
	return vbm("controlvm", m.Name, "poweroff")
}
func (m *Machine) Restart() error {
	switch m.State {
	case driver.Paused, driver.Saved:
		if err := m.Start(); err != nil {
			return err
		}
	}
	if err := m.Stop(); err != nil {
		return err
	}
	return m.Start()
}
func (m *Machine) Reset() error {
	switch m.State {
	case driver.Paused, driver.Saved:
		if err := m.Start(); err != nil {
			return err
		}
	}
	return vbm("controlvm", m.Name, "reset")
}
func (m *Machine) Delete() error {
	if err := m.Poweroff(); err != nil {
		return err
	}
	return vbm("unregistervm", m.Name, "--delete")
}
func (m *Machine) GetName() string {
	return m.Name
}