2013-07-31 15:36:17 -04:00
|
|
|
// +build !windows
|
2014-03-07 13:22:33 -05:00
|
|
|
|
2014-02-20 23:20:54 -05:00
|
|
|
// These functions are compatible with WS 9 and 10 on *NIX
|
2013-12-25 17:50:12 -05:00
|
|
|
package common
|
2013-07-31 15:36:17 -04:00
|
|
|
|
|
|
|
import (
|
2014-04-06 18:31:49 -04:00
|
|
|
"bytes"
|
2013-07-31 15:36:17 -04:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2014-04-06 18:31:49 -04:00
|
|
|
"log"
|
2013-07-31 15:36:17 -04:00
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
2014-04-06 18:31:49 -04:00
|
|
|
"regexp"
|
|
|
|
"runtime"
|
2013-07-31 15:36:17 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func workstationCheckLicense() error {
|
|
|
|
matches, err := filepath.Glob("/etc/vmware/license-*")
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error looking for VMware license: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(matches) == 0 {
|
|
|
|
return errors.New("Workstation does not appear to be licensed. Please license it.")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func workstationFindVdiskManager() (string, error) {
|
|
|
|
return exec.LookPath("vmware-vdiskmanager")
|
|
|
|
}
|
|
|
|
|
|
|
|
func workstationFindVMware() (string, error) {
|
|
|
|
return exec.LookPath("vmware")
|
|
|
|
}
|
|
|
|
|
|
|
|
func workstationFindVmrun() (string, error) {
|
|
|
|
return exec.LookPath("vmrun")
|
|
|
|
}
|
|
|
|
|
|
|
|
func workstationDhcpLeasesPath(device string) string {
|
|
|
|
return "/etc/vmware/" + device + "/dhcpd/dhcpd.leases"
|
|
|
|
}
|
|
|
|
|
|
|
|
func workstationToolsIsoPath(flavor string) string {
|
|
|
|
return "/usr/lib/vmware/isoimages/" + flavor + ".iso"
|
|
|
|
}
|
2013-08-02 02:55:56 -04:00
|
|
|
|
|
|
|
func workstationVmnetnatConfPath() string {
|
|
|
|
return ""
|
|
|
|
}
|
2014-04-06 18:31:49 -04:00
|
|
|
|
|
|
|
func workstationVerifyVersion(version string) error {
|
|
|
|
if runtime.GOOS != "linux" {
|
2014-08-22 04:07:36 -04:00
|
|
|
return fmt.Errorf("The VMware WS version %s driver is only supported on Linux, and Windows, at the moment. Your OS: %s", version, runtime.GOOS)
|
2014-04-06 18:31:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//TODO(pmyjavec) there is a better way to find this, how?
|
|
|
|
//the default will suffice for now.
|
|
|
|
vmxpath := "/usr/lib/vmware/bin/vmware-vmx"
|
|
|
|
|
|
|
|
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 Workstation (\d+)\.`)
|
|
|
|
matches := versionRe.FindStringSubmatch(stderr.String())
|
|
|
|
if matches == nil {
|
|
|
|
return fmt.Errorf(
|
2014-08-22 04:07:36 -04:00
|
|
|
"Could not find VMware WS version in output: %s", stderr.String())
|
2014-04-06 18:31:49 -04:00
|
|
|
}
|
2014-08-22 04:07:36 -04:00
|
|
|
log.Printf("Detected VMware WS version: %s", matches[1])
|
2014-04-06 18:31:49 -04:00
|
|
|
|
|
|
|
return compareVersions(matches[1], version)
|
|
|
|
}
|