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
1a3620d7
Commit
1a3620d7
authored
Aug 31, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/virtualbox: new multistep API
parent
77f7f249
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
164 additions
and
163 deletions
+164
-163
builder/virtualbox/builder.go
builder/virtualbox/builder.go
+9
-9
builder/virtualbox/ssh.go
builder/virtualbox/ssh.go
+5
-4
builder/virtualbox/step_attach_floppy.go
builder/virtualbox/step_attach_floppy.go
+11
-11
builder/virtualbox/step_attach_iso.go
builder/virtualbox/step_attach_iso.go
+10
-10
builder/virtualbox/step_create_disk.go
builder/virtualbox/step_create_disk.go
+9
-9
builder/virtualbox/step_create_vm.go
builder/virtualbox/step_create_vm.go
+9
-9
builder/virtualbox/step_download_guest_additions.go
builder/virtualbox/step_download_guest_additions.go
+15
-15
builder/virtualbox/step_export.go
builder/virtualbox/step_export.go
+12
-12
builder/virtualbox/step_forward_ssh.go
builder/virtualbox/step_forward_ssh.go
+8
-8
builder/virtualbox/step_http_server.go
builder/virtualbox/step_http_server.go
+6
-6
builder/virtualbox/step_prepare_output_dir.go
builder/virtualbox/step_prepare_output_dir.go
+9
-9
builder/virtualbox/step_run.go
builder/virtualbox/step_run.go
+9
-9
builder/virtualbox/step_shutdown.go
builder/virtualbox/step_shutdown.go
+10
-10
builder/virtualbox/step_suppress_messages.go
builder/virtualbox/step_suppress_messages.go
+5
-5
builder/virtualbox/step_type_boot_command.go
builder/virtualbox/step_type_boot_command.go
+10
-10
builder/virtualbox/step_upload_guest_additions.go
builder/virtualbox/step_upload_guest_additions.go
+11
-11
builder/virtualbox/step_upload_version.go
builder/virtualbox/step_upload_version.go
+8
-8
builder/virtualbox/step_vboxmanage.go
builder/virtualbox/step_vboxmanage.go
+8
-8
No files found.
builder/virtualbox/builder.go
View file @
1a3620d7
...
...
@@ -368,12 +368,12 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
}
// Setup the state bag
state
:=
make
(
map
[
string
]
interface
{}
)
state
[
"cache"
]
=
cache
state
[
"config"
]
=
&
b
.
config
state
[
"driver"
]
=
driver
state
[
"hook"
]
=
hook
state
[
"ui"
]
=
ui
state
:=
new
(
multistep
.
BasicStateBag
)
state
.
Put
(
"cache"
,
cache
)
state
.
Put
(
"config"
,
&
b
.
config
)
state
.
Put
(
"driver"
,
driver
)
state
.
Put
(
"hook"
,
hook
)
state
.
Put
(
"ui"
,
ui
)
// Run
if
b
.
config
.
PackerDebug
{
...
...
@@ -388,16 +388,16 @@ 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
{
if
rawErr
,
ok
:=
state
.
GetOk
(
"error"
)
;
ok
{
return
nil
,
rawErr
.
(
error
)
}
// If we were interrupted or cancelled, then just exit.
if
_
,
ok
:=
state
[
multistep
.
StateCancelled
]
;
ok
{
if
_
,
ok
:=
state
.
GetOk
(
multistep
.
StateCancelled
)
;
ok
{
return
nil
,
errors
.
New
(
"Build was cancelled."
)
}
if
_
,
ok
:=
state
[
multistep
.
StateHalted
]
;
ok
{
if
_
,
ok
:=
state
.
GetOk
(
multistep
.
StateHalted
)
;
ok
{
return
nil
,
errors
.
New
(
"Build was halted."
)
}
...
...
builder/virtualbox/ssh.go
View file @
1a3620d7
...
...
@@ -3,18 +3,19 @@ package virtualbox
import
(
gossh
"code.google.com/p/go.crypto/ssh"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/communicator/ssh"
"io/ioutil"
"os"
)
func
sshAddress
(
state
m
ap
[
string
]
interface
{}
)
(
string
,
error
)
{
sshHostPort
:=
state
[
"sshHostPort"
]
.
(
uint
)
func
sshAddress
(
state
m
ultistep
.
StateBag
)
(
string
,
error
)
{
sshHostPort
:=
state
.
Get
(
"sshHostPort"
)
.
(
uint
)
return
fmt
.
Sprintf
(
"127.0.0.1:%d"
,
sshHostPort
),
nil
}
func
sshConfig
(
state
m
ap
[
string
]
interface
{}
)
(
*
gossh
.
ClientConfig
,
error
)
{
config
:=
state
[
"config"
]
.
(
*
config
)
func
sshConfig
(
state
m
ultistep
.
StateBag
)
(
*
gossh
.
ClientConfig
,
error
)
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
auth
:=
[]
gossh
.
ClientAuth
{
gossh
.
ClientAuthPassword
(
ssh
.
Password
(
config
.
SSHPassword
)),
...
...
builder/virtualbox/step_attach_floppy.go
View file @
1a3620d7
...
...
@@ -20,10 +20,10 @@ type stepAttachFloppy struct {
floppyPath
string
}
func
(
s
*
stepAttachFloppy
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
stepAttachFloppy
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
// Determine if we even have a floppy disk to attach
var
floppyPath
string
if
floppyPathRaw
,
ok
:=
state
[
"floppy_path"
]
;
ok
{
if
floppyPathRaw
,
ok
:=
state
.
GetOk
(
"floppy_path"
)
;
ok
{
floppyPath
=
floppyPathRaw
.
(
string
)
}
else
{
log
.
Println
(
"No floppy disk, not attaching."
)
...
...
@@ -35,13 +35,13 @@ func (s *stepAttachFloppy) Run(state map[string]interface{}) multistep.StepActio
// floppy.
floppyPath
,
err
:=
s
.
copyFloppy
(
floppyPath
)
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error preparing floppy: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error preparing floppy: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vmName
:=
state
[
"vmName"
]
.
(
string
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmName
:=
state
.
Get
(
"vmName"
)
.
(
string
)
ui
.
Say
(
"Attaching floppy disk..."
)
...
...
@@ -52,7 +52,7 @@ func (s *stepAttachFloppy) Run(state map[string]interface{}) multistep.StepActio
"--add"
,
"floppy"
,
}
if
err
:=
driver
.
VBoxManage
(
command
...
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error creating floppy controller: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error creating floppy controller: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
...
...
@@ -66,7 +66,7 @@ func (s *stepAttachFloppy) Run(state map[string]interface{}) multistep.StepActio
"--medium"
,
floppyPath
,
}
if
err
:=
driver
.
VBoxManage
(
command
...
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error attaching floppy: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error attaching floppy: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
...
...
@@ -76,7 +76,7 @@ func (s *stepAttachFloppy) Run(state map[string]interface{}) multistep.StepActio
return
multistep
.
ActionContinue
}
func
(
s
*
stepAttachFloppy
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
stepAttachFloppy
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
if
s
.
floppyPath
==
""
{
return
}
...
...
@@ -84,8 +84,8 @@ func (s *stepAttachFloppy) Cleanup(state map[string]interface{}) {
// Delete the floppy disk
defer
os
.
Remove
(
s
.
floppyPath
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
vmName
:=
state
[
"vmName"
]
.
(
string
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
vmName
:=
state
.
Get
(
"vmName"
)
.
(
string
)
command
:=
[]
string
{
"storageattach"
,
vmName
,
...
...
builder/virtualbox/step_attach_iso.go
View file @
1a3620d7
...
...
@@ -15,11 +15,11 @@ type stepAttachISO struct {
diskPath
string
}
func
(
s
*
stepAttachISO
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
driver
:=
state
[
"driver"
]
.
(
Driver
)
isoPath
:=
state
[
"iso_path"
]
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vmName
:=
state
[
"vmName"
]
.
(
string
)
func
(
s
*
stepAttachISO
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
isoPath
:=
state
.
Get
(
"iso_path"
)
.
(
string
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmName
:=
state
.
Get
(
"vmName"
)
.
(
string
)
// Attach the disk to the controller
command
:=
[]
string
{
...
...
@@ -32,7 +32,7 @@ func (s *stepAttachISO) Run(state map[string]interface{}) multistep.StepAction {
}
if
err
:=
driver
.
VBoxManage
(
command
...
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error attaching ISO: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -43,14 +43,14 @@ func (s *stepAttachISO) Run(state map[string]interface{}) multistep.StepAction {
return
multistep
.
ActionContinue
}
func
(
s
*
stepAttachISO
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
stepAttachISO
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
if
s
.
diskPath
==
""
{
return
}
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vmName
:=
state
[
"vmName"
]
.
(
string
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmName
:=
state
.
Get
(
"vmName"
)
.
(
string
)
command
:=
[]
string
{
"storageattach"
,
vmName
,
...
...
builder/virtualbox/step_create_disk.go
View file @
1a3620d7
...
...
@@ -13,11 +13,11 @@ import (
// hard drive for the virtual machine.
type
stepCreateDisk
struct
{}
func
(
s
*
stepCreateDisk
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vmName
:=
state
[
"vmName"
]
.
(
string
)
func
(
s
*
stepCreateDisk
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmName
:=
state
.
Get
(
"vmName"
)
.
(
string
)
format
:=
"VDI"
path
:=
filepath
.
Join
(
config
.
OutputDir
,
fmt
.
Sprintf
(
"%s.%s"
,
config
.
VMName
,
strings
.
ToLower
(
format
)))
...
...
@@ -34,7 +34,7 @@ func (s *stepCreateDisk) Run(state map[string]interface{}) multistep.StepAction
err
:=
driver
.
VBoxManage
(
command
...
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating hard drive: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -44,7 +44,7 @@ func (s *stepCreateDisk) Run(state map[string]interface{}) multistep.StepAction
err
=
driver
.
VBoxManage
(
"storagectl"
,
vmName
,
"--name"
,
controllerName
,
"--add"
,
"ide"
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating disk controller: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -60,7 +60,7 @@ func (s *stepCreateDisk) Run(state map[string]interface{}) multistep.StepAction
}
if
err
:=
driver
.
VBoxManage
(
command
...
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error attaching hard drive: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -68,4 +68,4 @@ func (s *stepCreateDisk) Run(state map[string]interface{}) multistep.StepAction
return
multistep
.
ActionContinue
}
func
(
s
*
stepCreateDisk
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
stepCreateDisk
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{}
builder/virtualbox/step_create_vm.go
View file @
1a3620d7
...
...
@@ -14,10 +14,10 @@ type stepCreateVM struct {
vmName
string
}
func
(
s
*
stepCreateVM
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
func
(
s
*
stepCreateVM
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
name
:=
config
.
VMName
...
...
@@ -38,7 +38,7 @@ func (s *stepCreateVM) Run(state map[string]interface{}) multistep.StepAction {
err
:=
driver
.
VBoxManage
(
command
...
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating VM: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -50,18 +50,18 @@ func (s *stepCreateVM) Run(state map[string]interface{}) multistep.StepAction {
}
// Set the final name in the state bag so others can use it
state
[
"vmName"
]
=
s
.
vmName
state
.
Put
(
"vmName"
,
s
.
vmName
)
return
multistep
.
ActionContinue
}
func
(
s
*
stepCreateVM
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
stepCreateVM
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
if
s
.
vmName
==
""
{
return
}
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Unregistering and deleting virtual machine..."
)
if
err
:=
driver
.
VBoxManage
(
"unregistervm"
,
s
.
vmName
,
"--delete"
);
err
!=
nil
{
...
...
builder/virtualbox/step_download_guest_additions.go
View file @
1a3620d7
...
...
@@ -29,16 +29,16 @@ type guestAdditionsUrlTemplate struct {
// guest_additions_path string - Path to the guest additions.
type
stepDownloadGuestAdditions
struct
{}
func
(
s
*
stepDownloadGuestAdditions
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
func
(
s
*
stepDownloadGuestAdditions
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
var
action
multistep
.
StepAction
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
// Get VBox version
version
,
err
:=
driver
.
Version
()
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error reading version for guest additions download: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error reading version for guest additions download: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
...
...
@@ -71,7 +71,7 @@ func (s *stepDownloadGuestAdditions) Run(state map[string]interface{}) multistep
url
,
err
=
config
.
tpl
.
Process
(
url
,
tplData
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error preparing guest additions url: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -85,7 +85,7 @@ func (s *stepDownloadGuestAdditions) Run(state map[string]interface{}) multistep
url
,
err
=
common
.
DownloadableURL
(
url
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error preparing guest additions url: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -103,9 +103,9 @@ func (s *stepDownloadGuestAdditions) Run(state map[string]interface{}) multistep
return
downStep
.
Run
(
state
)
}
func
(
s
*
stepDownloadGuestAdditions
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
stepDownloadGuestAdditions
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{}
func
(
s
*
stepDownloadGuestAdditions
)
downloadAdditionsSHA256
(
state
m
ap
[
string
]
interface
{}
,
additionsVersion
string
,
additionsName
string
)
(
string
,
multistep
.
StepAction
)
{
func
(
s
*
stepDownloadGuestAdditions
)
downloadAdditionsSHA256
(
state
m
ultistep
.
StateBag
,
additionsVersion
string
,
additionsName
string
)
(
string
,
multistep
.
StepAction
)
{
// First things first, we get the list of checksums for the files available
// for this version.
checksumsUrl
:=
fmt
.
Sprintf
(
...
...
@@ -114,9 +114,9 @@ func (s *stepDownloadGuestAdditions) downloadAdditionsSHA256(state map[string]in
checksumsFile
,
err
:=
ioutil
.
TempFile
(
""
,
"packer"
)
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Failed creating temporary file to store guest addition checksums: %s"
,
err
)
err
)
)
return
""
,
multistep
.
ActionHalt
}
defer
os
.
Remove
(
checksumsFile
.
Name
())
...
...
@@ -136,9 +136,9 @@ func (s *stepDownloadGuestAdditions) downloadAdditionsSHA256(state map[string]in
// Next, we find the checksum for the file we're looking to download.
// It is an error if the checksum cannot be found.
checksumsF
,
err
:=
os
.
Open
(
state
[
"guest_additions_checksums_path"
]
.
(
string
))
checksumsF
,
err
:=
os
.
Open
(
state
.
Get
(
"guest_additions_checksums_path"
)
.
(
string
))
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error opening guest addition checksums: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error opening guest addition checksums: %s"
,
err
)
)
return
""
,
multistep
.
ActionHalt
}
defer
checksumsF
.
Close
()
...
...
@@ -166,8 +166,8 @@ func (s *stepDownloadGuestAdditions) downloadAdditionsSHA256(state map[string]in
}
if
checksum
==
""
{
state
[
"error"
]
=
fmt
.
Errorf
(
"The checksum for the file '%s' could not be found."
,
additionsName
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"The checksum for the file '%s' could not be found."
,
additionsName
)
)
return
""
,
multistep
.
ActionHalt
}
...
...
builder/virtualbox/step_export.go
View file @
1a3620d7
...
...
@@ -15,25 +15,25 @@ import (
// exportPath string - The path to the resulting export.
type
stepExport
struct
{}
func
(
s
*
stepExport
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vmName
:=
state
[
"vmName"
]
.
(
string
)
func
(
s
*
stepExport
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmName
:=
state
.
Get
(
"vmName"
)
.
(
string
)
// Clear out the Packer-created forwarding rule
ui
.
Say
(
"Preparing to export machine..."
)
ui
.
Message
(
fmt
.
Sprintf
(
"Deleting forwarded port mapping for SSH (host port %d)"
,
state
[
"sshHostPort"
]
))
ui
.
Message
(
fmt
.
Sprintf
(
"Deleting forwarded port mapping for SSH (host port %d)"
,
state
.
Get
(
"sshHostPort"
)
))
command
:=
[]
string
{
"modifyvm"
,
vmName
,
"--natpf1"
,
"delete"
,
"packerssh"
}
if
err
:=
driver
.
VBoxManage
(
command
...
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error deleting port forwarding rule: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
// Remove the attached floppy disk, if it exists
if
_
,
ok
:=
state
[
"floppy_path"
]
;
ok
{
if
_
,
ok
:=
state
.
GetOk
(
"floppy_path"
)
;
ok
{
ui
.
Message
(
"Removing floppy drive..."
)
command
:=
[]
string
{
"storageattach"
,
vmName
,
...
...
@@ -43,7 +43,7 @@ func (s *stepExport) Run(state map[string]interface{}) multistep.StepAction {
"--medium"
,
"none"
,
}
if
err
:=
driver
.
VBoxManage
(
command
...
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error removing floppy: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error removing floppy: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
...
...
@@ -63,14 +63,14 @@ func (s *stepExport) Run(state map[string]interface{}) multistep.StepAction {
err
:=
driver
.
VBoxManage
(
command
...
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error exporting virtual machine: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
state
[
"exportPath"
]
=
outputPath
state
.
Put
(
"exportPath"
,
outputPath
)
return
multistep
.
ActionContinue
}
func
(
s
*
stepExport
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
stepExport
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{}
builder/virtualbox/step_forward_ssh.go
View file @
1a3620d7
...
...
@@ -17,11 +17,11 @@ import (
// Produces:
type
stepForwardSSH
struct
{}
func
(
s
*
stepForwardSSH
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vmName
:=
state
[
"vmName"
]
.
(
string
)
func
(
s
*
stepForwardSSH
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmName
:=
state
.
Get
(
"vmName"
)
.
(
string
)
log
.
Printf
(
"Looking for available SSH port between %d and %d"
,
config
.
SSHHostPortMin
,
config
.
SSHHostPortMax
)
var
sshHostPort
uint
...
...
@@ -45,15 +45,15 @@ func (s *stepForwardSSH) Run(state map[string]interface{}) multistep.StepAction
}
if
err
:=
driver
.
VBoxManage
(
command
...
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating port forwarding rule: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
// Save the port we're using so that future steps can use it
state
[
"sshHostPort"
]
=
sshHostPort
state
.
Put
(
"sshHostPort"
,
sshHostPort
)
return
multistep
.
ActionContinue
}
func
(
s
*
stepForwardSSH
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
stepForwardSSH
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{}
builder/virtualbox/step_http_server.go
View file @
1a3620d7
...
...
@@ -23,13 +23,13 @@ type stepHTTPServer struct {
l
net
.
Listener
}
func
(
s
*
stepHTTPServer
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
func
(
s
*
stepHTTPServer
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
var
httpPort
uint
=
0
if
config
.
HTTPDir
==
""
{
state
[
"http_port"
]
=
httpPort
state
.
Put
(
"http_port"
,
httpPort
)
return
multistep
.
ActionContinue
}
...
...
@@ -62,12 +62,12 @@ func (s *stepHTTPServer) Run(state map[string]interface{}) multistep.StepAction
go
server
.
Serve
(
s
.
l
)
// Save the address into the state so it can be accessed in the future
state
[
"http_port"
]
=
httpPort
state
.
Put
(
"http_port"
,
httpPort
)
return
multistep
.
ActionContinue
}
func
(
s
*
stepHTTPServer
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
stepHTTPServer
)
Cleanup
(
m
ultistep
.
StateBag
)
{
if
s
.
l
!=
nil
{
// Close the listener so that the HTTP server stops
s
.
l
.
Close
()
...
...
builder/virtualbox/step_prepare_output_dir.go
View file @
1a3620d7
...
...
@@ -10,9 +10,9 @@ import (
type
stepPrepareOutputDir
struct
{}
func
(
stepPrepareOutputDir
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
func
(
stepPrepareOutputDir
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
if
_
,
err
:=
os
.
Stat
(
config
.
OutputDir
);
err
==
nil
&&
config
.
PackerForce
{
ui
.
Say
(
"Deleting previous output directory..."
)
...
...
@@ -20,20 +20,20 @@ func (stepPrepareOutputDir) Run(state map[string]interface{}) multistep.StepActi
}
if
err
:=
os
.
MkdirAll
(
config
.
OutputDir
,
0755
);
err
!=
nil
{
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
}
func
(
stepPrepareOutputDir
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
_
,
cancelled
:=
state
[
multistep
.
StateCancelled
]
_
,
halted
:=
state
[
multistep
.
StateHalted
]
func
(
stepPrepareOutputDir
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
_
,
cancelled
:=
state
.
GetOk
(
multistep
.
StateCancelled
)
_
,
halted
:=
state
.
GetOk
(
multistep
.
StateHalted
)
if
cancelled
||
halted
{
config
:=
state
[
"config"
]
.
(
*
config
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
.
Say
(
"Deleting output directory..."
)
for
i
:=
0
;
i
<
5
;
i
++
{
...
...
builder/virtualbox/step_run.go
View file @
1a3620d7
...
...
@@ -16,11 +16,11 @@ type stepRun struct {
vmName
string
}
func
(
s
*
stepRun
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vmName
:=
state
[
"vmName"
]
.
(
string
)
func
(
s
*
stepRun
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmName
:=
state
.
Get
(
"vmName"
)
.
(
string
)
ui
.
Say
(
"Starting the virtual machine..."
)
guiArgument
:=
"gui"
...
...
@@ -33,7 +33,7 @@ func (s *stepRun) Run(state map[string]interface{}) multistep.StepAction {
command
:=
[]
string
{
"startvm"
,
vmName
,
"--type"
,
guiArgument
}
if
err
:=
driver
.
VBoxManage
(
command
...
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error starting VM: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -48,13 +48,13 @@ func (s *stepRun) Run(state map[string]interface{}) multistep.StepAction {
return
multistep
.
ActionContinue
}
func
(
s
*
stepRun
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{
func
(
s
*
stepRun
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{
if
s
.
vmName
==
""
{
return
}
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
if
running
,
_
:=
driver
.
IsRunning
(
s
.
vmName
);
running
{
if
err
:=
driver
.
VBoxManage
(
"controlvm"
,
s
.
vmName
,
"poweroff"
);
err
!=
nil
{
...
...
builder/virtualbox/step_shutdown.go
View file @
1a3620d7
...
...
@@ -23,12 +23,12 @@ import (
// <nothing>
type
stepShutdown
struct
{}
func
(
s
*
stepShutdown
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
comm
:=
state
[
"communicator"
]
.
(
packer
.
Communicator
)
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vmName
:=
state
[
"vmName"
]
.
(
string
)
func
(
s
*
stepShutdown
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
comm
:=
state
.
Get
(
"communicator"
)
.
(
packer
.
Communicator
)
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmName
:=
state
.
Get
(
"vmName"
)
.
(
string
)
if
config
.
ShutdownCommand
!=
""
{
ui
.
Say
(
"Gracefully halting virtual machine..."
)
...
...
@@ -36,7 +36,7 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
cmd
:=
&
packer
.
RemoteCmd
{
Command
:
config
.
ShutdownCommand
}
if
err
:=
cmd
.
StartWithUi
(
comm
,
ui
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Failed to send shutdown command: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -53,7 +53,7 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
select
{
case
<-
shutdownTimer
:
err
:=
errors
.
New
(
"Timeout while waiting for machine to shut down."
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
default
:
...
...
@@ -64,7 +64,7 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
ui
.
Say
(
"Halting the virtual machine..."
)
if
err
:=
driver
.
Stop
(
vmName
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error stopping VM: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -74,4 +74,4 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
return
multistep
.
ActionContinue
}
func
(
s
*
stepShutdown
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
stepShutdown
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{}
builder/virtualbox/step_suppress_messages.go
View file @
1a3620d7
...
...
@@ -11,14 +11,14 @@ import (
// pop-up messages don't exist.
type
stepSuppressMessages
struct
{}
func
(
stepSuppressMessages
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
func
(
stepSuppressMessages
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
log
.
Println
(
"Suppressing annoying messages in VirtualBox"
)
if
err
:=
driver
.
SuppressMessages
();
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error configuring VirtualBox to suppress messages: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -26,4 +26,4 @@ func (stepSuppressMessages) Run(state map[string]interface{}) multistep.StepActi
return
multistep
.
ActionContinue
}
func
(
stepSuppressMessages
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{}
func
(
stepSuppressMessages
)
Cleanup
(
m
ultistep
.
StateBag
)
{}
builder/virtualbox/step_type_boot_command.go
View file @
1a3620d7
...
...
@@ -32,12 +32,12 @@ type bootCommandTemplateData struct {
// <nothing>
type
stepTypeBootCommand
struct
{}
func
(
s
*
stepTypeBootCommand
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
httpPort
:=
state
[
"http_port"
]
.
(
uint
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vmName
:=
state
[
"vmName"
]
.
(
string
)
func
(
s
*
stepTypeBootCommand
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
httpPort
:=
state
.
Get
(
"http_port"
)
.
(
uint
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmName
:=
state
.
Get
(
"vmName"
)
.
(
string
)
tplData
:=
&
bootCommandTemplateData
{
"10.0.2.2"
,
...
...
@@ -50,7 +50,7 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc
command
,
err
:=
config
.
tpl
.
Process
(
command
,
tplData
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error preparing boot command: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -73,13 +73,13 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc
// Since typing is sometimes so slow, we check for an interrupt
// in between each character.
if
_
,
ok
:=
state
[
multistep
.
StateCancelled
]
;
ok
{
if
_
,
ok
:=
state
.
GetOk
(
multistep
.
StateCancelled
)
;
ok
{
return
multistep
.
ActionHalt
}
if
err
:=
driver
.
VBoxManage
(
"controlvm"
,
vmName
,
"keyboardputscancode"
,
code
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error sending boot command: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -89,7 +89,7 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc
return
multistep
.
ActionContinue
}
func
(
*
stepTypeBootCommand
)
Cleanup
(
m
ap
[
string
]
interface
{}
)
{}
func
(
*
stepTypeBootCommand
)
Cleanup
(
m
ultistep
.
StateBag
)
{}
func
scancodes
(
message
string
)
[]
string
{
special
:=
make
(
map
[
string
][]
string
)
...
...
builder/virtualbox/step_upload_guest_additions.go
View file @
1a3620d7
...
...
@@ -14,22 +14,22 @@ type guestAdditionsPathTemplate struct {
// This step uploads the guest additions ISO to the VM.
type
stepUploadGuestAdditions
struct
{}
func
(
s
*
stepUploadGuestAdditions
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
comm
:=
state
[
"communicator"
]
.
(
packer
.
Communicator
)
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
guestAdditionsPath
:=
state
[
"guest_additions_path"
]
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
func
(
s
*
stepUploadGuestAdditions
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
comm
:=
state
.
Get
(
"communicator"
)
.
(
packer
.
Communicator
)
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
guestAdditionsPath
:=
state
.
Get
(
"guest_additions_path"
)
.
(
string
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
version
,
err
:=
driver
.
Version
()
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error reading version for guest additions upload: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error reading version for guest additions upload: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
f
,
err
:=
os
.
Open
(
guestAdditionsPath
)
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error opening guest additions ISO: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error opening guest additions ISO: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
...
...
@@ -40,18 +40,18 @@ func (s *stepUploadGuestAdditions) Run(state map[string]interface{}) multistep.S
config
.
GuestAdditionsPath
,
err
=
config
.
tpl
.
Process
(
config
.
GuestAdditionsPath
,
tplData
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error preparing guest additions path: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
ui
.
Say
(
"Uploading VirtualBox guest additions ISO..."
)
if
err
:=
comm
.
Upload
(
config
.
GuestAdditionsPath
,
f
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error uploading guest additions: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error uploading guest additions: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
}
func
(
s
*
stepUploadGuestAdditions
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
stepUploadGuestAdditions
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{}
builder/virtualbox/step_upload_version.go
View file @
1a3620d7
...
...
@@ -12,11 +12,11 @@ import (
// can be useful for various provisioning reasons.
type
stepUploadVersion
struct
{}
func
(
s
*
stepUploadVersion
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
comm
:=
state
[
"communicator"
]
.
(
packer
.
Communicator
)
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
func
(
s
*
stepUploadVersion
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
comm
:=
state
.
Get
(
"communicator"
)
.
(
packer
.
Communicator
)
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
if
config
.
VBoxVersionFile
==
""
{
log
.
Println
(
"VBoxVersionFile is empty. Not uploading."
)
...
...
@@ -25,7 +25,7 @@ func (s *stepUploadVersion) Run(state map[string]interface{}) multistep.StepActi
version
,
err
:=
driver
.
Version
()
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error reading version for metadata upload: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error reading version for metadata upload: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
...
...
@@ -33,11 +33,11 @@ func (s *stepUploadVersion) Run(state map[string]interface{}) multistep.StepActi
var
data
bytes
.
Buffer
data
.
WriteString
(
version
)
if
err
:=
comm
.
Upload
(
config
.
VBoxVersionFile
,
&
data
);
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error uploading VirtualBox version: %s"
,
err
)
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error uploading VirtualBox version: %s"
,
err
)
)
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
}
func
(
s
*
stepUploadVersion
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
stepUploadVersion
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{}
builder/virtualbox/step_vboxmanage.go
View file @
1a3620d7
...
...
@@ -19,11 +19,11 @@ type commandTemplate struct {
// Produces:
type
stepVBoxManage
struct
{}
func
(
s
*
stepVBoxManage
)
Run
(
state
m
ap
[
string
]
interface
{}
)
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vmName
:=
state
[
"vmName"
]
.
(
string
)
func
(
s
*
stepVBoxManage
)
Run
(
state
m
ultistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmName
:=
state
.
Get
(
"vmName"
)
.
(
string
)
if
len
(
config
.
VBoxManage
)
>
0
{
ui
.
Say
(
"Executing custom VBoxManage commands..."
)
...
...
@@ -42,7 +42,7 @@ func (s *stepVBoxManage) Run(state map[string]interface{}) multistep.StepAction
command
[
i
],
err
=
config
.
tpl
.
Process
(
arg
,
tplData
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error preparing vboxmanage command: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -51,7 +51,7 @@ func (s *stepVBoxManage) Run(state map[string]interface{}) multistep.StepAction
ui
.
Message
(
fmt
.
Sprintf
(
"Executing: %s"
,
strings
.
Join
(
command
,
" "
)))
if
err
:=
driver
.
VBoxManage
(
command
...
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error executing command: %s"
,
err
)
state
[
"error"
]
=
err
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
...
...
@@ -60,4 +60,4 @@ func (s *stepVBoxManage) Run(state map[string]interface{}) multistep.StepAction
return
multistep
.
ActionContinue
}
func
(
s
*
stepVBoxManage
)
Cleanup
(
state
m
ap
[
string
]
interface
{}
)
{}
func
(
s
*
stepVBoxManage
)
Cleanup
(
state
m
ultistep
.
StateBag
)
{}
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