Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
56c383cf
Commit
56c383cf
authored
Jul 27, 2013
by
Ross Smith II
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gofmt fixes, improved/added log messages, fixes #221/#222
parent
071a6099
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
59 deletions
+71
-59
builder/vmware/driver_workstation9_windows.go
builder/vmware/driver_workstation9_windows.go
+48
-45
builder/vmware/guest_ip.go
builder/vmware/guest_ip.go
+1
-1
builder/vmware/host_ip_windows.go
builder/vmware/host_ip_windows.go
+22
-13
No files found.
builder/vmware/driver_workstation9_windows.go
View file @
56c383cf
...
...
@@ -11,8 +11,8 @@ import (
"os/exec"
"path/filepath"
"strings"
"syscall"
"unsafe"
"syscall"
)
// Workstation9Driver is a driver that can run VMware Workstation 9
...
...
@@ -104,16 +104,16 @@ func (d *Workstation9Driver) Verify() error {
}
// Check to see if it APPEARS to be licensed.
/*
matches, err := filepath.Glob("/etc/vmware/license-*")
if err != nil {
return fmt.Errorf("Error looking for VMware license: %s", err)
}
/*
matches, err := filepath.Glob("/etc/vmware/license-*")
if err != nil {
return fmt.Errorf("Error looking for VMware license: %s", err)
}
if len(matches) == 0 {
return errors.New("Workstation does not appear to be licensed. Please license it.")
}
*/
if len(matches) == 0 {
return errors.New("Workstation does not appear to be licensed. Please license it.")
}
*/
return
nil
}
...
...
@@ -126,6 +126,7 @@ func (d *Workstation9Driver) findApp() error {
}
path
+=
"vmware.exe"
}
path
=
strings
.
Replace
(
path
,
"
\\
"
,
"/"
,
-
1
)
log
.
Printf
(
"Using '%s' for vmware path"
,
path
)
d
.
AppPath
=
path
...
...
@@ -141,6 +142,7 @@ func (d *Workstation9Driver) findVdiskManager() error {
}
path
+=
"vmware-vdiskmanager.exe"
}
path
=
strings
.
Replace
(
path
,
"
\\
"
,
"/"
,
-
1
)
log
.
Printf
(
"Using '%s' for vmware-vdiskmanager path"
,
path
)
d
.
VdiskManagerPath
=
path
return
nil
...
...
@@ -155,6 +157,7 @@ func (d *Workstation9Driver) findVmrun() error {
}
path
+=
"vmrun.exe"
}
path
=
strings
.
Replace
(
path
,
"
\\
"
,
"/"
,
-
1
)
log
.
Printf
(
"Using '%s' for vmrun path"
,
path
)
d
.
VmrunPath
=
path
return
nil
...
...
@@ -203,41 +206,41 @@ func (d *Workstation9Driver) runAndLog(cmd *exec.Cmd) (string, string, error) {
// see http://blog.natefinch.com/2012/11/go-win-stuff.html
func
readRegString
(
hive
syscall
.
Handle
,
subKeyPath
,
valueName
string
)
(
value
string
,
err
error
)
{
var
h
syscall
.
Handle
err
=
syscall
.
RegOpenKeyEx
(
hive
,
syscall
.
StringToUTF16Ptr
(
subKeyPath
),
0
,
syscall
.
KEY_READ
,
&
h
)
if
err
!=
nil
{
return
}
defer
syscall
.
RegCloseKey
(
h
)
var
typ
uint32
var
bufSize
uint32
err
=
syscall
.
RegQueryValueEx
(
h
,
syscall
.
StringToUTF16Ptr
(
valueName
),
nil
,
&
typ
,
nil
,
&
bufSize
)
if
err
!=
nil
{
return
}
data
:=
make
([]
uint16
,
bufSize
/
2
+
1
)
err
=
syscall
.
RegQueryValueEx
(
h
,
syscall
.
StringToUTF16Ptr
(
valueName
),
nil
,
&
typ
,
(
*
byte
)(
unsafe
.
Pointer
(
&
data
[
0
])),
&
bufSize
)
if
err
!=
nil
{
return
}
return
syscall
.
UTF16ToString
(
data
),
nil
var
h
syscall
.
Handle
err
=
syscall
.
RegOpenKeyEx
(
hive
,
syscall
.
StringToUTF16Ptr
(
subKeyPath
),
0
,
syscall
.
KEY_READ
,
&
h
)
if
err
!=
nil
{
return
}
defer
syscall
.
RegCloseKey
(
h
)
var
typ
uint32
var
bufSize
uint32
err
=
syscall
.
RegQueryValueEx
(
h
,
syscall
.
StringToUTF16Ptr
(
valueName
),
nil
,
&
typ
,
nil
,
&
bufSize
)
if
err
!=
nil
{
return
}
data
:=
make
([]
uint16
,
bufSize
/
2
+
1
)
err
=
syscall
.
RegQueryValueEx
(
h
,
syscall
.
StringToUTF16Ptr
(
valueName
),
nil
,
&
typ
,
(
*
byte
)(
unsafe
.
Pointer
(
&
data
[
0
])),
&
bufSize
)
if
err
!=
nil
{
return
}
return
syscall
.
UTF16ToString
(
data
),
nil
}
func
getVmwarePath
()
(
s
string
,
e
error
)
{
...
...
builder/vmware/guest_ip.go
View file @
56c383cf
...
...
@@ -51,7 +51,7 @@ func (f *DHCPLeaseGuestLookup) GuestIP() (string, error) {
for
_
,
line
:=
range
strings
.
Split
(
string
(
dhcpBytes
),
"
\n
"
)
{
// Need to trim off CR character when running in windows
line
=
strings
.
TrimRight
(
line
,
"
\r
"
)
;
line
=
strings
.
TrimRight
(
line
,
"
\r
"
)
matches
:=
ipLineRe
.
FindStringSubmatch
(
line
)
if
matches
!=
nil
{
...
...
builder/vmware/host_ip_windows.go
View file @
56c383cf
...
...
@@ -5,12 +5,12 @@ package vmware
import
(
"errors"
"
regexp
"
"
io/ioutil
"
"log"
"strings"
"net"
"os"
"io/ioutil"
"regexp"
"strings"
)
// Interface to help find the host IP that is available from within
...
...
@@ -38,12 +38,13 @@ func (f *IfconfigIPFinder) HostIP() (string, error) {
log
.
Printf
(
"Searching for MAC %s"
,
vmwareMac
)
re
:=
regexp
.
MustCompile
(
"(?i)^"
+
vmwareMac
)
var
rv
string
ip
:=
""
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
{
continue
...
...
@@ -51,23 +52,25 @@ func (f *IfconfigIPFinder) HostIP() (string, error) {
addrs
,
err
:=
ifi
.
Addrs
()
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
}
for
_
,
address
:=
range
addrs
{
rv
=
address
.
String
()
log
.
Printf
(
"Found
VMWare IP address %s"
,
address
.
String
()
)
ip
=
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)
}
if
rv
>
""
{
return
rv
,
nil
if
ip
==
""
{
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
)
{
...
...
@@ -75,12 +78,15 @@ func getVMWareMAC() (string, error) {
const
defaultMacRe
=
"00:50:56"
programData
:=
os
.
Getenv
(
"ProgramData"
)
programData
=
strings
.
Replace
(
programData
,
"
\\
"
,
"/"
,
-
1
)
vmnetnat
:=
programData
+
"/VMware/vmnetnat.conf"
if
_
,
err
:=
os
.
Stat
(
vmnetnat
);
os
.
IsNotExist
(
err
)
{
log
.
Printf
(
"File not found: '%s' (found '%s' in %%ProgramData%%)"
,
vmnetnat
,
programData
)
return
defaultMacRe
,
err
}
log
.
Printf
(
"Searching for key hostMAC in '%s'"
,
vmnetnat
)
fh
,
err
:=
os
.
Open
(
vmnetnat
)
if
err
!=
nil
{
return
defaultMacRe
,
err
...
...
@@ -96,14 +102,17 @@ func getVMWareMAC() (string, error) {
for
_
,
line
:=
range
strings
.
Split
(
string
(
bytes
),
"
\n
"
)
{
// Need to trim off CR character when running in windows
line
=
strings
.
TrimRight
(
line
,
"
\r
"
)
;
line
=
strings
.
TrimRight
(
line
,
"
\r
"
)
matches
:=
hostMacRe
.
FindStringSubmatch
(
line
)
if
matches
!=
nil
{
log
.
Printf
(
"Found MAC '%s' in '%s'"
,
matches
[
1
],
vmnetnat
)
return
matches
[
1
],
nil
}
}
log
.
Printf
(
"Did not find key hostMAC in '%s', using %s instead"
,
vmnetnat
,
defaultMacRe
)
return
defaultMacRe
,
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment