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
83cf8b23
Commit
83cf8b23
authored
May 04, 2014
by
Rickard von Essen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1120 from rickard-von-essen/vbox-ovf_guest_add
virtualbox-ovf support for guest_additions_mode
parents
035f5dac
c2013bf6
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
136 additions
and
61 deletions
+136
-61
builder/virtualbox/common/guest_addition_modes.go
builder/virtualbox/common/guest_addition_modes.go
+9
-0
builder/virtualbox/common/step_attach_guest_additions.go
builder/virtualbox/common/step_attach_guest_additions.go
+9
-10
builder/virtualbox/common/step_download_guest_additions.go
builder/virtualbox/common/step_download_guest_additions.go
+16
-13
builder/virtualbox/common/step_upload_guest_additions.go
builder/virtualbox/common/step_upload_guest_additions.go
+12
-10
builder/virtualbox/iso/builder.go
builder/virtualbox/iso/builder.go
+17
-14
builder/virtualbox/iso/builder_test.go
builder/virtualbox/iso/builder_test.go
+3
-2
builder/virtualbox/ovf/builder.go
builder/virtualbox/ovf/builder.go
+15
-6
builder/virtualbox/ovf/config.go
builder/virtualbox/ovf/config.go
+55
-6
No files found.
builder/virtualbox/common/guest_addition_modes.go
0 → 100644
View file @
83cf8b23
package
common
// 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"
)
builder/virtualbox/
iso
/step_attach_guest_additions.go
→
builder/virtualbox/
common
/step_attach_guest_additions.go
View file @
83cf8b23
package
iso
package
common
import
(
"fmt"
"github.com/mitchellh/multistep"
vboxcommon
"github.com/mitchellh/packer/builder/virtualbox/common"
"github.com/mitchellh/packer/packer"
"log"
)
...
...
@@ -19,18 +18,18 @@ import (
// vmName string
//
// Produces:
type
stepAttachGuestAdditions
struct
{
attachedPath
string
type
StepAttachGuestAdditions
struct
{
attachedPath
string
GuestAdditionsMode
string
}
func
(
s
*
stepAttachGuestAdditions
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
vboxcommon
.
Driver
)
func
(
s
*
StepAttachGuestAdditions
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmName
:=
state
.
Get
(
"vmName"
)
.
(
string
)
// If we're not attaching the guest additions then just return
if
config
.
GuestAdditionsMode
!=
GuestAdditionsModeAttach
{
if
s
.
GuestAdditionsMode
!=
GuestAdditionsModeAttach
{
log
.
Println
(
"Not attaching guest additions since we're uploading."
)
return
multistep
.
ActionContinue
}
...
...
@@ -61,12 +60,12 @@ func (s *stepAttachGuestAdditions) Run(state multistep.StateBag) multistep.StepA
return
multistep
.
ActionContinue
}
func
(
s
*
s
tepAttachGuestAdditions
)
Cleanup
(
state
multistep
.
StateBag
)
{
func
(
s
*
S
tepAttachGuestAdditions
)
Cleanup
(
state
multistep
.
StateBag
)
{
if
s
.
attachedPath
==
""
{
return
}
driver
:=
state
.
Get
(
"driver"
)
.
(
vboxcommon
.
Driver
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmName
:=
state
.
Get
(
"vmName"
)
.
(
string
)
...
...
builder/virtualbox/
iso
/step_download_guest_additions.go
→
builder/virtualbox/
common
/step_download_guest_additions.go
View file @
83cf8b23
package
iso
package
common
import
(
"bytes"
"fmt"
"github.com/mitchellh/multistep"
vboxcommon
"github.com/mitchellh/packer/builder/virtualbox/common"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"io"
...
...
@@ -28,16 +27,20 @@ type guestAdditionsUrlTemplate struct {
//
// Produces:
// guest_additions_path string - Path to the guest additions.
type
stepDownloadGuestAdditions
struct
{}
type
StepDownloadGuestAdditions
struct
{
GuestAdditionsMode
string
GuestAdditionsURL
string
GuestAdditionsSHA256
string
Tpl
*
packer
.
ConfigTemplate
}
func
(
s
*
s
tepDownloadGuestAdditions
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
func
(
s
*
S
tepDownloadGuestAdditions
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
var
action
multistep
.
StepAction
driver
:=
state
.
Get
(
"driver"
)
.
(
vboxcommon
.
Driver
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
// If we've disabled guest additions, don't download
if
config
.
GuestAdditionsMode
==
GuestAdditionsModeDisable
{
if
s
.
GuestAdditionsMode
==
GuestAdditionsModeDisable
{
log
.
Println
(
"Not downloading guest additions since it is disabled."
)
return
multistep
.
ActionContinue
}
...
...
@@ -59,8 +62,8 @@ func (s *stepDownloadGuestAdditions) Run(state multistep.StateBag) multistep.Ste
// Use provided version or get it from virtualbox.org
var
checksum
string
if
config
.
GuestAdditionsSHA256
!=
""
{
checksum
=
config
.
GuestAdditionsSHA256
if
s
.
GuestAdditionsSHA256
!=
""
{
checksum
=
s
.
GuestAdditionsSHA256
}
else
{
checksum
,
action
=
s
.
downloadAdditionsSHA256
(
state
,
version
,
additionsName
)
if
action
!=
multistep
.
ActionContinue
{
...
...
@@ -69,13 +72,13 @@ func (s *stepDownloadGuestAdditions) Run(state multistep.StateBag) multistep.Ste
}
// Use the provided source (URL or file path) or generate it
url
:=
config
.
GuestAdditionsURL
url
:=
s
.
GuestAdditionsURL
if
url
!=
""
{
tplData
:=
&
guestAdditionsUrlTemplate
{
Version
:
version
,
}
url
,
err
=
config
.
t
pl
.
Process
(
url
,
tplData
)
url
,
err
=
s
.
T
pl
.
Process
(
url
,
tplData
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error preparing guest additions url: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
...
...
@@ -110,9 +113,9 @@ func (s *stepDownloadGuestAdditions) Run(state multistep.StateBag) multistep.Ste
return
downStep
.
Run
(
state
)
}
func
(
s
*
s
tepDownloadGuestAdditions
)
Cleanup
(
state
multistep
.
StateBag
)
{}
func
(
s
*
S
tepDownloadGuestAdditions
)
Cleanup
(
state
multistep
.
StateBag
)
{}
func
(
s
*
s
tepDownloadGuestAdditions
)
downloadAdditionsSHA256
(
state
multistep
.
StateBag
,
additionsVersion
string
,
additionsName
string
)
(
string
,
multistep
.
StepAction
)
{
func
(
s
*
S
tepDownloadGuestAdditions
)
downloadAdditionsSHA256
(
state
multistep
.
StateBag
,
additionsVersion
string
,
additionsName
string
)
(
string
,
multistep
.
StepAction
)
{
// First things first, we get the list of checksums for the files available
// for this version.
checksumsUrl
:=
fmt
.
Sprintf
(
...
...
builder/virtualbox/
iso
/step_upload_guest_additions.go
→
builder/virtualbox/
common
/step_upload_guest_additions.go
View file @
83cf8b23
package
iso
package
common
import
(
"fmt"
"github.com/mitchellh/multistep"
vboxcommon
"github.com/mitchellh/packer/builder/virtualbox/common"
"github.com/mitchellh/packer/packer"
"log"
"os"
...
...
@@ -14,16 +13,19 @@ type guestAdditionsPathTemplate struct {
}
// This step uploads the guest additions ISO to the VM.
type
stepUploadGuestAdditions
struct
{}
type
StepUploadGuestAdditions
struct
{
GuestAdditionsMode
string
GuestAdditionsPath
string
Tpl
*
packer
.
ConfigTemplate
}
func
(
s
*
s
tepUploadGuestAdditions
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
func
(
s
*
S
tepUploadGuestAdditions
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
comm
:=
state
.
Get
(
"communicator"
)
.
(
packer
.
Communicator
)
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
vboxcommon
.
Driver
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
// If we're attaching then don't do this, since we attached.
if
config
.
GuestAdditionsMode
!=
GuestAdditionsModeUpload
{
if
s
.
GuestAdditionsMode
!=
GuestAdditionsModeUpload
{
log
.
Println
(
"Not uploading guest additions since mode is not upload"
)
return
multistep
.
ActionContinue
}
...
...
@@ -47,7 +49,7 @@ func (s *stepUploadGuestAdditions) Run(state multistep.StateBag) multistep.StepA
Version
:
version
,
}
config
.
GuestAdditionsPath
,
err
=
config
.
tpl
.
Process
(
config
.
GuestAdditionsPath
,
tplData
)
s
.
GuestAdditionsPath
,
err
=
s
.
Tpl
.
Process
(
s
.
GuestAdditionsPath
,
tplData
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error preparing guest additions path: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
...
...
@@ -56,7 +58,7 @@ func (s *stepUploadGuestAdditions) Run(state multistep.StateBag) multistep.StepA
}
ui
.
Say
(
"Uploading VirtualBox guest additions ISO..."
)
if
err
:=
comm
.
Upload
(
config
.
GuestAdditionsPath
,
f
);
err
!=
nil
{
if
err
:=
comm
.
Upload
(
s
.
GuestAdditionsPath
,
f
);
err
!=
nil
{
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error uploading guest additions: %s"
,
err
))
return
multistep
.
ActionHalt
}
...
...
@@ -64,4 +66,4 @@ func (s *stepUploadGuestAdditions) Run(state multistep.StateBag) multistep.StepA
return
multistep
.
ActionContinue
}
func
(
s
*
s
tepUploadGuestAdditions
)
Cleanup
(
state
multistep
.
StateBag
)
{}
func
(
s
*
S
tepUploadGuestAdditions
)
Cleanup
(
state
multistep
.
StateBag
)
{}
builder/virtualbox/iso/builder.go
View file @
83cf8b23
...
...
@@ -13,14 +13,6 @@ 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
...
...
@@ -220,9 +212,9 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
validMode
:=
false
validModes
:=
[]
string
{
GuestAdditionsModeDisable
,
GuestAdditionsModeAttach
,
GuestAdditionsModeUpload
,
vboxcommon
.
GuestAdditionsModeDisable
,
vboxcommon
.
GuestAdditionsModeAttach
,
vboxcommon
.
GuestAdditionsModeUpload
,
}
for
_
,
mode
:=
range
validModes
{
...
...
@@ -269,7 +261,12 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
}
steps
:=
[]
multistep
.
Step
{
new
(
stepDownloadGuestAdditions
),
&
vboxcommon
.
StepDownloadGuestAdditions
{
GuestAdditionsMode
:
b
.
config
.
GuestAdditionsMode
,
GuestAdditionsURL
:
b
.
config
.
GuestAdditionsURL
,
GuestAdditionsSHA256
:
b
.
config
.
GuestAdditionsSHA256
,
Tpl
:
b
.
config
.
tpl
,
},
&
common
.
StepDownload
{
Checksum
:
b
.
config
.
ISOChecksum
,
ChecksumType
:
b
.
config
.
ISOChecksumType
,
...
...
@@ -289,7 +286,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
new
(
stepCreateVM
),
new
(
stepCreateDisk
),
new
(
stepAttachISO
),
new
(
stepAttachGuestAdditions
),
&
vboxcommon
.
StepAttachGuestAdditions
{
GuestAdditionsMode
:
b
.
config
.
GuestAdditionsMode
,
},
new
(
vboxcommon
.
StepAttachFloppy
),
&
vboxcommon
.
StepForwardSSH
{
GuestPort
:
b
.
config
.
SSHPort
,
...
...
@@ -313,7 +312,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
vboxcommon
.
StepUploadVersion
{
Path
:
b
.
config
.
VBoxVersionFile
,
},
new
(
stepUploadGuestAdditions
),
&
vboxcommon
.
StepUploadGuestAdditions
{
GuestAdditionsMode
:
b
.
config
.
GuestAdditionsMode
,
GuestAdditionsPath
:
b
.
config
.
GuestAdditionsPath
,
Tpl
:
b
.
config
.
tpl
,
},
new
(
common
.
StepProvision
),
&
vboxcommon
.
StepShutdown
{
Command
:
b
.
config
.
ShutdownCommand
,
...
...
builder/virtualbox/iso/builder_test.go
View file @
83cf8b23
package
iso
import
(
"github.com/mitchellh/packer/builder/virtualbox/common"
"github.com/mitchellh/packer/packer"
"reflect"
"testing"
...
...
@@ -37,7 +38,7 @@ func TestBuilderPrepare_Defaults(t *testing.T) {
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
if
b
.
config
.
GuestAdditionsMode
!=
GuestAdditionsModeUpload
{
if
b
.
config
.
GuestAdditionsMode
!=
common
.
GuestAdditionsModeUpload
{
t
.
Errorf
(
"bad guest additions mode: %s"
,
b
.
config
.
GuestAdditionsMode
)
}
...
...
@@ -111,7 +112,7 @@ func TestBuilderPrepare_GuestAdditionsMode(t *testing.T) {
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
if
b
.
config
.
GuestAdditionsMode
!=
GuestAdditionsModeAttach
{
if
b
.
config
.
GuestAdditionsMode
!=
common
.
GuestAdditionsModeAttach
{
t
.
Fatalf
(
"bad: %s"
,
b
.
config
.
GuestAdditionsMode
)
}
...
...
builder/virtualbox/ovf/builder.go
View file @
83cf8b23
...
...
@@ -42,6 +42,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
state
:=
new
(
multistep
.
BasicStateBag
)
state
.
Put
(
"config"
,
b
.
config
)
state
.
Put
(
"driver"
,
driver
)
state
.
Put
(
"cache"
,
cache
)
state
.
Put
(
"hook"
,
hook
)
state
.
Put
(
"ui"
,
ui
)
...
...
@@ -55,14 +56,20 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
common
.
StepCreateFloppy
{
Files
:
b
.
config
.
FloppyFiles
,
},
&
vboxcommon
.
StepDownloadGuestAdditions
{
GuestAdditionsMode
:
b
.
config
.
GuestAdditionsMode
,
GuestAdditionsURL
:
b
.
config
.
GuestAdditionsURL
,
GuestAdditionsSHA256
:
b
.
config
.
GuestAdditionsSHA256
,
Tpl
:
b
.
config
.
tpl
,
},
&
StepImport
{
Name
:
b
.
config
.
VMName
,
SourcePath
:
b
.
config
.
SourcePath
,
ImportOpts
:
b
.
config
.
ImportOpts
,
},
/*
new(stepAttachGuestAdditions)
,
*/
&
vboxcommon
.
StepAttachGuestAdditions
{
GuestAdditionsMode
:
b
.
config
.
GuestAdditionsMode
,
},
new
(
vboxcommon
.
StepAttachFloppy
),
&
vboxcommon
.
StepForwardSSH
{
GuestPort
:
b
.
config
.
SSHPort
,
...
...
@@ -85,9 +92,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
vboxcommon
.
StepUploadVersion
{
Path
:
b
.
config
.
VBoxVersionFile
,
},
/*
new(stepUploadGuestAdditions),
*/
&
vboxcommon
.
StepUploadGuestAdditions
{
GuestAdditionsMode
:
b
.
config
.
GuestAdditionsMode
,
GuestAdditionsPath
:
b
.
config
.
GuestAdditionsPath
,
Tpl
:
b
.
config
.
tpl
,
},
new
(
common
.
StepProvision
),
&
vboxcommon
.
StepShutdown
{
Command
:
b
.
config
.
ShutdownCommand
,
...
...
builder/virtualbox/ovf/config.go
View file @
83cf8b23
...
...
@@ -3,6 +3,7 @@ package ovf
import
(
"fmt"
"os"
"strings"
vboxcommon
"github.com/mitchellh/packer/builder/virtualbox/common"
"github.com/mitchellh/packer/common"
...
...
@@ -23,9 +24,13 @@ type Config struct {
vboxcommon
.
VBoxManagePostConfig
`mapstructure:",squash"`
vboxcommon
.
VBoxVersionConfig
`mapstructure:",squash"`
SourcePath
string
`mapstructure:"source_path"`
VMName
string
`mapstructure:"vm_name"`
ImportOpts
string
`mapstructure:"import_opts"`
SourcePath
string
`mapstructure:"source_path"`
GuestAdditionsMode
string
`mapstructure:"guest_additions_mode"`
GuestAdditionsPath
string
`mapstructure:"guest_additions_path"`
GuestAdditionsURL
string
`mapstructure:"guest_additions_url"`
GuestAdditionsSHA256
string
`mapstructure:"guest_additions_sha256"`
VMName
string
`mapstructure:"vm_name"`
ImportOpts
string
`mapstructure:"import_opts"`
tpl
*
packer
.
ConfigTemplate
}
...
...
@@ -44,6 +49,13 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
c
.
tpl
.
UserVars
=
c
.
PackerUserVars
// Defaults
if
c
.
GuestAdditionsMode
==
""
{
c
.
GuestAdditionsMode
=
"upload"
}
if
c
.
GuestAdditionsPath
==
""
{
c
.
GuestAdditionsPath
=
"VBoxGuestAdditions.iso"
}
if
c
.
VMName
==
""
{
c
.
VMName
=
fmt
.
Sprintf
(
"packer-%s-{{timestamp}}"
,
c
.
PackerBuildName
)
}
...
...
@@ -62,9 +74,11 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
VBoxVersionConfig
.
Prepare
(
c
.
tpl
)
...
)
templates
:=
map
[
string
]
*
string
{
"source_path"
:
&
c
.
SourcePath
,
"vm_name"
:
&
c
.
VMName
,
"import_opts"
:
&
c
.
ImportOpts
,
"guest_additions_mode"
:
&
c
.
GuestAdditionsMode
,
"guest_additions_sha256"
:
&
c
.
GuestAdditionsSHA256
,
"source_path"
:
&
c
.
SourcePath
,
"vm_name"
:
&
c
.
VMName
,
"import_opts"
:
&
c
.
ImportOpts
,
}
for
n
,
ptr
:=
range
templates
{
...
...
@@ -85,6 +99,41 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
}
}
validates
:=
map
[
string
]
*
string
{
"guest_additions_path"
:
&
c
.
GuestAdditionsPath
,
"guest_additions_url"
:
&
c
.
GuestAdditionsURL
,
}
for
n
,
ptr
:=
range
validates
{
if
err
:=
c
.
tpl
.
Validate
(
*
ptr
);
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error parsing %s: %s"
,
n
,
err
))
}
}
validMode
:=
false
validModes
:=
[]
string
{
vboxcommon
.
GuestAdditionsModeDisable
,
vboxcommon
.
GuestAdditionsModeAttach
,
vboxcommon
.
GuestAdditionsModeUpload
,
}
for
_
,
mode
:=
range
validModes
{
if
c
.
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
c
.
GuestAdditionsSHA256
!=
""
{
c
.
GuestAdditionsSHA256
=
strings
.
ToLower
(
c
.
GuestAdditionsSHA256
)
}
// Warnings
var
warnings
[]
string
if
c
.
ShutdownCommand
==
""
{
...
...
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