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
4bd2aa61
Commit
4bd2aa61
authored
Dec 22, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/virtualbox: StepVBoxmanage
parent
7a4ff3f2
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
120 additions
and
98 deletions
+120
-98
builder/virtualbox/common/step_vboxmanage.go
builder/virtualbox/common/step_vboxmanage.go
+14
-10
builder/virtualbox/common/vboxmanage_config.go
builder/virtualbox/common/vboxmanage_config.go
+28
-0
builder/virtualbox/common/vboxmanage_config_test.go
builder/virtualbox/common/vboxmanage_config_test.go
+37
-0
builder/virtualbox/iso/builder.go
builder/virtualbox/iso/builder.go
+29
-39
builder/virtualbox/iso/builder_test.go
builder/virtualbox/iso/builder_test.go
+0
-43
builder/virtualbox/ovf/builder.go
builder/virtualbox/ovf/builder.go
+6
-2
builder/virtualbox/ovf/config.go
builder/virtualbox/ovf/config.go
+6
-4
No files found.
builder/virtualbox/
iso
/step_vboxmanage.go
→
builder/virtualbox/
common
/step_vboxmanage.go
View file @
4bd2aa61
package
iso
package
common
import
(
"fmt"
"github.com/mitchellh/multistep"
vboxcommon
"github.com/mitchellh/packer/builder/virtualbox/common"
"github.com/mitchellh/packer/packer"
"strings"
)
...
...
@@ -16,17 +15,22 @@ type commandTemplate struct {
// template.
//
// Uses:
// driver Driver
// ui packer.Ui
// vmName string
//
// Produces:
type
stepVBoxManage
struct
{}
type
StepVBoxManage
struct
{
Commands
[][]
string
Tpl
*
packer
.
ConfigTemplate
}
func
(
s
*
stepVBoxManage
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
vboxcommon
.
Driver
)
func
(
s
*
StepVBoxManage
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmName
:=
state
.
Get
(
"vmName"
)
.
(
string
)
if
len
(
config
.
VBoxManage
)
>
0
{
if
len
(
s
.
Commands
)
>
0
{
ui
.
Say
(
"Executing custom VBoxManage commands..."
)
}
...
...
@@ -34,13 +38,13 @@ func (s *stepVBoxManage) Run(state multistep.StateBag) multistep.StepAction {
Name
:
vmName
,
}
for
_
,
originalCommand
:=
range
config
.
VBoxManage
{
for
_
,
originalCommand
:=
range
s
.
Commands
{
command
:=
make
([]
string
,
len
(
originalCommand
))
copy
(
command
,
originalCommand
)
for
i
,
arg
:=
range
command
{
var
err
error
command
[
i
],
err
=
config
.
t
pl
.
Process
(
arg
,
tplData
)
command
[
i
],
err
=
s
.
T
pl
.
Process
(
arg
,
tplData
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error preparing vboxmanage command: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
...
...
@@ -61,4 +65,4 @@ func (s *stepVBoxManage) Run(state multistep.StateBag) multistep.StepAction {
return
multistep
.
ActionContinue
}
func
(
s
*
s
tepVBoxManage
)
Cleanup
(
state
multistep
.
StateBag
)
{}
func
(
s
*
S
tepVBoxManage
)
Cleanup
(
state
multistep
.
StateBag
)
{}
builder/virtualbox/common/vboxmanage_config.go
0 → 100644
View file @
4bd2aa61
package
common
import
(
"fmt"
"github.com/mitchellh/packer/packer"
)
type
VBoxManageConfig
struct
{
VBoxManage
[][]
string
`mapstructure:"vboxmanage"`
}
func
(
c
*
VBoxManageConfig
)
Prepare
(
t
*
packer
.
ConfigTemplate
)
[]
error
{
if
c
.
VBoxManage
==
nil
{
c
.
VBoxManage
=
make
([][]
string
,
0
)
}
errs
:=
make
([]
error
,
0
)
for
i
,
args
:=
range
c
.
VBoxManage
{
for
j
,
arg
:=
range
args
{
if
err
:=
t
.
Validate
(
arg
);
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Error processing vboxmanage[%d][%d]: %s"
,
i
,
j
,
err
))
}
}
}
return
errs
}
builder/virtualbox/common/vboxmanage_config_test.go
0 → 100644
View file @
4bd2aa61
package
common
import
(
"reflect"
"testing"
)
func
TestVBoxManageConfigPrepare_VBoxManage
(
t
*
testing
.
T
)
{
// Test with empty
c
:=
new
(
VBoxManageConfig
)
errs
:=
c
.
Prepare
(
testConfigTemplate
(
t
))
if
len
(
errs
)
>
0
{
t
.
Fatalf
(
"err: %#v"
,
errs
)
}
if
!
reflect
.
DeepEqual
(
c
.
VBoxManage
,
[][]
string
{})
{
t
.
Fatalf
(
"bad: %#v"
,
c
.
VBoxManage
)
}
// Test with a good one
c
=
new
(
VBoxManageConfig
)
c
.
VBoxManage
=
[][]
string
{
{
"foo"
,
"bar"
,
"baz"
},
}
errs
=
c
.
Prepare
(
testConfigTemplate
(
t
))
if
len
(
errs
)
>
0
{
t
.
Fatalf
(
"err: %#v"
,
errs
)
}
expected
:=
[][]
string
{
[]
string
{
"foo"
,
"bar"
,
"baz"
},
}
if
!
reflect
.
DeepEqual
(
c
.
VBoxManage
,
expected
)
{
t
.
Fatalf
(
"bad: %#v"
,
c
.
VBoxManage
)
}
}
builder/virtualbox/iso/builder.go
View file @
4bd2aa61
...
...
@@ -32,6 +32,7 @@ type config struct {
vboxcommon
.
FloppyConfig
`mapstructure:",squash"`
vboxcommon
.
OutputConfig
`mapstructure:",squash"`
vboxcommon
.
SSHConfig
`mapstructure:",squash"`
vboxcommon
.
VBoxManageConfig
`mapstructure:",squash"`
BootCommand
[]
string
`mapstructure:"boot_command"`
DiskSize
uint
`mapstructure:"disk_size"`
...
...
@@ -51,7 +52,6 @@ type config struct {
ISOUrls
[]
string
`mapstructure:"iso_urls"`
ShutdownCommand
string
`mapstructure:"shutdown_command"`
VBoxVersionFile
string
`mapstructure:"virtualbox_version_file"`
VBoxManage
[][]
string
`mapstructure:"vboxmanage"`
VMName
string
`mapstructure:"vm_name"`
RawBootWait
string
`mapstructure:"boot_wait"`
...
...
@@ -81,6 +81,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
OutputConfig
.
Prepare
(
b
.
config
.
tpl
,
&
b
.
config
.
PackerConfig
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
SSHConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
VBoxManageConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
warnings
:=
make
([]
string
,
0
)
if
b
.
config
.
DiskSize
==
0
{
...
...
@@ -115,10 +116,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b
.
config
.
RawBootWait
=
"10s"
}
if
b
.
config
.
VBoxManage
==
nil
{
b
.
config
.
VBoxManage
=
make
([][]
string
,
0
)
}
if
b
.
config
.
VBoxVersionFile
==
""
{
b
.
config
.
VBoxVersionFile
=
".vbox_version"
}
...
...
@@ -277,15 +274,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs
,
fmt
.
Errorf
(
"Failed parsing shutdown_timeout: %s"
,
err
))
}
for
i
,
args
:=
range
b
.
config
.
VBoxManage
{
for
j
,
arg
:=
range
args
{
if
err
:=
b
.
config
.
tpl
.
Validate
(
arg
);
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing vboxmanage[%d][%d]: %s"
,
i
,
j
,
err
))
}
}
}
// Warnings
if
b
.
config
.
ShutdownCommand
==
""
{
warnings
=
append
(
warnings
,
...
...
@@ -335,7 +323,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
HostPortMin
:
b
.
config
.
SSHHostPortMin
,
HostPortMax
:
b
.
config
.
SSHHostPortMax
,
},
new
(
stepVBoxManage
),
&
vboxcommon
.
StepVBoxManage
{
Commands
:
b
.
config
.
VBoxManage
,
},
new
(
stepRun
),
new
(
stepTypeBootCommand
),
&
common
.
StepConnectSSH
{
...
...
builder/virtualbox/iso/builder_test.go
View file @
4bd2aa61
...
...
@@ -2,8 +2,6 @@ package iso
import
(
"github.com/mitchellh/packer/packer"
"io/ioutil"
"os"
"reflect"
"testing"
)
...
...
@@ -575,47 +573,6 @@ func TestBuilderPrepare_ShutdownTimeout(t *testing.T) {
}
}
func
TestBuilderPrepare_VBoxManage
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
// Test with empty
delete
(
config
,
"vboxmanage"
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
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
{}
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
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
)
}
}
func
TestBuilderPrepare_VBoxVersionFile
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
...
...
builder/virtualbox/ovf/builder.go
View file @
4bd2aa61
...
...
@@ -59,8 +59,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
HostPortMin
:
b
.
config
.
SSHHostPortMin
,
HostPortMax
:
b
.
config
.
SSHHostPortMax
,
},
&
vboxcommon
.
StepVBoxManage
{
Commands
:
b
.
config
.
VBoxManage
,
},
/*
new(stepVBoxManage),
new(stepRun),
*/
&
common
.
StepConnectSSH
{
...
...
@@ -71,7 +73,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
/*
new(stepUploadVersion),
new(stepUploadGuestAdditions),
*/
new
(
common
.
StepProvision
),
/*
new(stepShutdown),
new(stepRemoveDevices),
new(stepExport),
...
...
builder/virtualbox/ovf/config.go
View file @
4bd2aa61
...
...
@@ -12,6 +12,7 @@ type Config struct {
vboxcommon
.
FloppyConfig
`mapstructure:",squash"`
vboxcommon
.
OutputConfig
`mapstructure:",squash"`
vboxcommon
.
SSHConfig
`mapstructure:",squash"`
vboxcommon
.
VBoxManageConfig
`mapstructure:",squash"`
tpl
*
packer
.
ConfigTemplate
}
...
...
@@ -34,6 +35,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
FloppyConfig
.
Prepare
(
c
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
OutputConfig
.
Prepare
(
c
.
tpl
,
&
c
.
PackerConfig
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
SSHConfig
.
Prepare
(
c
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
VBoxManageConfig
.
Prepare
(
c
.
tpl
)
...
)
// Check for any errors.
if
errs
!=
nil
&&
len
(
errs
.
Errors
)
>
0
{
...
...
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