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
95e0e465
Commit
95e0e465
authored
Dec 24, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: move StepRun to common
parent
7f86fa5f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
121 additions
and
23 deletions
+121
-23
builder/vmware/common/step_run.go
builder/vmware/common/step_run.go
+34
-22
builder/vmware/common/step_run_test.go
builder/vmware/common/step_run_test.go
+82
-0
builder/vmware/iso/builder.go
builder/vmware/iso/builder.go
+5
-1
No files found.
builder/vmware/
iso
/step_run.go
→
builder/vmware/
common
/step_run.go
View file @
95e0e465
package
iso
package
common
import
(
"fmt"
"github.com/mitchellh/multistep"
vmwcommon
"github.com/mitchellh/packer/builder/vmware/common"
"github.com/mitchellh/packer/packer"
"time"
)
...
...
@@ -11,39 +10,51 @@ import (
// This step runs the created virtual machine.
//
// Uses:
// config *config
// driver Driver
// ui packer.Ui
// vmx_path string
//
// Produces:
// <nothing>
type
stepRun
struct
{
type
StepRun
struct
{
BootWait
time
.
Duration
DurationBeforeStop
time
.
Duration
Headless
bool
bootTime
time
.
Time
vmxPath
string
}
func
(
s
*
stepRun
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
vmwcommon
.
Driver
)
func
(
s
*
StepRun
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmxPath
:=
state
.
Get
(
"vmx_path"
)
.
(
string
)
vncIp
:=
state
.
Get
(
"vnc_ip"
)
.
(
string
)
vncPort
:=
state
.
Get
(
"vnc_port"
)
.
(
uint
)
// Set the VMX path so that we know we started the machine
s
.
bootTime
=
time
.
Now
()
s
.
vmxPath
=
vmxPath
ui
.
Say
(
"Starting virtual machine..."
)
if
config
.
Headless
{
ui
.
Message
(
fmt
.
Sprintf
(
"The VM will be run headless, without a GUI. If you want to
\n
"
+
"view the screen of the VM, connect via VNC without a password to
\n
"
+
"%s:%d"
,
vncIp
,
vncPort
))
if
s
.
Headless
{
vncIpRaw
,
vncIpOk
:=
state
.
GetOk
(
"vnc_ip"
)
vncPortRaw
,
vncPortOk
:=
state
.
GetOk
(
"vnc_port"
)
if
vncIpOk
&&
vncPortOk
{
vncIp
:=
vncIpRaw
.
(
string
)
vncPort
:=
vncPortRaw
.
(
uint
)
ui
.
Message
(
fmt
.
Sprintf
(
"The VM will be run headless, without a GUI. If you want to
\n
"
+
"view the screen of the VM, connect via VNC without a password to
\n
"
+
"%s:%d"
,
vncIp
,
vncPort
))
}
else
{
ui
.
Message
(
"The VM will be run headless, without a GUI, as configured.
\n
"
+
"If the run isn't succeeding as you expect, please enable the GUI
\n
"
+
"to inspect the progress of the build."
)
}
}
if
err
:=
driver
.
Start
(
vmxPath
,
config
.
Headless
);
err
!=
nil
{
if
err
:=
driver
.
Start
(
vmxPath
,
s
.
Headless
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error starting VM: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
...
...
@@ -51,9 +62,9 @@ func (s *stepRun) Run(state multistep.StateBag) multistep.StepAction {
}
// Wait the wait amount
if
int64
(
config
.
b
ootWait
)
>
0
{
ui
.
Say
(
fmt
.
Sprintf
(
"Waiting %s for boot..."
,
config
.
b
ootWait
.
String
()))
wait
:=
time
.
After
(
config
.
b
ootWait
)
if
int64
(
s
.
B
ootWait
)
>
0
{
ui
.
Say
(
fmt
.
Sprintf
(
"Waiting %s for boot..."
,
s
.
B
ootWait
.
String
()))
wait
:=
time
.
After
(
s
.
B
ootWait
)
WAITLOOP
:
for
{
select
{
...
...
@@ -71,18 +82,19 @@ func (s *stepRun) Run(state multistep.StateBag) multistep.StepAction {
return
multistep
.
ActionContinue
}
func
(
s
*
s
tepRun
)
Cleanup
(
state
multistep
.
StateBag
)
{
driver
:=
state
.
Get
(
"driver"
)
.
(
vmwcommon
.
Driver
)
func
(
s
*
S
tepRun
)
Cleanup
(
state
multistep
.
StateBag
)
{
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
// If we started the machine... stop it.
if
s
.
vmxPath
!=
""
{
// If we started it less than 5 seconds ago... wait.
sinceBootTime
:=
time
.
Since
(
s
.
bootTime
)
waitBootTime
:=
5
*
time
.
Second
waitBootTime
:=
s
.
DurationBeforeStop
if
sinceBootTime
<
waitBootTime
{
sleepTime
:=
waitBootTime
-
sinceBootTime
ui
.
Say
(
fmt
.
Sprintf
(
"Waiting %s to give VMware time to clean up..."
,
sleepTime
.
String
()))
ui
.
Say
(
fmt
.
Sprintf
(
"Waiting %s to give VMware time to clean up..."
,
sleepTime
.
String
()))
time
.
Sleep
(
sleepTime
)
}
...
...
builder/vmware/common/step_run_test.go
0 → 100644
View file @
95e0e465
package
common
import
(
"testing"
"github.com/mitchellh/multistep"
)
func
TestStepRun_impl
(
t
*
testing
.
T
)
{
var
_
multistep
.
Step
=
new
(
StepRun
)
}
func
TestStepRun
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
new
(
StepRun
)
state
.
Put
(
"vmx_path"
,
"foo"
)
driver
:=
state
.
Get
(
"driver"
)
.
(
*
DriverMock
)
// Test the run
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionContinue
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
if
_
,
ok
:=
state
.
GetOk
(
"error"
);
ok
{
t
.
Fatal
(
"should NOT have error"
)
}
// Test the driver
if
!
driver
.
StartCalled
{
t
.
Fatal
(
"start should be called"
)
}
if
driver
.
StartPath
!=
"foo"
{
t
.
Fatalf
(
"bad: %#v"
,
driver
.
StartPath
)
}
if
driver
.
StartHeadless
{
t
.
Fatal
(
"bad"
)
}
// Test cleanup
step
.
Cleanup
(
state
)
if
driver
.
StopCalled
{
t
.
Fatal
(
"stop should not be called if not running"
)
}
}
func
TestStepRun_cleanupRunning
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
new
(
StepRun
)
state
.
Put
(
"vmx_path"
,
"foo"
)
driver
:=
state
.
Get
(
"driver"
)
.
(
*
DriverMock
)
// Test the run
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionContinue
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
if
_
,
ok
:=
state
.
GetOk
(
"error"
);
ok
{
t
.
Fatal
(
"should NOT have error"
)
}
// Test the driver
if
!
driver
.
StartCalled
{
t
.
Fatal
(
"start should be called"
)
}
if
driver
.
StartPath
!=
"foo"
{
t
.
Fatalf
(
"bad: %#v"
,
driver
.
StartPath
)
}
if
driver
.
StartHeadless
{
t
.
Fatal
(
"bad"
)
}
// Mark that it is running
driver
.
IsRunningResult
=
true
// Test cleanup
step
.
Cleanup
(
state
)
if
!
driver
.
StopCalled
{
t
.
Fatal
(
"stop should be called"
)
}
}
builder/vmware/iso/builder.go
View file @
95e0e465
...
...
@@ -396,7 +396,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
stepHTTPServer
{},
&
stepConfigureVNC
{},
&
StepRegister
{},
&
stepRun
{},
&
vmwcommon
.
StepRun
{
BootWait
:
b
.
config
.
bootWait
,
DurationBeforeStop
:
5
*
time
.
Second
,
Headless
:
b
.
config
.
Headless
,
},
&
stepTypeBootCommand
{},
&
common
.
StepConnectSSH
{
SSHAddress
:
driver
.
SSHAddress
,
...
...
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