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
aa95caa2
Commit
aa95caa2
authored
Nov 02, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/virtualbox: allow disabling guest addition uploading
parent
25465347
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
4 deletions
+72
-4
builder/virtualbox/builder.go
builder/virtualbox/builder.go
+33
-1
builder/virtualbox/builder_test.go
builder/virtualbox/builder_test.go
+36
-0
builder/virtualbox/step_attach_guest_additions.go
builder/virtualbox/step_attach_guest_additions.go
+1
-1
builder/virtualbox/step_upload_guest_additions.go
builder/virtualbox/step_upload_guest_additions.go
+2
-2
No files found.
builder/virtualbox/builder.go
View file @
aa95caa2
...
...
@@ -16,6 +16,14 @@ import (
const
BuilderId
=
"mitchellh.virtualbox"
// These are the different valid mode values for "guest_additions_mode" which
// determine how guest additions are delivered to the guest.
const
(
GuestAdditionsModeDisable
string
=
"disable"
GuestAdditionsModeAttach
=
"attach"
GuestAdditionsModeUpload
=
"upload"
)
type
Builder
struct
{
config
config
runner
multistep
.
Runner
...
...
@@ -28,7 +36,7 @@ type config struct {
DiskSize
uint
`mapstructure:"disk_size"`
FloppyFiles
[]
string
`mapstructure:"floppy_files"`
Format
string
`mapstructure:"format"`
GuestAdditions
Attach
bool
`mapstructure:"guest_additions_attach
"`
GuestAdditions
Mode
string
`mapstructure:"guest_additions_mode
"`
GuestAdditionsPath
string
`mapstructure:"guest_additions_path"`
GuestAdditionsURL
string
`mapstructure:"guest_additions_url"`
GuestAdditionsSHA256
string
`mapstructure:"guest_additions_sha256"`
...
...
@@ -87,6 +95,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
b
.
config
.
FloppyFiles
=
make
([]
string
,
0
)
}
if
b
.
config
.
GuestAdditionsMode
==
""
{
b
.
config
.
GuestAdditionsMode
=
"upload"
}
if
b
.
config
.
GuestAdditionsPath
==
""
{
b
.
config
.
GuestAdditionsPath
=
"VBoxGuestAdditions.iso"
}
...
...
@@ -145,6 +157,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
// Errors
templates
:=
map
[
string
]
*
string
{
"guest_additions_mode"
:
&
b
.
config
.
GuestAdditionsMode
,
"guest_additions_sha256"
:
&
b
.
config
.
GuestAdditionsSHA256
,
"guest_os_type"
:
&
b
.
config
.
GuestOSType
,
"hard_drive_interface"
:
&
b
.
config
.
HardDriveInterface
,
...
...
@@ -264,6 +277,25 @@ func (b *Builder) Prepare(raws ...interface{}) error {
}
}
validMode
:=
false
validModes
:=
[]
string
{
GuestAdditionsModeDisable
,
GuestAdditionsModeAttach
,
GuestAdditionsModeUpload
,
}
for
_
,
mode
:=
range
validModes
{
if
b
.
config
.
GuestAdditionsMode
==
mode
{
validMode
=
true
break
}
}
if
!
validMode
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"guest_additions_mode is invalid. Must be one of: %v"
,
validModes
))
}
if
b
.
config
.
GuestAdditionsSHA256
!=
""
{
b
.
config
.
GuestAdditionsSHA256
=
strings
.
ToLower
(
b
.
config
.
GuestAdditionsSHA256
)
}
...
...
builder/virtualbox/builder_test.go
View file @
aa95caa2
...
...
@@ -65,6 +65,10 @@ func TestBuilderPrepare_Defaults(t *testing.T) {
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
if
b
.
config
.
GuestAdditionsMode
!=
GuestAdditionsModeUpload
{
t
.
Errorf
(
"bad guest additions mode: %s"
,
b
.
config
.
GuestAdditionsMode
)
}
if
b
.
config
.
GuestOSType
!=
"Other"
{
t
.
Errorf
(
"bad guest OS type: %s"
,
b
.
config
.
GuestOSType
)
}
...
...
@@ -178,6 +182,38 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
}
}
func
TestBuilderPrepare_GuestAdditionsMode
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
// test default mode
delete
(
config
,
"guest_additions_mode"
)
err
:=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"bad err: %s"
,
err
)
}
// Test another mode
config
[
"guest_additions_mode"
]
=
"attach"
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
if
b
.
config
.
GuestAdditionsMode
!=
GuestAdditionsModeAttach
{
t
.
Fatalf
(
"bad: %s"
,
b
.
config
.
GuestAdditionsMode
)
}
// Test bad mode
config
[
"guest_additions_mode"
]
=
"teleport"
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Fatal
(
"should error"
)
}
}
func
TestBuilderPrepare_GuestAdditionsPath
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
...
...
builder/virtualbox/step_attach_guest_additions.go
View file @
aa95caa2
...
...
@@ -30,7 +30,7 @@ func (s *stepAttachGuestAdditions) Run(state multistep.StateBag) multistep.StepA
vmName
:=
state
.
Get
(
"vmName"
)
.
(
string
)
// If we're not attaching the guest additions then just return
if
!
config
.
GuestAdditions
Attach
{
if
config
.
GuestAdditionsMode
!=
GuestAdditionsMode
Attach
{
log
.
Println
(
"Not attaching guest additions since we're uploading."
)
return
multistep
.
ActionContinue
}
...
...
builder/virtualbox/step_upload_guest_additions.go
View file @
aa95caa2
...
...
@@ -23,8 +23,8 @@ func (s *stepUploadGuestAdditions) Run(state multistep.StateBag) multistep.StepA
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
// If we're attaching then don't do this, since we attached.
if
config
.
GuestAdditions
Attach
{
log
.
Println
(
"Not uploading guest additions since
we're attaching.
"
)
if
config
.
GuestAdditions
Mode
!=
GuestAdditionsModeUpload
{
log
.
Println
(
"Not uploading guest additions since
mode is not upload
"
)
return
multistep
.
ActionContinue
}
...
...
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