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
a3bd9ecd
Commit
a3bd9ecd
authored
Jun 23, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/virtualbox: add "vboxmanage" to run custom commands
parent
53b7b396
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
0 deletions
+103
-0
builder/virtualbox/builder.go
builder/virtualbox/builder.go
+6
-0
builder/virtualbox/builder_test.go
builder/virtualbox/builder_test.go
+36
-0
builder/virtualbox/step_vboxmanage.go
builder/virtualbox/step_vboxmanage.go
+61
-0
No files found.
builder/virtualbox/builder.go
View file @
a3bd9ecd
...
@@ -43,6 +43,7 @@ type config struct {
...
@@ -43,6 +43,7 @@ type config struct {
SSHPort
uint
`mapstructure:"ssh_port"`
SSHPort
uint
`mapstructure:"ssh_port"`
SSHUser
string
`mapstructure:"ssh_username"`
SSHUser
string
`mapstructure:"ssh_username"`
SSHWaitTimeout
time
.
Duration
``
SSHWaitTimeout
time
.
Duration
``
VBoxManage
[][]
string
`mapstructure:"vboxmanage"`
VMName
string
`mapstructure:"vm_name"`
VMName
string
`mapstructure:"vm_name"`
PackerDebug
bool
`mapstructure:"packer_debug"`
PackerDebug
bool
`mapstructure:"packer_debug"`
...
@@ -94,6 +95,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
...
@@ -94,6 +95,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
b
.
config
.
SSHPort
=
22
b
.
config
.
SSHPort
=
22
}
}
if
b
.
config
.
VBoxManage
==
nil
{
b
.
config
.
VBoxManage
=
make
([][]
string
,
0
)
}
if
b
.
config
.
VMName
==
""
{
if
b
.
config
.
VMName
==
""
{
b
.
config
.
VMName
=
"packer"
b
.
config
.
VMName
=
"packer"
}
}
...
@@ -204,6 +209,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -204,6 +209,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
new
(
stepCreateDisk
),
new
(
stepCreateDisk
),
new
(
stepAttachISO
),
new
(
stepAttachISO
),
new
(
stepForwardSSH
),
new
(
stepForwardSSH
),
new
(
stepVBoxManage
),
new
(
stepRun
),
new
(
stepRun
),
new
(
stepTypeBootCommand
),
new
(
stepTypeBootCommand
),
new
(
stepWaitForSSH
),
new
(
stepWaitForSSH
),
...
...
builder/virtualbox/builder_test.go
View file @
a3bd9ecd
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"io/ioutil"
"io/ioutil"
"os"
"os"
"reflect"
"testing"
"testing"
)
)
...
@@ -279,3 +280,38 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
...
@@ -279,3 +280,38 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
t
.
Fatalf
(
"should not have error: %s"
,
err
)
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
}
}
}
func
TestBuilderPrepare_VBoxManage
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
// Test with empty
delete
(
config
,
"vboxmanage"
)
err
:=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
!
reflect
.
DeepEqual
(
b
.
config
.
VBoxManage
,
[][]
string
{})
{
t
.
Fatalf
(
"bad: %#v"
,
b
.
config
.
VBoxManage
)
}
// Test with a good one
config
[
"vboxmanage"
]
=
[][]
interface
{}{
[]
interface
{}{
"foo"
,
"bar"
,
"baz"
},
}
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
expected
:=
[][]
string
{
[]
string
{
"foo"
,
"bar"
,
"baz"
},
}
if
!
reflect
.
DeepEqual
(
b
.
config
.
VBoxManage
,
expected
)
{
t
.
Fatalf
(
"bad: %#v"
,
b
.
config
.
VBoxManage
)
}
}
builder/virtualbox/step_vboxmanage.go
0 → 100644
View file @
a3bd9ecd
package
virtualbox
import
(
"bytes"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"strings"
"text/template"
)
type
commandTemplate
struct
{
Name
string
}
// This step executes additional VBoxManage commands as specified by the
// template.
//
// Uses:
//
// Produces:
type
stepVBoxManage
struct
{}
func
(
s
*
stepVBoxManage
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
vmName
:=
state
[
"vmName"
]
.
(
string
)
if
len
(
config
.
VBoxManage
)
>
0
{
ui
.
Say
(
"Executing custom VBoxManage commands..."
)
}
tplData
:=
&
commandTemplate
{
Name
:
vmName
,
}
for
_
,
originalCommand
:=
range
config
.
VBoxManage
{
command
:=
make
([]
string
,
len
(
originalCommand
))
copy
(
command
,
originalCommand
)
for
i
,
arg
:=
range
command
{
var
buf
bytes
.
Buffer
t
:=
template
.
Must
(
template
.
New
(
"arg"
)
.
Parse
(
arg
))
t
.
Execute
(
&
buf
,
tplData
)
command
[
i
]
=
buf
.
String
()
}
ui
.
Say
(
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
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
}
return
multistep
.
ActionContinue
}
func
(
s
*
stepVBoxManage
)
Cleanup
(
state
map
[
string
]
interface
{})
{}
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