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
dfee3eb8
Commit
dfee3eb8
authored
Jun 05, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: Properly detect host IP
parent
34f40869
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
2 deletions
+65
-2
builder/vmware/host_ip.go
builder/vmware/host_ip.go
+43
-0
builder/vmware/host_ip_test.go
builder/vmware/host_ip_test.go
+11
-0
builder/vmware/step_type_boot_command.go
builder/vmware/step_type_boot_command.go
+10
-1
builder/vmware/step_wait_for_ip.go
builder/vmware/step_wait_for_ip.go
+1
-1
No files found.
builder/vmware/host_ip.go
0 → 100644
View file @
dfee3eb8
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*(.+?)\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
0 → 100644
View file @
dfee3eb8
package
vmware
import
"testing"
func
TestIfconfigIPFinder_Impl
(
t
*
testing
.
T
)
{
var
raw
interface
{}
raw
=
&
IfconfigIPFinder
{}
if
_
,
ok
:=
raw
.
(
HostIPFinder
);
!
ok
{
t
.
Fatalf
(
"IfconfigIPFinder is not a host IP finder"
)
}
}
builder/vmware/step_type_boot_command.go
View file @
dfee3eb8
...
...
@@ -41,6 +41,7 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vncPort
:=
state
[
"vnc_port"
]
.
(
uint
)
// Connect to VNC
ui
.
Say
(
"Connecting to VM via VNC"
)
nc
,
err
:=
net
.
Dial
(
"tcp"
,
fmt
.
Sprintf
(
"127.0.0.1:%d"
,
vncPort
))
if
err
!=
nil
{
...
...
@@ -58,8 +59,16 @@ 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"
}
hostIp
,
err
:=
ipFinder
.
HostIP
()
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error detecting host IP: %s"
,
err
))
return
multistep
.
ActionHalt
}
tplData
:=
&
bootCommandTemplateData
{
"127.0.0.1"
,
hostIp
,
httpPort
,
config
.
VMName
,
}
...
...
builder/vmware/step_wait_for_ip.go
View file @
dfee3eb8
...
...
@@ -19,7 +19,7 @@ func (stepWaitForIP) Run(state map[string]interface{}) multistep.StepAction {
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
.
Say
(
"Waiting for SSH to become available..."
)
select
{}
select
{}
return
multistep
.
ActionContinue
}
...
...
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