github.com/sneal/packer@v0.5.2/builder/vmware/common/driver_workstation9.go (about) 1 package common 2 3 import ( 4 "errors" 5 "fmt" 6 "log" 7 "os" 8 "os/exec" 9 "path/filepath" 10 "strings" 11 12 "github.com/mitchellh/multistep" 13 ) 14 15 // Workstation9Driver is a driver that can run VMware Workstation 9 16 // on non-Windows platforms. 17 type Workstation9Driver struct { 18 AppPath string 19 VdiskManagerPath string 20 VmrunPath string 21 22 // SSHConfig are the SSH settings for the Fusion VM 23 SSHConfig *SSHConfig 24 } 25 26 func (d *Workstation9Driver) Clone(dst, src string) error { 27 return errors.New("Cloning is not supported with WS 9. Please use WS 10+.") 28 } 29 30 func (d *Workstation9Driver) CompactDisk(diskPath string) error { 31 defragCmd := exec.Command(d.VdiskManagerPath, "-d", diskPath) 32 if _, _, err := runAndLog(defragCmd); err != nil { 33 return err 34 } 35 36 shrinkCmd := exec.Command(d.VdiskManagerPath, "-k", diskPath) 37 if _, _, err := runAndLog(shrinkCmd); err != nil { 38 return err 39 } 40 41 return nil 42 } 43 44 func (d *Workstation9Driver) CreateDisk(output string, size string, type_id string) error { 45 cmd := exec.Command(d.VdiskManagerPath, "-c", "-s", size, "-a", "lsilogic", "-t", type_id, output) 46 if _, _, err := runAndLog(cmd); err != nil { 47 return err 48 } 49 50 return nil 51 } 52 53 func (d *Workstation9Driver) IsRunning(vmxPath string) (bool, error) { 54 vmxPath, err := filepath.Abs(vmxPath) 55 if err != nil { 56 return false, err 57 } 58 59 cmd := exec.Command(d.VmrunPath, "-T", "ws", "list") 60 stdout, _, err := runAndLog(cmd) 61 if err != nil { 62 return false, err 63 } 64 65 for _, line := range strings.Split(stdout, "\n") { 66 if line == vmxPath { 67 return true, nil 68 } 69 } 70 71 return false, nil 72 } 73 74 func (d *Workstation9Driver) SSHAddress(state multistep.StateBag) (string, error) { 75 return SSHAddressFunc(d.SSHConfig)(state) 76 } 77 78 func (d *Workstation9Driver) Start(vmxPath string, headless bool) error { 79 guiArgument := "gui" 80 if headless { 81 guiArgument = "nogui" 82 } 83 84 cmd := exec.Command(d.VmrunPath, "-T", "ws", "start", vmxPath, guiArgument) 85 if _, _, err := runAndLog(cmd); err != nil { 86 return err 87 } 88 89 return nil 90 } 91 92 func (d *Workstation9Driver) Stop(vmxPath string) error { 93 cmd := exec.Command(d.VmrunPath, "-T", "ws", "stop", vmxPath, "hard") 94 if _, _, err := runAndLog(cmd); err != nil { 95 return err 96 } 97 98 return nil 99 } 100 101 func (d *Workstation9Driver) SuppressMessages(vmxPath string) error { 102 return nil 103 } 104 105 func (d *Workstation9Driver) Verify() error { 106 var err error 107 if d.AppPath == "" { 108 if d.AppPath, err = workstationFindVMware(); err != nil { 109 return err 110 } 111 } 112 113 if d.VmrunPath == "" { 114 if d.VmrunPath, err = workstationFindVmrun(); err != nil { 115 return err 116 } 117 } 118 119 if d.VdiskManagerPath == "" { 120 if d.VdiskManagerPath, err = workstationFindVdiskManager(); err != nil { 121 return err 122 } 123 } 124 125 log.Printf("VMware app path: %s", d.AppPath) 126 log.Printf("vmrun path: %s", d.VmrunPath) 127 log.Printf("vdisk-manager path: %s", d.VdiskManagerPath) 128 129 if _, err := os.Stat(d.AppPath); err != nil { 130 return fmt.Errorf("VMware application not found: %s", d.AppPath) 131 } 132 133 if _, err := os.Stat(d.VmrunPath); err != nil { 134 return fmt.Errorf("'vmrun' application not found: %s", d.VmrunPath) 135 } 136 137 if _, err := os.Stat(d.VdiskManagerPath); err != nil { 138 return fmt.Errorf("'vmrun' application not found: %s", d.VdiskManagerPath) 139 } 140 141 // Check to see if it APPEARS to be licensed. 142 if err := workstationCheckLicense(); err != nil { 143 return err 144 } 145 146 return nil 147 } 148 149 func (d *Workstation9Driver) ToolsIsoPath(flavor string) string { 150 return workstationToolsIsoPath(flavor) 151 } 152 153 func (d *Workstation9Driver) DhcpLeasesPath(device string) string { 154 return workstationDhcpLeasesPath(device) 155 } 156 157 func (d *Workstation9Driver) VmnetnatConfPath() string { 158 return workstationVmnetnatConfPath() 159 }