github.com/sneal/packer@v0.5.2/builder/vmware/common/driver_fusion6.go (about)

     1  package common
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  	"log"
     7  	"os"
     8  	"os/exec"
     9  	"path/filepath"
    10  	"regexp"
    11  	"strings"
    12  )
    13  
    14  // Fusion6Driver is a driver that can run VMWare Fusion 5.
    15  type Fusion6Driver struct {
    16  	Fusion5Driver
    17  }
    18  
    19  func (d *Fusion6Driver) Clone(dst, src string) error {
    20  	cmd := exec.Command(d.vmrunPath(),
    21  		"-T", "fusion",
    22  		"clone", src, dst,
    23  		"full")
    24  	if _, _, err := runAndLog(cmd); err != nil {
    25  		return err
    26  	}
    27  
    28  	return nil
    29  }
    30  
    31  func (d *Fusion6Driver) Verify() error {
    32  	if err := d.Fusion5Driver.Verify(); err != nil {
    33  		return err
    34  	}
    35  
    36  	vmxpath := filepath.Join(d.AppPath, "Contents", "Library", "vmware-vmx")
    37  	if _, err := os.Stat(vmxpath); err != nil {
    38  		if os.IsNotExist(err) {
    39  			return fmt.Errorf("vmware-vmx could not be found at path: %s",
    40  				vmxpath)
    41  		}
    42  
    43  		return err
    44  	}
    45  
    46  	var stderr bytes.Buffer
    47  	cmd := exec.Command(vmxpath, "-v")
    48  	cmd.Stderr = &stderr
    49  	if err := cmd.Run(); err != nil {
    50  		return err
    51  	}
    52  
    53  	versionRe := regexp.MustCompile(`(?i)VMware [a-z0-9-]+ (\d+\.\d+\.\d+)\s`)
    54  	matches := versionRe.FindStringSubmatch(stderr.String())
    55  	if matches == nil {
    56  		return fmt.Errorf(
    57  			"Couldn't find VMware version in output: %s", stderr.String())
    58  	}
    59  	log.Printf("Detected VMware version: %s", matches[1])
    60  
    61  	if !strings.HasPrefix(matches[1], "6.") {
    62  		return fmt.Errorf(
    63  			"Fusion 6 not detected. Got version: %s", matches[1])
    64  	}
    65  
    66  	return nil
    67  }