github.com/rothwerx/packer@v0.9.0/builder/vmware/common/driver_workstation_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  	"errors"
     9  	"fmt"
    10  	"log"
    11  	"os/exec"
    12  	"path/filepath"
    13  	"regexp"
    14  	"runtime"
    15  )
    16  
    17  func workstationCheckLicense() error {
    18  	matches, err := filepath.Glob("/etc/vmware/license-*")
    19  	if err != nil {
    20  		return fmt.Errorf("Error looking for VMware license: %s", err)
    21  	}
    22  
    23  	if len(matches) == 0 {
    24  		return errors.New("Workstation does not appear to be licensed. Please license it.")
    25  	}
    26  
    27  	return nil
    28  }
    29  
    30  func workstationFindVdiskManager() (string, error) {
    31  	return exec.LookPath("vmware-vdiskmanager")
    32  }
    33  
    34  func workstationFindVMware() (string, error) {
    35  	return exec.LookPath("vmware")
    36  }
    37  
    38  func workstationFindVmrun() (string, error) {
    39  	return exec.LookPath("vmrun")
    40  }
    41  
    42  func workstationDhcpLeasesPath(device string) string {
    43  	return "/etc/vmware/" + device + "/dhcpd/dhcpd.leases"
    44  }
    45  
    46  func workstationToolsIsoPath(flavor string) string {
    47  	return "/usr/lib/vmware/isoimages/" + flavor + ".iso"
    48  }
    49  
    50  func workstationVmnetnatConfPath() string {
    51  	return ""
    52  }
    53  
    54  func workstationVerifyVersion(version string) error {
    55  	if runtime.GOOS != "linux" {
    56  		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)
    57  	}
    58  
    59  	//TODO(pmyjavec) there is a better way to find this, how?
    60  	//the default will suffice for now.
    61  	vmxpath := "/usr/lib/vmware/bin/vmware-vmx"
    62  
    63  	var stderr bytes.Buffer
    64  	cmd := exec.Command(vmxpath, "-v")
    65  	cmd.Stderr = &stderr
    66  	if err := cmd.Run(); err != nil {
    67  		return err
    68  	}
    69  
    70  	versionRe := regexp.MustCompile(`(?i)VMware Workstation (\d+)\.`)
    71  	matches := versionRe.FindStringSubmatch(stderr.String())
    72  	if matches == nil {
    73  		return fmt.Errorf(
    74  			"Could not find VMware WS version in output: %s", stderr.String())
    75  	}
    76  	log.Printf("Detected VMware WS version: %s", matches[1])
    77  
    78  	return compareVersions(matches[1], version, "Workstation")
    79  }