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
7fe40cfc
Commit
7fe40cfc
authored
Jun 11, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/virtualbox: Create the VM
parent
07cacb6d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
6 deletions
+80
-6
builder/virtualbox/builder.go
builder/virtualbox/builder.go
+6
-0
builder/virtualbox/builder_test.go
builder/virtualbox/builder_test.go
+4
-0
builder/virtualbox/driver.go
builder/virtualbox/driver.go
+9
-6
builder/virtualbox/step_create_vm.go
builder/virtualbox/step_create_vm.go
+61
-0
No files found.
builder/virtualbox/builder.go
View file @
7fe40cfc
...
...
@@ -20,6 +20,7 @@ type Builder struct {
type
config
struct
{
GuestOSType
string
`mapstructure:"guest_os_type"`
OutputDir
string
`mapstructure:"output_directory"`
VMName
string
`mapstructure:"vm_name"`
}
func
(
b
*
Builder
)
Prepare
(
raw
interface
{})
error
{
...
...
@@ -36,6 +37,10 @@ func (b *Builder) Prepare(raw interface{}) error {
b
.
config
.
OutputDir
=
"virtualbox"
}
if
b
.
config
.
VMName
==
""
{
b
.
config
.
VMName
=
"packer"
}
errs
:=
make
([]
error
,
0
)
b
.
driver
,
err
=
b
.
newDriver
()
...
...
@@ -54,6 +59,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer
steps
:=
[]
multistep
.
Step
{
new
(
stepPrepareOutputDir
),
new
(
stepSuppressMessages
),
new
(
stepCreateVM
),
}
// Setup the state bag
...
...
builder/virtualbox/builder_test.go
View file @
7fe40cfc
...
...
@@ -32,4 +32,8 @@ func TestBuilderPrepare_Defaults(t *testing.T) {
if
b
.
config
.
OutputDir
!=
"virtualbox"
{
t
.
Errorf
(
"bad output dir: %s"
,
b
.
config
.
OutputDir
)
}
if
b
.
config
.
VMName
!=
"packer"
{
t
.
Errorf
(
"bad vm name: %s"
,
b
.
config
.
VMName
)
}
}
builder/virtualbox/driver.go
View file @
7fe40cfc
...
...
@@ -14,6 +14,9 @@ type Driver interface {
// suppress any annoying popups from VirtualBox.
SuppressMessages
()
error
// VBoxManage executes the given VBoxManage command
VBoxManage
(
...
string
)
error
// Verify checks to make sure that this driver should function
// properly. If there is any indication the driver can't function,
// this will return an error.
...
...
@@ -34,7 +37,7 @@ func (d *VBox42Driver) SuppressMessages() error {
}
for
k
,
v
:=
range
extraData
{
if
err
:=
d
.
vboxm
anage
(
"setextradata"
,
"global"
,
k
,
v
);
err
!=
nil
{
if
err
:=
d
.
VBoxM
anage
(
"setextradata"
,
"global"
,
k
,
v
);
err
!=
nil
{
return
err
}
}
...
...
@@ -42,11 +45,7 @@ func (d *VBox42Driver) SuppressMessages() error {
return
nil
}
func
(
d
*
VBox42Driver
)
Verify
()
error
{
return
nil
}
func
(
d
*
VBox42Driver
)
vboxmanage
(
args
...
string
)
error
{
func
(
d
*
VBox42Driver
)
VBoxManage
(
args
...
string
)
error
{
log
.
Printf
(
"Executing VBoxManage: %#v"
,
args
)
cmd
:=
exec
.
Command
(
d
.
VBoxManagePath
,
args
...
)
if
err
:=
cmd
.
Run
();
err
!=
nil
{
...
...
@@ -55,3 +54,7 @@ func (d *VBox42Driver) vboxmanage(args ...string) error {
return
nil
}
func
(
d
*
VBox42Driver
)
Verify
()
error
{
return
nil
}
builder/virtualbox/step_create_vm.go
0 → 100644
View file @
7fe40cfc
package
virtualbox
import
(
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"time"
)
// This step creates the actual virtual machine.
type
stepCreateVM
struct
{
vmName
string
}
func
(
s
*
stepCreateVM
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
*
config
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
name
:=
config
.
VMName
commands
:=
make
([][]
string
,
4
)
commands
[
0
]
=
[]
string
{
"createvm"
,
"--name"
,
name
,
"--ostype"
,
config
.
GuestOSType
,
"--register"
}
commands
[
1
]
=
[]
string
{
"modifyvm"
,
name
,
"--boot1"
,
"disk"
,
"--boot2"
,
"dvd"
,
"--boot3"
,
"none"
,
"--boot4"
,
"none"
,
}
commands
[
2
]
=
[]
string
{
"modifyvm"
,
name
,
"--cpus"
,
"1"
}
commands
[
3
]
=
[]
string
{
"modifyvm"
,
name
,
"--memory"
,
"512"
}
ui
.
Say
(
"Creating virtual machine..."
)
for
_
,
command
:=
range
commands
{
err
:=
driver
.
VBoxManage
(
command
...
)
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error creating VM: %s"
,
err
))
return
multistep
.
ActionHalt
}
// Set the VM name propery on the first command
if
s
.
vmName
==
""
{
s
.
vmName
=
name
}
}
time
.
Sleep
(
15
*
time
.
Second
)
return
multistep
.
ActionContinue
}
func
(
s
*
stepCreateVM
)
Cleanup
(
state
map
[
string
]
interface
{})
{
if
s
.
vmName
==
""
{
return
}
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
.
Say
(
"Unregistering and deleting virtual machine..."
)
if
err
:=
driver
.
VBoxManage
(
"unregistervm"
,
s
.
vmName
,
"--delete"
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error deleting virtual machine: %s"
,
err
))
}
}
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