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
1286f735
Commit
1286f735
authored
Jul 31, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: redo host IP stuff for Windows
parent
7bdb0c96
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
120 additions
and
155 deletions
+120
-155
builder/vmware/host_ip.go
builder/vmware/host_ip.go
+0
-36
builder/vmware/host_ip_ifconfig.go
builder/vmware/host_ip_ifconfig.go
+37
-0
builder/vmware/host_ip_ifconfig_test.go
builder/vmware/host_ip_ifconfig_test.go
+0
-0
builder/vmware/host_ip_vmnetnatconf.go
builder/vmware/host_ip_vmnetnatconf.go
+64
-0
builder/vmware/host_ip_vmnetnatconf_test.go
builder/vmware/host_ip_vmnetnatconf_test.go
+11
-0
builder/vmware/host_ip_windows.go
builder/vmware/host_ip_windows.go
+0
-118
builder/vmware/step_type_boot_command.go
builder/vmware/step_type_boot_command.go
+8
-1
No files found.
builder/vmware/host_ip.go
View file @
1286f735
...
...
@@ -2,44 +2,8 @@
package
vmware
import
(
"bytes"
"errors"
"os/exec"
"regexp"
)
// Interface to help find the host IP that is available from within
// the VMware virtual machines.
type
HostIPFinder
interface
{
HostIP
()
(
string
,
error
)
}
// IfconfigIPFinder finds the host IP based on the output of `ifconfig`.
type
IfconfigIPFinder
struct
{
Device
string
}
func
(
f
*
IfconfigIPFinder
)
HostIP
()
(
string
,
error
)
{
ifconfigPath
,
err
:=
exec
.
LookPath
(
"ifconfig"
)
if
err
!=
nil
{
return
""
,
err
}
stdout
:=
new
(
bytes
.
Buffer
)
cmd
:=
exec
.
Command
(
ifconfigPath
,
f
.
Device
)
cmd
.
Stdout
=
stdout
cmd
.
Stderr
=
new
(
bytes
.
Buffer
)
if
err
:=
cmd
.
Run
();
err
!=
nil
{
return
""
,
err
}
re
:=
regexp
.
MustCompile
(
`inet\s*(?:addr:)?(.+?)\s`
)
matches
:=
re
.
FindStringSubmatch
(
stdout
.
String
())
if
matches
==
nil
{
return
""
,
errors
.
New
(
"IP not found in ifconfig output..."
)
}
return
matches
[
1
],
nil
}
builder/vmware/host_ip_ifconfig.go
0 → 100644
View file @
1286f735
package
vmware
import
(
"bytes"
"errors"
"os/exec"
"regexp"
)
// IfconfigIPFinder finds the host IP based on the output of `ifconfig`.
type
IfconfigIPFinder
struct
{
Device
string
}
func
(
f
*
IfconfigIPFinder
)
HostIP
()
(
string
,
error
)
{
ifconfigPath
,
err
:=
exec
.
LookPath
(
"ifconfig"
)
if
err
!=
nil
{
return
""
,
err
}
stdout
:=
new
(
bytes
.
Buffer
)
cmd
:=
exec
.
Command
(
ifconfigPath
,
f
.
Device
)
cmd
.
Stdout
=
stdout
cmd
.
Stderr
=
new
(
bytes
.
Buffer
)
if
err
:=
cmd
.
Run
();
err
!=
nil
{
return
""
,
err
}
re
:=
regexp
.
MustCompile
(
`inet\s*(?:addr:)?(.+?)\s`
)
matches
:=
re
.
FindStringSubmatch
(
stdout
.
String
())
if
matches
==
nil
{
return
""
,
errors
.
New
(
"IP not found in ifconfig output..."
)
}
return
matches
[
1
],
nil
}
builder/vmware/host_ip_test.go
→
builder/vmware/host_ip_
ifconfig_
test.go
View file @
1286f735
File moved
builder/vmware/host_ip_vmnetnatconf.go
0 → 100644
View file @
1286f735
package
vmware
import
(
"bufio"
"errors"
"fmt"
"io"
"os"
"path/filepath"
"regexp"
"strings"
)
// VMnetNatConfIPFinder finds the IP address of the host machine by
// retrieving the IP from the vmnetnat.conf. This isn't a full proof
// technique but so far it has not failed.
type
VMnetNatConfIPFinder
struct
{}
func
(
*
VMnetNatConfIPFinder
)
HostIP
()
(
string
,
error
)
{
programData
:=
os
.
Getenv
(
"ProgramData"
)
if
programData
==
""
{
return
""
,
errors
.
New
(
"ProgramData directory not found."
)
}
programData
=
strings
.
Replace
(
programData
,
"
\\
"
,
"/"
,
-
1
)
vmnetnat
:=
filepath
.
Join
(
programData
,
"/VMware/vmnetnat.conf"
)
if
_
,
err
:=
os
.
Stat
(
vmnetnat
);
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"Error with vmnetnat.conf: %s"
,
err
)
}
f
,
err
:=
os
.
Open
(
vmnetnat
)
if
err
!=
nil
{
return
""
,
err
}
defer
f
.
Close
()
ipRe
:=
regexp
.
MustCompile
(
`^\s*ip\s*=\s*(.+?)\s*$`
)
r
:=
bufio
.
NewReader
(
f
)
for
{
line
,
err
:=
r
.
ReadString
(
'\n'
)
if
line
!=
""
{
matches
:=
ipRe
.
FindStringSubmatch
(
line
)
if
matches
!=
nil
{
ip
:=
matches
[
1
]
dotIndex
:=
strings
.
LastIndex
(
ip
,
"."
)
if
dotIndex
==
-
1
{
continue
}
ip
=
ip
[
0
:
dotIndex
]
+
".1"
return
ip
,
nil
}
}
if
err
==
io
.
EOF
{
break
}
return
""
,
err
}
return
""
,
errors
.
New
(
"host IP not found in NAT config"
)
}
builder/vmware/host_ip_vmnetnatconf_test.go
0 → 100644
View file @
1286f735
package
vmware
import
"testing"
func
TestVMnetNatConfIPFinder_Impl
(
t
*
testing
.
T
)
{
var
raw
interface
{}
raw
=
&
VMnetNatConfIPFinder
{}
if
_
,
ok
:=
raw
.
(
HostIPFinder
);
!
ok
{
t
.
Fatalf
(
"VMnetNatConfIPFinder is not a host IP finder"
)
}
}
builder/vmware/host_ip_windows.go
deleted
100644 → 0
View file @
7bdb0c96
// +build windows
// Contributed by Ross Smith II (smithii.com)
package
vmware
import
(
"errors"
"io/ioutil"
"log"
"net"
"os"
"regexp"
"strings"
)
// Interface to help find the host IP that is available from within
// the VMware virtual machines.
type
HostIPFinder
interface
{
HostIP
()
(
string
,
error
)
}
// IfconfigIPFinder finds the host IP based on the output of `ifconfig`.
type
IfconfigIPFinder
struct
{
Device
string
}
func
(
f
*
IfconfigIPFinder
)
HostIP
()
(
string
,
error
)
{
ift
,
err
:=
net
.
Interfaces
()
if
err
!=
nil
{
return
""
,
errors
.
New
(
"No network interfaces found"
)
}
vmwareMac
,
err
:=
getVMWareMAC
()
if
err
!=
nil
{
log
.
Print
(
err
)
}
log
.
Printf
(
"Searching for MAC %s"
,
vmwareMac
)
re
:=
regexp
.
MustCompile
(
"(?i)^"
+
vmwareMac
)
ip
:=
""
for
_
,
ifi
:=
range
ift
{
mac
:=
ifi
.
HardwareAddr
.
String
()
log
.
Printf
(
"Found MAC %s"
,
mac
)
matches
:=
re
.
FindStringSubmatch
(
mac
)
if
matches
==
nil
{
continue
}
addrs
,
err
:=
ifi
.
Addrs
()
if
err
!=
nil
{
log
.
Printf
(
"No IP addresses found for MAC %s"
,
mac
)
continue
}
for
_
,
address
:=
range
addrs
{
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
ip
==
""
{
return
""
,
errors
.
New
(
"No MACs found matching "
+
vmwareMac
)
}
log
.
Printf
(
"Returning IP address %s"
,
ip
)
return
ip
,
nil
}
func
getVMWareMAC
()
(
string
,
error
)
{
// return the first three tuples, if the actual MAC cannot be found
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
}
defer
fh
.
Close
()
bytes
,
err
:=
ioutil
.
ReadAll
(
fh
)
if
err
!=
nil
{
return
defaultMacRe
,
err
}
hostMacRe
:=
regexp
.
MustCompile
(
`(?i)^\s*hostMAC\s*=\s*(.+)\s*$`
)
for
_
,
line
:=
range
strings
.
Split
(
string
(
bytes
),
"
\n
"
)
{
// Need to trim off CR character when running in windows
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
}
builder/vmware/step_type_boot_command.go
View file @
1286f735
...
...
@@ -8,6 +8,7 @@ import (
"github.com/mitchellh/packer/packer"
"log"
"net"
"runtime"
"strings"
"text/template"
"time"
...
...
@@ -64,7 +65,13 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc
log
.
Printf
(
"Connected to VNC desktop: %s"
,
c
.
DesktopName
)
// Determine the host IP
ipFinder
:=
&
IfconfigIPFinder
{
"vmnet8"
}
var
ipFinder
HostIPFinder
if
runtime
.
GOOS
==
"windows"
{
ipFinder
=
new
(
VMnetNatConfIPFinder
)
}
else
{
ipFinder
=
&
IfconfigIPFinder
{
Device
:
"vmnet8"
}
}
hostIp
,
err
:=
ipFinder
.
HostIP
()
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error detecting host IP: %s"
,
err
)
...
...
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