github.com/rothwerx/packer@v0.9.0/builder/vmware/common/driver_player_unix.go (about)

     1  // +build !windows
     2  
     3  // These functions are compatible with WS 9 and 10 on *NIX
     4  package common
     5  
     6  import (
     7  	"bytes"
     8  	"fmt"
     9  	"log"
    10  	"os/exec"
    11  	"regexp"
    12  	"runtime"
    13  )
    14  
    15  func playerFindVdiskManager() (string, error) {
    16  	return exec.LookPath("vmware-vdiskmanager")
    17  }
    18  
    19  func playerFindQemuImg() (string, error) {
    20  	return exec.LookPath("qemu-img")
    21  }
    22  
    23  func playerFindVMware() (string, error) {
    24  	return exec.LookPath("vmplayer")
    25  }
    26  
    27  func playerFindVmrun() (string, error) {
    28  	return exec.LookPath("vmrun")
    29  }
    30  
    31  func playerDhcpLeasesPath(device string) string {
    32  	return "/etc/vmware/" + device + "/dhcpd/dhcpd.leases"
    33  }
    34  
    35  func playerToolsIsoPath(flavor string) string {
    36  	return "/usr/lib/vmware/isoimages/" + flavor + ".iso"
    37  }
    38  
    39  func playerVmnetnatConfPath() string {
    40  	return ""
    41  }
    42  
    43  func playerVerifyVersion(version string) error {
    44  	if runtime.GOOS != "linux" {
    45  		return fmt.Errorf("The VMWare Player version %s driver is only supported on Linux, and Windows, at the moment. Your OS: %s", version, runtime.GOOS)
    46  	}
    47  
    48  	//TODO(pmyjavec) there is a better way to find this, how?
    49  	//the default will suffice for now.
    50  	vmxpath := "/usr/lib/vmware/bin/vmware-vmx"
    51  
    52  	var stderr bytes.Buffer
    53  	cmd := exec.Command(vmxpath, "-v")
    54  	cmd.Stderr = &stderr
    55  	if err := cmd.Run(); err != nil {
    56  		return err
    57  	}
    58  
    59  	versionRe := regexp.MustCompile(`(?i)VMware Player (\d+)\.`)
    60  	matches := versionRe.FindStringSubmatch(stderr.String())
    61  	if matches == nil {
    62  		return fmt.Errorf(
    63  			"Could not find VMWare Player version in output: %s", stderr.String())
    64  	}
    65  	log.Printf("Detected VMWare Player version: %s", matches[1])
    66  
    67  	return compareVersions(matches[1], version, "Player")
    68  }