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
921770b6
Commit
921770b6
authored
Jun 23, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/virtualbox: Download guest additions for the VM
parent
e91421b1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
136 additions
and
22 deletions
+136
-22
builder/virtualbox/builder.go
builder/virtualbox/builder.go
+27
-21
builder/virtualbox/builder_test.go
builder/virtualbox/builder_test.go
+26
-0
builder/virtualbox/step_download_guest_additions.go
builder/virtualbox/step_download_guest_additions.go
+82
-0
builder/virtualbox/step_download_iso.go
builder/virtualbox/step_download_iso.go
+1
-1
No files found.
builder/virtualbox/builder.go
View file @
921770b6
...
@@ -25,27 +25,28 @@ type Builder struct {
...
@@ -25,27 +25,28 @@ type Builder struct {
}
}
type
config
struct
{
type
config
struct
{
BootCommand
[]
string
`mapstructure:"boot_command"`
BootCommand
[]
string
`mapstructure:"boot_command"`
BootWait
time
.
Duration
``
BootWait
time
.
Duration
``
DiskSize
uint
`mapstructure:"disk_size"`
DiskSize
uint
`mapstructure:"disk_size"`
GuestOSType
string
`mapstructure:"guest_os_type"`
GuestAdditionsPath
string
`mapstructure:"guest_additions_path"`
HTTPDir
string
`mapstructure:"http_directory"`
GuestOSType
string
`mapstructure:"guest_os_type"`
HTTPPortMin
uint
`mapstructure:"http_port_min"`
HTTPDir
string
`mapstructure:"http_directory"`
HTTPPortMax
uint
`mapstructure:"http_port_max"`
HTTPPortMin
uint
`mapstructure:"http_port_min"`
ISOMD5
string
`mapstructure:"iso_md5"`
HTTPPortMax
uint
`mapstructure:"http_port_max"`
ISOUrl
string
`mapstructure:"iso_url"`
ISOMD5
string
`mapstructure:"iso_md5"`
OutputDir
string
`mapstructure:"output_directory"`
ISOUrl
string
`mapstructure:"iso_url"`
ShutdownCommand
string
`mapstructure:"shutdown_command"`
OutputDir
string
`mapstructure:"output_directory"`
ShutdownTimeout
time
.
Duration
``
ShutdownCommand
string
`mapstructure:"shutdown_command"`
SSHHostPortMin
uint
`mapstructure:"ssh_host_port_min"`
ShutdownTimeout
time
.
Duration
``
SSHHostPortMax
uint
`mapstructure:"ssh_host_port_max"`
SSHHostPortMin
uint
`mapstructure:"ssh_host_port_min"`
SSHPassword
string
`mapstructure:"ssh_password"`
SSHHostPortMax
uint
`mapstructure:"ssh_host_port_max"`
SSHPort
uint
`mapstructure:"ssh_port"`
SSHPassword
string
`mapstructure:"ssh_password"`
SSHUser
string
`mapstructure:"ssh_username"`
SSHPort
uint
`mapstructure:"ssh_port"`
SSHWaitTimeout
time
.
Duration
``
SSHUser
string
`mapstructure:"ssh_username"`
VBoxVersionFile
string
`mapstructure:"virtualbox_version_file"`
SSHWaitTimeout
time
.
Duration
``
VBoxManage
[][]
string
`mapstructure:"vboxmanage"`
VBoxVersionFile
string
`mapstructure:"virtualbox_version_file"`
VMName
string
`mapstructure:"vm_name"`
VBoxManage
[][]
string
`mapstructure:"vboxmanage"`
VMName
string
`mapstructure:"vm_name"`
PackerDebug
bool
`mapstructure:"packer_debug"`
PackerDebug
bool
`mapstructure:"packer_debug"`
...
@@ -68,6 +69,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
...
@@ -68,6 +69,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
b
.
config
.
DiskSize
=
40000
b
.
config
.
DiskSize
=
40000
}
}
if
b
.
config
.
GuestAdditionsPath
==
""
{
b
.
config
.
GuestAdditionsPath
=
"VBoxGuestAdditions.iso"
}
if
b
.
config
.
GuestOSType
==
""
{
if
b
.
config
.
GuestOSType
==
""
{
b
.
config
.
GuestOSType
=
"Other"
b
.
config
.
GuestOSType
=
"Other"
}
}
...
@@ -206,6 +211,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
...
@@ -206,6 +211,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
func
(
b
*
Builder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
(
packer
.
Artifact
,
error
)
{
func
(
b
*
Builder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
(
packer
.
Artifact
,
error
)
{
steps
:=
[]
multistep
.
Step
{
steps
:=
[]
multistep
.
Step
{
new
(
stepDownloadGuestAdditions
),
new
(
stepDownloadISO
),
new
(
stepDownloadISO
),
new
(
stepPrepareOutputDir
),
new
(
stepPrepareOutputDir
),
new
(
stepHTTPServer
),
new
(
stepHTTPServer
),
...
...
builder/virtualbox/builder_test.go
View file @
921770b6
...
@@ -102,6 +102,32 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
...
@@ -102,6 +102,32 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
}
}
}
}
func
TestBuilderPrepare_GuestAdditionsPath
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
delete
(
config
,
"disk_size"
)
err
:=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"bad err: %s"
,
err
)
}
if
b
.
config
.
GuestAdditionsPath
!=
"VBoxGuestAdditions.iso"
{
t
.
Fatalf
(
"bad: %s"
,
b
.
config
.
GuestAdditionsPath
)
}
config
[
"guest_additions_path"
]
=
"foo"
b
=
Builder
{}
err
=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
if
b
.
config
.
GuestAdditionsPath
!=
"foo"
{
t
.
Fatalf
(
"bad size: %s"
,
b
.
config
.
GuestAdditionsPath
)
}
}
func
TestBuilderPrepare_HTTPPort
(
t
*
testing
.
T
)
{
func
TestBuilderPrepare_HTTPPort
(
t
*
testing
.
T
)
{
var
b
Builder
var
b
Builder
config
:=
testConfig
()
config
:=
testConfig
()
...
...
builder/virtualbox/step_download_guest_additions.go
0 → 100644
View file @
921770b6
package
virtualbox
import
(
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/builder/common"
"github.com/mitchellh/packer/packer"
"log"
"time"
)
// This step uploads a file containing the VirtualBox version, which
// can be useful for various provisioning reasons.
//
// Produces:
// guest_additions_path string - Path to the guest additions.
type
stepDownloadGuestAdditions
struct
{}
func
(
s
*
stepDownloadGuestAdditions
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
cache
:=
state
[
"cache"
]
.
(
packer
.
Cache
)
driver
:=
state
[
"driver"
]
.
(
Driver
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
version
,
err
:=
driver
.
Version
()
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error reading version for guest additions download: %s"
,
err
)
return
multistep
.
ActionHalt
}
url
:=
fmt
.
Sprintf
(
"http://download.virtualbox.org/virtualbox/%s/VBoxGuestAdditions_%s.iso"
,
version
,
version
)
log
.
Printf
(
"Guest additions URL: %s"
,
url
)
log
.
Printf
(
"Acquiring lock to download the guest additions ISO."
)
cachePath
:=
cache
.
Lock
(
url
)
defer
cache
.
Unlock
(
url
)
downloadConfig
:=
&
common
.
DownloadConfig
{
Url
:
url
,
TargetPath
:
cachePath
,
Hash
:
nil
,
}
download
:=
common
.
NewDownloadClient
(
downloadConfig
)
downloadCompleteCh
:=
make
(
chan
error
,
1
)
go
func
()
{
ui
.
Say
(
"Downloading VirtualBox guest additions. Progress will be shown periodically."
)
cachePath
,
err
=
download
.
Get
()
downloadCompleteCh
<-
err
}()
progressTicker
:=
time
.
NewTicker
(
5
*
time
.
Second
)
defer
progressTicker
.
Stop
()
DownloadWaitLoop
:
for
{
select
{
case
err
:=
<-
downloadCompleteCh
:
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error downloading guest additions: %s"
,
err
)
return
multistep
.
ActionHalt
}
break
DownloadWaitLoop
case
<-
progressTicker
.
C
:
ui
.
Message
(
fmt
.
Sprintf
(
"Download progress: %d%%"
,
download
.
PercentProgress
()))
case
<-
time
.
After
(
1
*
time
.
Second
)
:
if
_
,
ok
:=
state
[
multistep
.
StateCancelled
];
ok
{
ui
.
Say
(
"Interrupt received. Cancelling download..."
)
return
multistep
.
ActionHalt
}
}
}
state
[
"guest_additions_path"
]
=
cachePath
return
multistep
.
ActionContinue
}
func
(
s
*
stepDownloadGuestAdditions
)
Cleanup
(
state
map
[
string
]
interface
{})
{}
builder/virtualbox/step_download_iso.go
View file @
921770b6
...
@@ -78,7 +78,7 @@ DownloadWaitLoop:
...
@@ -78,7 +78,7 @@ DownloadWaitLoop:
break
DownloadWaitLoop
break
DownloadWaitLoop
case
<-
progressTicker
.
C
:
case
<-
progressTicker
.
C
:
ui
.
Say
(
fmt
.
Sprintf
(
"Download progress: %d%%"
,
download
.
PercentProgress
()))
ui
.
Message
(
fmt
.
Sprintf
(
"Download progress: %d%%"
,
download
.
PercentProgress
()))
case
<-
time
.
After
(
1
*
time
.
Second
)
:
case
<-
time
.
After
(
1
*
time
.
Second
)
:
if
_
,
ok
:=
state
[
multistep
.
StateCancelled
];
ok
{
if
_
,
ok
:=
state
[
multistep
.
StateCancelled
];
ok
{
ui
.
Say
(
"Interrupt received. Cancelling download..."
)
ui
.
Say
(
"Interrupt received. Cancelling download..."
)
...
...
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