-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
264 additions
and
326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package vmware | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
type Fusion7 struct{} | ||
|
||
func (v *Fusion7) vmrunPath() (string, error) { | ||
vmrun := os.Getenv("VMWARE_VMRUN_PATH") | ||
|
||
if vmrun != "" { | ||
return vmrun, nil | ||
} | ||
|
||
// Guess it is in the default installation path | ||
vmrun = "/Applications/VMware Fusion.app/Contents/Library/vmrun" | ||
if _, err := os.Stat(vmrun); err != nil { | ||
if os.IsNotExist(err) { | ||
return "", fmt.Errorf("VMWare vmrun not found at path: %s", vmrun) | ||
} | ||
} | ||
|
||
return vmrun, nil | ||
} | ||
|
||
func (v *Fusion7) Info(vmxfile string) (*VMInfo, error) { | ||
return nil, nil | ||
} | ||
|
||
func (v *Fusion7) SetInfo(info *VMInfo) error { | ||
return nil | ||
} | ||
|
||
func (v *Fusion7) Clone(vmxfile, dstfile string, ctype CloneType) error { | ||
return nil | ||
} | ||
|
||
func (v *Fusion7) Start(vmxfile string, gui bool) error { | ||
return nil | ||
} | ||
|
||
func (v *Fusion7) Stop(vmxfile string) error { | ||
return nil | ||
} | ||
|
||
func (v *Fusion7) Delete(vmxfile string) error { | ||
return nil | ||
} | ||
|
||
func (v *Fusion7) IsRunning(vmxfile string) (bool, error) { | ||
return false, nil | ||
} | ||
|
||
func (v *Fusion7) HasToolsInstalled(vmxfile string) (bool, error) { | ||
return false, nil | ||
} | ||
|
||
func (v *Fusion7) IPAddress(vmxfile string) (string, error) { | ||
return "", nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package vmware | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"log" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
type NetworkType string | ||
|
||
const ( | ||
NetworkHostOnly NetworkType = "hostonly" | ||
NetworkNAT NetworkType = "nat" | ||
NetworkBridged NetworkType = "bridged" | ||
) | ||
|
||
type CloneType string | ||
|
||
const ( | ||
CloneFull CloneType = "full" | ||
CloneLinked CloneType = "linked" | ||
) | ||
|
||
type NetworkAdapter struct { | ||
NetType NetworkType | ||
} | ||
|
||
type VMInfo struct { | ||
Name string | ||
Annotation string | ||
MemorySize int | ||
CPUs int | ||
NetworkAdapters []NetworkAdapter | ||
} | ||
|
||
type VMManager interface { | ||
vmrunPath() (string, error) | ||
Info(vmxfile string) (*VMInfo, error) | ||
SetInfo(info *VMInfo) error | ||
Clone(vmxfile, dstfile string, ctype CloneType) error | ||
Start(vmxfile string, gui bool) error | ||
Stop(vmxfile string) error | ||
Delete(vmxfile string) error | ||
IsRunning(vmxfile string) (bool, error) | ||
HasToolsInstalled(vmxfile string) (bool, error) | ||
IPAddress(vmxfile string) (string, error) | ||
} | ||
|
||
// Borrowed from https://github.com/mitchellh/packer/blob/master/builder/vmware/common/driver.go | ||
func runAndLog(cmd *exec.Cmd) (string, string, error) { | ||
var stdout, stderr bytes.Buffer | ||
|
||
log.Printf("Executing: %s %v", cmd.Path, cmd.Args[1:]) | ||
cmd.Stdout = &stdout | ||
cmd.Stderr = &stderr | ||
err := cmd.Run() | ||
|
||
stdoutString := strings.TrimSpace(stdout.String()) | ||
stderrString := strings.TrimSpace(stderr.String()) | ||
|
||
if _, ok := err.(*exec.ExitError); ok { | ||
message := stderrString | ||
if message == "" { | ||
message = stdoutString | ||
} | ||
|
||
err = fmt.Errorf("VMware error: %s", message) | ||
} | ||
|
||
log.Printf("stdout: %s", stdoutString) | ||
log.Printf("stderr: %s", stderrString) | ||
|
||
// Replace these for Windows, we only want to deal with Unix | ||
// style line endings. | ||
returnStdout := strings.Replace(stdout.String(), "\r\n", "\n", -1) | ||
returnStderr := strings.Replace(stderr.String(), "\r\n", "\n", -1) | ||
|
||
return returnStdout, returnStderr, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.