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 {
}
type
config
struct
{
BootCommand
[]
string
`mapstructure:"boot_command"`
BootWait
time
.
Duration
``
DiskSize
uint
`mapstructure:"disk_size"`
GuestOSType
string
`mapstructure:"guest_os_type"`
HTTPDir
string
`mapstructure:"http_directory"`
HTTPPortMin
uint
`mapstructure:"http_port_min"`
HTTPPortMax
uint
`mapstructure:"http_port_max"`
ISOMD5
string
`mapstructure:"iso_md5"`
ISOUrl
string
`mapstructure:"iso_url"`
OutputDir
string
`mapstructure:"output_directory"`
ShutdownCommand
string
`mapstructure:"shutdown_command"`
ShutdownTimeout
time
.
Duration
``
SSHHostPortMin
uint
`mapstructure:"ssh_host_port_min"`
SSHHostPortMax
uint
`mapstructure:"ssh_host_port_max"`
SSHPassword
string
`mapstructure:"ssh_password"`
SSHPort
uint
`mapstructure:"ssh_port"`
SSHUser
string
`mapstructure:"ssh_username"`
SSHWaitTimeout
time
.
Duration
``
VBoxVersionFile
string
`mapstructure:"virtualbox_version_file"`
VBoxManage
[][]
string
`mapstructure:"vboxmanage"`
VMName
string
`mapstructure:"vm_name"`
BootCommand
[]
string
`mapstructure:"boot_command"`
BootWait
time
.
Duration
``
DiskSize
uint
`mapstructure:"disk_size"`
GuestAdditionsPath
string
`mapstructure:"guest_additions_path"`
GuestOSType
string
`mapstructure:"guest_os_type"`
HTTPDir
string
`mapstructure:"http_directory"`
HTTPPortMin
uint
`mapstructure:"http_port_min"`
HTTPPortMax
uint
`mapstructure:"http_port_max"`
ISOMD5
string
`mapstructure:"iso_md5"`
ISOUrl
string
`mapstructure:"iso_url"`
OutputDir
string
`mapstructure:"output_directory"`
ShutdownCommand
string
`mapstructure:"shutdown_command"`
ShutdownTimeout
time
.
Duration
``
SSHHostPortMin
uint
`mapstructure:"ssh_host_port_min"`
SSHHostPortMax
uint
`mapstructure:"ssh_host_port_max"`
SSHPassword
string
`mapstructure:"ssh_password"`
SSHPort
uint
`mapstructure:"ssh_port"`
SSHUser
string
`mapstructure:"ssh_username"`
SSHWaitTimeout
time
.
Duration
``
VBoxVersionFile
string
`mapstructure:"virtualbox_version_file"`
VBoxManage
[][]
string
`mapstructure:"vboxmanage"`
VMName
string
`mapstructure:"vm_name"`
PackerDebug
bool
`mapstructure:"packer_debug"`
...
...
@@ -68,6 +69,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
b
.
config
.
DiskSize
=
40000
}
if
b
.
config
.
GuestAdditionsPath
==
""
{
b
.
config
.
GuestAdditionsPath
=
"VBoxGuestAdditions.iso"
}
if
b
.
config
.
GuestOSType
==
""
{
b
.
config
.
GuestOSType
=
"Other"
}
...
...
@@ -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
)
{
steps
:=
[]
multistep
.
Step
{
new
(
stepDownloadGuestAdditions
),
new
(
stepDownloadISO
),
new
(
stepPrepareOutputDir
),
new
(
stepHTTPServer
),
...
...
builder/virtualbox/builder_test.go
View file @
921770b6
...
...
@@ -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
)
{
var
b
Builder
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:
break
DownloadWaitLoop
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
)
:
if
_
,
ok
:=
state
[
multistep
.
StateCancelled
];
ok
{
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