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
b8103ff9
Commit
b8103ff9
authored
Jun 19, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/virtualbox: properly handle errors
parent
da4dfbcd
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
53 additions
and
16 deletions
+53
-16
builder/virtualbox/builder.go
builder/virtualbox/builder.go
+5
-0
builder/virtualbox/step_attach_iso.go
builder/virtualbox/step_attach_iso.go
+3
-1
builder/virtualbox/step_create_disk.go
builder/virtualbox/step_create_disk.go
+9
-3
builder/virtualbox/step_create_vm.go
builder/virtualbox/step_create_vm.go
+3
-1
builder/virtualbox/step_download_iso.go
builder/virtualbox/step_download_iso.go
+7
-3
builder/virtualbox/step_export.go
builder/virtualbox/step_export.go
+3
-1
builder/virtualbox/step_forward_ssh.go
builder/virtualbox/step_forward_ssh.go
+3
-1
builder/virtualbox/step_prepare_output_dir.go
builder/virtualbox/step_prepare_output_dir.go
+1
-0
builder/virtualbox/step_run.go
builder/virtualbox/step_run.go
+3
-1
builder/virtualbox/step_shutdown.go
builder/virtualbox/step_shutdown.go
+10
-3
builder/virtualbox/step_suppress_messages.go
builder/virtualbox/step_suppress_messages.go
+3
-1
builder/virtualbox/step_type_boot_command.go
builder/virtualbox/step_type_boot_command.go
+3
-1
No files found.
builder/virtualbox/builder.go
View file @
b8103ff9
...
...
@@ -226,6 +226,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
b
.
runner
.
Run
(
state
)
// If there was an error, return that
if
rawErr
,
ok
:=
state
[
"error"
];
ok
{
return
nil
,
rawErr
.
(
error
)
}
return
nil
,
nil
}
...
...
builder/virtualbox/step_attach_iso.go
View file @
b8103ff9
...
...
@@ -31,7 +31,9 @@ func (s *stepAttachISO) Run(state map[string]interface{}) multistep.StepAction {
"--medium"
,
isoPath
,
}
if
err
:=
driver
.
VBoxManage
(
command
...
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error attaching hard drive: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error attaching ISO: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
builder/virtualbox/step_create_disk.go
View file @
b8103ff9
...
...
@@ -32,7 +32,9 @@ func (s *stepCreateDisk) Run(state map[string]interface{}) multistep.StepAction
ui
.
Say
(
"Creating hard drive..."
)
err
:=
driver
.
VBoxManage
(
command
...
)
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error creating hard drive: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error creating hard drive: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -40,7 +42,9 @@ func (s *stepCreateDisk) Run(state map[string]interface{}) multistep.StepAction
controllerName
:=
"IDE Controller"
err
=
driver
.
VBoxManage
(
"storagectl"
,
vmName
,
"--name"
,
controllerName
,
"--add"
,
"ide"
)
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error creating disk controller: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error creating disk controller: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -54,7 +58,9 @@ func (s *stepCreateDisk) Run(state map[string]interface{}) multistep.StepAction
"--medium"
,
path
,
}
if
err
:=
driver
.
VBoxManage
(
command
...
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error attaching hard drive: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error attaching hard drive: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
builder/virtualbox/step_create_vm.go
View file @
b8103ff9
...
...
@@ -34,7 +34,9 @@ func (s *stepCreateVM) Run(state map[string]interface{}) multistep.StepAction {
for
_
,
command
:=
range
commands
{
err
:=
driver
.
VBoxManage
(
command
...
)
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error creating VM: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error creating VM: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
builder/virtualbox/step_download_iso.go
View file @
b8103ff9
...
...
@@ -29,7 +29,9 @@ func (s stepDownloadISO) Run(state map[string]interface{}) multistep.StepAction
checksum
,
err
:=
hex
.
DecodeString
(
config
.
ISOMD5
)
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error parsing checksum: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error parsing checksum: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -57,12 +59,14 @@ func (s stepDownloadISO) Run(state map[string]interface{}) multistep.StepAction
progressTicker
:=
time
.
NewTicker
(
5
*
time
.
Second
)
defer
progressTicker
.
Stop
()
DownloadWaitLoop
:
DownloadWaitLoop
:
for
{
select
{
case
err
:=
<-
downloadCompleteCh
:
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error downloading ISO: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error downloading ISO: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
}
break
DownloadWaitLoop
...
...
builder/virtualbox/step_export.go
View file @
b8103ff9
...
...
@@ -34,7 +34,9 @@ func (s *stepExport) Run(state map[string]interface{}) multistep.StepAction {
ui
.
Say
(
"Exporting virtual machine..."
)
err
:=
driver
.
VBoxManage
(
command
...
)
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error exporting virtual machine: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error exporting virtual machine: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
builder/virtualbox/step_forward_ssh.go
View file @
b8103ff9
...
...
@@ -44,7 +44,9 @@ func (s *stepForwardSSH) Run(state map[string]interface{}) multistep.StepAction
fmt
.
Sprintf
(
"packerssh,tcp,127.0.0.1,%d,,%d"
,
sshHostPort
,
config
.
SSHPort
),
}
if
err
:=
driver
.
VBoxManage
(
command
...
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error creating port forwarding rule: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error creating port forwarding rule: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
builder/virtualbox/step_prepare_output_dir.go
View file @
b8103ff9
...
...
@@ -11,6 +11,7 @@ func (stepPrepareOutputDir) Run(state map[string]interface{}) multistep.StepActi
config
:=
state
[
"config"
]
.
(
*
config
)
if
err
:=
os
.
MkdirAll
(
config
.
OutputDir
,
0755
);
err
!=
nil
{
state
[
"error"
]
=
err
return
multistep
.
ActionHalt
}
...
...
builder/virtualbox/step_run.go
View file @
b8103ff9
...
...
@@ -25,7 +25,9 @@ func (s *stepRun) Run(state map[string]interface{}) multistep.StepAction {
ui
.
Say
(
"Starting the virtual machine..."
)
command
:=
[]
string
{
"startvm"
,
vmName
,
"--type"
,
"gui"
}
if
err
:=
driver
.
VBoxManage
(
command
...
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error starting VM: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error starting VM: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
builder/virtualbox/step_shutdown.go
View file @
b8103ff9
package
virtualbox
import
(
"errors"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
...
...
@@ -34,7 +35,9 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
log
.
Printf
(
"Executing shutdown command: %s"
,
config
.
ShutdownCommand
)
cmd
:=
&
packer
.
RemoteCmd
{
Command
:
config
.
ShutdownCommand
}
if
err
:=
comm
.
Start
(
cmd
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Failed to send shutdown command: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Failed to send shutdown command: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -52,7 +55,9 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
select
{
case
<-
shutdownTimer
:
ui
.
Error
(
"Timeout while waiting for machine to shut down."
)
err
:=
errors
.
New
(
"Timeout while waiting for machine to shut down."
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
default
:
time
.
Sleep
(
1
*
time
.
Second
)
...
...
@@ -61,7 +66,9 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
}
else
{
ui
.
Say
(
"Halting the virtual machine..."
)
if
err
:=
driver
.
Stop
(
vmName
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error stopping VM: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error stopping VM: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
}
...
...
builder/virtualbox/step_suppress_messages.go
View file @
b8103ff9
...
...
@@ -17,7 +17,9 @@ func (stepSuppressMessages) Run(state map[string]interface{}) multistep.StepActi
log
.
Println
(
"Suppressing annoying messages in VirtualBox"
)
if
err
:=
driver
.
SuppressMessages
();
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error configuring VirtualBox to suppress messages: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error configuring VirtualBox to suppress messages: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
builder/virtualbox/step_type_boot_command.go
View file @
b8103ff9
...
...
@@ -66,7 +66,9 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc
}
if
err
:=
driver
.
VBoxManage
(
"controlvm"
,
vmName
,
"keyboardputscancode"
,
code
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error sending boot command: %s"
,
err
))
err
:=
fmt
.
Errorf
(
"Error sending boot command: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
}
...
...
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