github.com/rothwerx/packer@v0.9.0/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  const VMWARE_FUSION_VERSION = "6"
    15  
    16  // Fusion6Driver is a driver that can run VMware Fusion 6.
    17  type Fusion6Driver struct {
    18  	Fusion5Driver
    19  }
    20  
    21  func (d *Fusion6Driver) Clone(dst, src string) error {
    22  	cmd := exec.Command(d.vmrunPath(),
    23  		"-T", "fusion",
    24  		"clone", src, dst,
    25  		"full")
    26  	if _, _, err := runAndLog(cmd); err != nil {
    27  		if strings.Contains(err.Error(), "parameters was invalid") {
    28  			return fmt.Errorf(
    29  				"Clone is not supported with your version of Fusion. Packer "+
    30  					"only works with Fusion %s Professional or above. Please verify your version.", VMWARE_FUSION_VERSION)
    31  		}
    32  
    33  		return err
    34  	}
    35  
    36  	return nil
    37  }
    38  
    39  func (d *Fusion6Driver) Verify() error {
    40  	if err := d.Fusion5Driver.Verify(); err != nil {
    41  		return err
    42  	}
    43  
    44  	vmxpath := filepath.Join(d.AppPath, "Contents", "Library", "vmware-vmx")
    45  	if _, err := os.Stat(vmxpath); err != nil {
    46  		if os.IsNotExist(err) {
    47  			return fmt.Errorf("vmware-vmx could not be found at path: %s",
    48  				vmxpath)
    49  		}
    50  
    51  		return err
    52  	}
    53  
    54  	var stderr bytes.Buffer
    55  	cmd := exec.Command(vmxpath, "-v")
    56  	cmd.Stderr = &stderr
    57  	if err := cmd.Run(); err != nil {
    58  		return err
    59  	}
    60  
    61  	versionRe := regexp.MustCompile(`(?i)VMware [a-z0-9-]+ (\d+)\.`)
    62  	matches := versionRe.FindStringSubmatch(stderr.String())
    63  	if matches == nil {
    64  		return fmt.Errorf(
    65  			"Couldn't find VMware version in output: %s", stderr.String())
    66  	}
    67  	log.Printf("Detected VMware version: %s", matches[1])
    68  
    69  	return compareVersions(matches[1], VMWARE_FUSION_VERSION, "Fusion Professional")
    70  }