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
865f1975
Commit
865f1975
authored
Sep 18, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/virtualbox: support attaching guest additions [GH-405]
parent
f85c9e43
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
96 additions
and
0 deletions
+96
-0
CHANGELOG.md
CHANGELOG.md
+2
-0
builder/virtualbox/builder.go
builder/virtualbox/builder.go
+2
-0
builder/virtualbox/step_attach_guest_additions.go
builder/virtualbox/step_attach_guest_additions.go
+81
-0
builder/virtualbox/step_upload_guest_additions.go
builder/virtualbox/step_upload_guest_additions.go
+7
-0
website/source/docs/builders/virtualbox.html.markdown
website/source/docs/builders/virtualbox.html.markdown
+4
-0
No files found.
CHANGELOG.md
View file @
865f1975
...
...
@@ -2,6 +2,8 @@
FEATURES:
*
builders/virtualbox: Guest additions can be attached rather than uploaded,
easier to handle for Windows guests. [GH-405]
*
provisioner/chef-solo: Ability to specify a custom Chef configuration
template.
*
provisioner/chef-solo: Roles and data bags support. [GH-348]
...
...
builder/virtualbox/builder.go
View file @
865f1975
...
...
@@ -28,6 +28,7 @@ type config struct {
DiskSize
uint
`mapstructure:"disk_size"`
FloppyFiles
[]
string
`mapstructure:"floppy_files"`
Format
string
`mapstructure:"format"`
GuestAdditionsAttach
bool
`mapstructure:"guest_additions_attach"`
GuestAdditionsPath
string
`mapstructure:"guest_additions_path"`
GuestAdditionsURL
string
`mapstructure:"guest_additions_url"`
GuestAdditionsSHA256
string
`mapstructure:"guest_additions_sha256"`
...
...
@@ -361,6 +362,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
new
(
stepCreateVM
),
new
(
stepCreateDisk
),
new
(
stepAttachISO
),
new
(
stepAttachGuestAdditions
),
new
(
stepAttachFloppy
),
new
(
stepForwardSSH
),
new
(
stepVBoxManage
),
...
...
builder/virtualbox/step_attach_guest_additions.go
0 → 100644
View file @
865f1975
package
virtualbox
import
(
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
)
// This step attaches the VirtualBox guest additions as a inserted CD onto
// the virtual machine.
//
// Uses:
// config *config
// driver Driver
// guest_additions_path string
// ui packer.Ui
// vmName string
//
// Produces:
type
stepAttachGuestAdditions
struct
{
attachedPath
string
}
func
(
s
*
stepAttachGuestAdditions
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
guestAdditionsPath
:=
state
.
Get
(
"guest_additions_path"
)
.
(
string
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmName
:=
state
.
Get
(
"vmName"
)
.
(
string
)
// If we're not attaching the guest additions then just return
if
!
config
.
GuestAdditionsAttach
{
log
.
Println
(
"Not attaching guest additions since we're uploading."
)
return
multistep
.
ActionContinue
}
// Attach the guest additions to the computer
log
.
Println
(
"Attaching guest additions ISO onto IDE controller..."
)
command
:=
[]
string
{
"storageattach"
,
vmName
,
"--storagectl"
,
"IDE Controller"
,
"--port"
,
"1"
,
"--device"
,
"0"
,
"--type"
,
"dvddrive"
,
"--medium"
,
guestAdditionsPath
,
}
if
err
:=
driver
.
VBoxManage
(
command
...
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error attaching guest additions: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
// Track the path so that we can unregister it from VirtualBox later
s
.
attachedPath
=
guestAdditionsPath
return
multistep
.
ActionContinue
}
func
(
s
*
stepAttachGuestAdditions
)
Cleanup
(
state
multistep
.
StateBag
)
{
if
s
.
attachedPath
==
""
{
return
}
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmName
:=
state
.
Get
(
"vmName"
)
.
(
string
)
command
:=
[]
string
{
"storageattach"
,
vmName
,
"--storagectl"
,
"IDE Controller"
,
"--port"
,
"1"
,
"--device"
,
"0"
,
"--medium"
,
"none"
,
}
if
err
:=
driver
.
VBoxManage
(
command
...
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error unregistering guest additions: %s"
,
err
))
}
}
builder/virtualbox/step_upload_guest_additions.go
View file @
865f1975
...
...
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
"os"
)
...
...
@@ -21,6 +22,12 @@ func (s *stepUploadGuestAdditions) Run(state multistep.StateBag) multistep.StepA
guestAdditionsPath
:=
state
.
Get
(
"guest_additions_path"
)
.
(
string
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
// If we're attaching then don't do this, since we attached.
if
config
.
GuestAdditionsAttach
{
log
.
Println
(
"Not uploading guest additions since we're attaching."
)
return
multistep
.
ActionContinue
}
version
,
err
:=
driver
.
Version
()
if
err
!=
nil
{
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error reading version for guest additions upload: %s"
,
err
))
...
...
website/source/docs/builders/virtualbox.html.markdown
View file @
865f1975
...
...
@@ -85,6 +85,10 @@ Optional:
*
`format`
(string) - Either "ovf" or "ova", this specifies the output
format of the exported virtual machine. This defaults to "ovf".
*
`guest_additions_attach`
(bool) - If this is true (defaults to "false"),
the guest additions ISO will be attached to the virtual machine as a CD
rather than uploaded as a raw ISO.
*
`guest_additions_path`
(string) - The path on the guest virtual machine
where the VirtualBox guest additions ISO will be uploaded. By default this
is "VBoxGuestAdditions.iso" which should upload into the login directory
...
...
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