From 8fecdf179da38f140e53fbb193f58acca7f435d1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 26 Dec 2013 14:54:26 -0700 Subject: [PATCH] builder/vmware/common: Fusion6Driver --- builder/vmware/common/driver.go | 6 +++ builder/vmware/common/driver_fusion6.go | 60 +++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 builder/vmware/common/driver_fusion6.go diff --git a/builder/vmware/common/driver.go b/builder/vmware/common/driver.go index 992d0939c..aee7997e1 100644 --- a/builder/vmware/common/driver.go +++ b/builder/vmware/common/driver.go @@ -62,6 +62,12 @@ func NewDriver(config *SSHConfig) (Driver, error) { switch runtime.GOOS { case "darwin": drivers = []Driver{ + &Fusion6Driver{ + Fusion5Driver: Fusion5Driver{ + AppPath: "/Applications/VMware Fusion.app", + SSHConfig: config, + }, + }, &Fusion5Driver{ AppPath: "/Applications/VMware Fusion.app", SSHConfig: config, diff --git a/builder/vmware/common/driver_fusion6.go b/builder/vmware/common/driver_fusion6.go new file mode 100644 index 000000000..0bb49e17f --- /dev/null +++ b/builder/vmware/common/driver_fusion6.go @@ -0,0 +1,60 @@ +package common + +import ( + "bytes" + "errors" + "fmt" + "log" + "os" + "os/exec" + "path/filepath" + "regexp" + "strings" +) + +// Fusion6Driver is a driver that can run VMWare Fusion 5. +type Fusion6Driver struct { + Fusion5Driver +} + +func (d *Fusion6Driver) Clone(dst, src string) error { + return errors.New("Cloning is not supported with Fusion 5. Please use Fusion 6+.") +} + +func (d *Fusion6Driver) Verify() error { + if err := d.Fusion5Driver.Verify(); err != nil { + return err + } + + vmxpath := filepath.Join(d.AppPath, "Contents", "Library", "vmware-vmx") + if _, err := os.Stat(vmxpath); err != nil { + if os.IsNotExist(err) { + return fmt.Errorf("vmware-vmx could not be found at path: %s", + vmxpath) + } + + return err + } + + var stderr bytes.Buffer + cmd := exec.Command(vmxpath, "-v") + cmd.Stderr = &stderr + if err := cmd.Run(); err != nil { + return err + } + + versionRe := regexp.MustCompile(`(?i)VMware [a-z0-9-]+ (\d+\.\d+\.\d+)\s`) + matches := versionRe.FindStringSubmatch(stderr.String()) + if matches == nil { + return fmt.Errorf( + "Couldn't find VMware version in output: %s", stderr.String()) + } + log.Printf("Detected VMware version: %s", matches[1]) + + if !strings.HasPrefix(matches[1], "6.") { + return fmt.Errorf( + "Fusion 6 not detected. Got version: %s", matches[1]) + } + + return nil +}