Commit 56c383cf authored by Ross Smith II's avatar Ross Smith II

gofmt fixes, improved/added log messages, fixes #221/#222

parent 071a6099
...@@ -11,8 +11,8 @@ import ( ...@@ -11,8 +11,8 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
"unsafe"
"syscall" "syscall"
"unsafe"
) )
// Workstation9Driver is a driver that can run VMware Workstation 9 // Workstation9Driver is a driver that can run VMware Workstation 9
...@@ -104,7 +104,7 @@ func (d *Workstation9Driver) Verify() error { ...@@ -104,7 +104,7 @@ func (d *Workstation9Driver) Verify() error {
} }
// Check to see if it APPEARS to be licensed. // Check to see if it APPEARS to be licensed.
/* /*
matches, err := filepath.Glob("/etc/vmware/license-*") matches, err := filepath.Glob("/etc/vmware/license-*")
if err != nil { if err != nil {
return fmt.Errorf("Error looking for VMware license: %s", err) return fmt.Errorf("Error looking for VMware license: %s", err)
...@@ -113,7 +113,7 @@ func (d *Workstation9Driver) Verify() error { ...@@ -113,7 +113,7 @@ func (d *Workstation9Driver) Verify() error {
if len(matches) == 0 { if len(matches) == 0 {
return errors.New("Workstation does not appear to be licensed. Please license it.") return errors.New("Workstation does not appear to be licensed. Please license it.")
} }
*/ */
return nil return nil
} }
...@@ -126,6 +126,7 @@ func (d *Workstation9Driver) findApp() error { ...@@ -126,6 +126,7 @@ func (d *Workstation9Driver) findApp() error {
} }
path += "vmware.exe" path += "vmware.exe"
} }
path = strings.Replace(path, "\\", "/", -1)
log.Printf("Using '%s' for vmware path", path) log.Printf("Using '%s' for vmware path", path)
d.AppPath = path d.AppPath = path
...@@ -141,6 +142,7 @@ func (d *Workstation9Driver) findVdiskManager() error { ...@@ -141,6 +142,7 @@ func (d *Workstation9Driver) findVdiskManager() error {
} }
path += "vmware-vdiskmanager.exe" path += "vmware-vdiskmanager.exe"
} }
path = strings.Replace(path, "\\", "/", -1)
log.Printf("Using '%s' for vmware-vdiskmanager path", path) log.Printf("Using '%s' for vmware-vdiskmanager path", path)
d.VdiskManagerPath = path d.VdiskManagerPath = path
return nil return nil
...@@ -155,6 +157,7 @@ func (d *Workstation9Driver) findVmrun() error { ...@@ -155,6 +157,7 @@ func (d *Workstation9Driver) findVmrun() error {
} }
path += "vmrun.exe" path += "vmrun.exe"
} }
path = strings.Replace(path, "\\", "/", -1)
log.Printf("Using '%s' for vmrun path", path) log.Printf("Using '%s' for vmrun path", path)
d.VmrunPath = path d.VmrunPath = path
return nil return nil
......
...@@ -51,7 +51,7 @@ func (f *DHCPLeaseGuestLookup) GuestIP() (string, error) { ...@@ -51,7 +51,7 @@ func (f *DHCPLeaseGuestLookup) GuestIP() (string, error) {
for _, line := range strings.Split(string(dhcpBytes), "\n") { for _, line := range strings.Split(string(dhcpBytes), "\n") {
// Need to trim off CR character when running in windows // Need to trim off CR character when running in windows
line = strings.TrimRight(line, "\r"); line = strings.TrimRight(line, "\r")
matches := ipLineRe.FindStringSubmatch(line) matches := ipLineRe.FindStringSubmatch(line)
if matches != nil { if matches != nil {
......
...@@ -5,12 +5,12 @@ package vmware ...@@ -5,12 +5,12 @@ package vmware
import ( import (
"errors" "errors"
"regexp" "io/ioutil"
"log" "log"
"strings"
"net" "net"
"os" "os"
"io/ioutil" "regexp"
"strings"
) )
// Interface to help find the host IP that is available from within // Interface to help find the host IP that is available from within
...@@ -38,12 +38,13 @@ func (f *IfconfigIPFinder) HostIP() (string, error) { ...@@ -38,12 +38,13 @@ func (f *IfconfigIPFinder) HostIP() (string, error) {
log.Printf("Searching for MAC %s", vmwareMac) log.Printf("Searching for MAC %s", vmwareMac)
re := regexp.MustCompile("(?i)^" + vmwareMac) re := regexp.MustCompile("(?i)^" + vmwareMac)
var rv string ip := ""
for _, ifi := range ift { for _, ifi := range ift {
log.Printf("Found interface %s", ifi.HardwareAddr.String()) mac := ifi.HardwareAddr.String()
log.Printf("Found MAC %s", mac)
matches := re.FindStringSubmatch(ifi.HardwareAddr.String()) matches := re.FindStringSubmatch(mac)
if matches == nil { if matches == nil {
continue continue
...@@ -51,23 +52,25 @@ func (f *IfconfigIPFinder) HostIP() (string, error) { ...@@ -51,23 +52,25 @@ func (f *IfconfigIPFinder) HostIP() (string, error) {
addrs, err := ifi.Addrs() addrs, err := ifi.Addrs()
if err != nil { if err != nil {
log.Printf("No IP addresses found for %s", ifi.HardwareAddr.String()) log.Printf("No IP addresses found for MAC %s", mac)
continue continue
} }
for _, address := range addrs { for _, address := range addrs {
rv = address.String() ip = address.String()
log.Printf("Found VMWare IP address %s", address.String()) log.Printf("Found IP address %s for MAC %s", ip, mac)
} }
// continue looping as VMNet8 comes after VMNet1 (at least on my system) // continue looping as VMNet8 comes after VMNet1 (at least on my system)
} }
if rv > "" { if ip == "" {
return rv, nil return "", errors.New("No MACs found matching " + vmwareMac)
} }
return "", errors.New("No VMWare MAC addresses found") log.Printf("Returning IP address %s", ip)
return ip, nil
} }
func getVMWareMAC() (string, error) { func getVMWareMAC() (string, error) {
...@@ -75,12 +78,15 @@ func getVMWareMAC() (string, error) { ...@@ -75,12 +78,15 @@ func getVMWareMAC() (string, error) {
const defaultMacRe = "00:50:56" const defaultMacRe = "00:50:56"
programData := os.Getenv("ProgramData") programData := os.Getenv("ProgramData")
programData = strings.Replace(programData, "\\", "/", -1)
vmnetnat := programData + "/VMware/vmnetnat.conf" vmnetnat := programData + "/VMware/vmnetnat.conf"
if _, err := os.Stat(vmnetnat); os.IsNotExist(err) { if _, err := os.Stat(vmnetnat); os.IsNotExist(err) {
log.Printf("File not found: '%s' (found '%s' in %%ProgramData%%)", vmnetnat, programData) log.Printf("File not found: '%s' (found '%s' in %%ProgramData%%)", vmnetnat, programData)
return defaultMacRe, err return defaultMacRe, err
} }
log.Printf("Searching for key hostMAC in '%s'", vmnetnat)
fh, err := os.Open(vmnetnat) fh, err := os.Open(vmnetnat)
if err != nil { if err != nil {
return defaultMacRe, err return defaultMacRe, err
...@@ -96,14 +102,17 @@ func getVMWareMAC() (string, error) { ...@@ -96,14 +102,17 @@ func getVMWareMAC() (string, error) {
for _, line := range strings.Split(string(bytes), "\n") { for _, line := range strings.Split(string(bytes), "\n") {
// Need to trim off CR character when running in windows // Need to trim off CR character when running in windows
line = strings.TrimRight(line, "\r"); line = strings.TrimRight(line, "\r")
matches := hostMacRe.FindStringSubmatch(line) matches := hostMacRe.FindStringSubmatch(line)
if matches != nil { if matches != nil {
log.Printf("Found MAC '%s' in '%s'", matches[1], vmnetnat)
return matches[1], nil return matches[1], nil
} }
} }
log.Printf("Did not find key hostMAC in '%s', using %s instead", vmnetnat, defaultMacRe)
return defaultMacRe, nil return defaultMacRe, nil
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment