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
5f1c5972
Commit
5f1c5972
authored
Dec 22, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/virtualbox: StepUploadVersion
parent
5feb7bce
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
92 additions
and
60 deletions
+92
-60
builder/virtualbox/common/step_upload_version.go
builder/virtualbox/common/step_upload_version.go
+9
-9
builder/virtualbox/common/vbox_version_config.go
builder/virtualbox/common/vbox_version_config.go
+31
-0
builder/virtualbox/common/vbox_version_config_test.go
builder/virtualbox/common/vbox_version_config_test.go
+33
-0
builder/virtualbox/iso/builder.go
builder/virtualbox/iso/builder.go
+14
-16
builder/virtualbox/iso/builder_test.go
builder/virtualbox/iso/builder_test.go
+0
-34
builder/virtualbox/ovf/builder.go
builder/virtualbox/ovf/builder.go
+3
-1
builder/virtualbox/ovf/config.go
builder/virtualbox/ovf/config.go
+2
-0
No files found.
builder/virtualbox/
iso
/step_upload_version.go
→
builder/virtualbox/
common
/step_upload_version.go
View file @
5f1c5972
package
iso
package
common
import
(
"bytes"
"fmt"
"github.com/mitchellh/multistep"
vboxcommon
"github.com/mitchellh/packer/builder/virtualbox/common"
"github.com/mitchellh/packer/packer"
"log"
)
// This step uploads a file containing the VirtualBox version, which
// can be useful for various provisioning reasons.
type
stepUploadVersion
struct
{}
type
StepUploadVersion
struct
{
Path
string
}
func
(
s
*
s
tepUploadVersion
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
func
(
s
*
S
tepUploadVersion
)
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
config
.
VBoxVersionFile
==
""
{
if
s
.
Path
==
""
{
log
.
Println
(
"VBoxVersionFile is empty. Not uploading."
)
return
multistep
.
ActionContinue
}
...
...
@@ -33,7 +33,7 @@ func (s *stepUploadVersion) Run(state multistep.StateBag) multistep.StepAction {
ui
.
Say
(
fmt
.
Sprintf
(
"Uploading VirtualBox version info (%s)"
,
version
))
var
data
bytes
.
Buffer
data
.
WriteString
(
version
)
if
err
:=
comm
.
Upload
(
config
.
VBoxVersionFile
,
&
data
);
err
!=
nil
{
if
err
:=
comm
.
Upload
(
s
.
Path
,
&
data
);
err
!=
nil
{
state
.
Put
(
"error"
,
fmt
.
Errorf
(
"Error uploading VirtualBox version: %s"
,
err
))
return
multistep
.
ActionHalt
}
...
...
@@ -41,4 +41,4 @@ func (s *stepUploadVersion) Run(state multistep.StateBag) multistep.StepAction {
return
multistep
.
ActionContinue
}
func
(
s
*
s
tepUploadVersion
)
Cleanup
(
state
multistep
.
StateBag
)
{}
func
(
s
*
S
tepUploadVersion
)
Cleanup
(
state
multistep
.
StateBag
)
{}
builder/virtualbox/common/vbox_version_config.go
0 → 100644
View file @
5f1c5972
package
common
import
(
"fmt"
"github.com/mitchellh/packer/packer"
)
type
VBoxVersionConfig
struct
{
VBoxVersionFile
string
`mapstructure:"virtualbox_version_file"`
}
func
(
c
*
VBoxVersionConfig
)
Prepare
(
t
*
packer
.
ConfigTemplate
)
[]
error
{
if
c
.
VBoxVersionFile
==
""
{
c
.
VBoxVersionFile
=
".vbox_version"
}
templates
:=
map
[
string
]
*
string
{
"virtualbox_version_file"
:
&
c
.
VBoxVersionFile
,
}
errs
:=
make
([]
error
,
0
)
for
n
,
ptr
:=
range
templates
{
var
err
error
*
ptr
,
err
=
t
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
n
,
err
))
}
}
return
errs
}
builder/virtualbox/common/vbox_version_config_test.go
0 → 100644
View file @
5f1c5972
package
common
import
(
"testing"
)
func
TestVBoxVersionConfigPrepare_BootWait
(
t
*
testing
.
T
)
{
var
c
*
VBoxVersionConfig
var
errs
[]
error
// Test empty
c
=
new
(
VBoxVersionConfig
)
errs
=
c
.
Prepare
(
testConfigTemplate
(
t
))
if
len
(
errs
)
>
0
{
t
.
Fatalf
(
"should not have error: %s"
,
errs
)
}
if
c
.
VBoxVersionFile
!=
".vbox_version"
{
t
.
Fatalf
(
"bad value: %s"
,
c
.
VBoxVersionFile
)
}
// Test with a good one
c
=
new
(
VBoxVersionConfig
)
c
.
VBoxVersionFile
=
"foo"
errs
=
c
.
Prepare
(
testConfigTemplate
(
t
))
if
len
(
errs
)
>
0
{
t
.
Fatalf
(
"should not have error: %s"
,
errs
)
}
if
c
.
VBoxVersionFile
!=
"foo"
{
t
.
Fatalf
(
"bad value: %s"
,
c
.
VBoxVersionFile
)
}
}
builder/virtualbox/iso/builder.go
View file @
5f1c5972
...
...
@@ -35,6 +35,7 @@ type config struct {
vboxcommon
.
ShutdownConfig
`mapstructure:",squash"`
vboxcommon
.
SSHConfig
`mapstructure:",squash"`
vboxcommon
.
VBoxManageConfig
`mapstructure:",squash"`
vboxcommon
.
VBoxVersionConfig
`mapstructure:",squash"`
BootCommand
[]
string
`mapstructure:"boot_command"`
DiskSize
uint
`mapstructure:"disk_size"`
...
...
@@ -50,7 +51,6 @@ type config struct {
ISOChecksum
string
`mapstructure:"iso_checksum"`
ISOChecksumType
string
`mapstructure:"iso_checksum_type"`
ISOUrls
[]
string
`mapstructure:"iso_urls"`
VBoxVersionFile
string
`mapstructure:"virtualbox_version_file"`
VMName
string
`mapstructure:"vm_name"`
RawSingleISOUrl
string
`mapstructure:"iso_url"`
...
...
@@ -79,6 +79,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
RunConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
SSHConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
VBoxManageConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
VBoxVersionConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
warnings
:=
make
([]
string
,
0
)
if
b
.
config
.
DiskSize
==
0
{
...
...
@@ -109,26 +110,21 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b
.
config
.
HTTPPortMax
=
9000
}
if
b
.
config
.
VBoxVersionFile
==
""
{
b
.
config
.
VBoxVersionFile
=
".vbox_version"
}
if
b
.
config
.
VMName
==
""
{
b
.
config
.
VMName
=
fmt
.
Sprintf
(
"packer-%s"
,
b
.
config
.
PackerBuildName
)
}
// 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
,
"http_directory"
:
&
b
.
config
.
HTTPDir
,
"iso_checksum"
:
&
b
.
config
.
ISOChecksum
,
"iso_checksum_type"
:
&
b
.
config
.
ISOChecksumType
,
"iso_url"
:
&
b
.
config
.
RawSingleISOUrl
,
"virtualbox_version_file"
:
&
b
.
config
.
VBoxVersionFile
,
"vm_name"
:
&
b
.
config
.
VMName
,
"guest_additions_mode"
:
&
b
.
config
.
GuestAdditionsMode
,
"guest_additions_sha256"
:
&
b
.
config
.
GuestAdditionsSHA256
,
"guest_os_type"
:
&
b
.
config
.
GuestOSType
,
"hard_drive_interface"
:
&
b
.
config
.
HardDriveInterface
,
"http_directory"
:
&
b
.
config
.
HTTPDir
,
"iso_checksum"
:
&
b
.
config
.
ISOChecksum
,
"iso_checksum_type"
:
&
b
.
config
.
ISOChecksumType
,
"iso_url"
:
&
b
.
config
.
RawSingleISOUrl
,
"vm_name"
:
&
b
.
config
.
VMName
,
}
for
n
,
ptr
:=
range
templates
{
...
...
@@ -300,7 +296,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
SSHConfig
:
vboxcommon
.
SSHConfigFunc
(
b
.
config
.
SSHConfig
),
SSHWaitTimeout
:
b
.
config
.
SSHWaitTimeout
,
},
new
(
stepUploadVersion
),
&
vboxcommon
.
StepUploadVersion
{
Path
:
b
.
config
.
VBoxVersionFile
,
},
new
(
stepUploadGuestAdditions
),
new
(
common
.
StepProvision
),
&
vboxcommon
.
StepShutdown
{
...
...
builder/virtualbox/iso/builder_test.go
View file @
5f1c5972
...
...
@@ -454,37 +454,3 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
t
.
Fatalf
(
"bad: %#v"
,
b
.
config
.
ISOUrls
)
}
}
func
TestBuilderPrepare_VBoxVersionFile
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
// Test empty
delete
(
config
,
"virtualbox_version_file"
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
b
.
config
.
VBoxVersionFile
!=
".vbox_version"
{
t
.
Fatalf
(
"bad value: %s"
,
b
.
config
.
VBoxVersionFile
)
}
// Test with a good one
config
[
"virtualbox_version_file"
]
=
"foo"
b
=
Builder
{}
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
if
b
.
config
.
VBoxVersionFile
!=
"foo"
{
t
.
Fatalf
(
"bad value: %s"
,
b
.
config
.
VBoxVersionFile
)
}
}
builder/virtualbox/ovf/builder.go
View file @
5f1c5972
...
...
@@ -71,8 +71,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
SSHConfig
:
vboxcommon
.
SSHConfigFunc
(
b
.
config
.
SSHConfig
),
SSHWaitTimeout
:
b
.
config
.
SSHWaitTimeout
,
},
&
vboxcommon
.
StepUploadVersion
{
Path
:
b
.
config
.
VBoxVersionFile
,
},
/*
new(stepUploadVersion),
new(stepUploadGuestAdditions),
*/
new
(
common
.
StepProvision
),
...
...
builder/virtualbox/ovf/config.go
View file @
5f1c5972
...
...
@@ -16,6 +16,7 @@ type Config struct {
vboxcommon
.
SSHConfig
`mapstructure:",squash"`
vboxcommon
.
ShutdownConfig
`mapstructure:",squash"`
vboxcommon
.
VBoxManageConfig
`mapstructure:",squash"`
vboxcommon
.
VBoxVersionConfig
`mapstructure:",squash"`
tpl
*
packer
.
ConfigTemplate
}
...
...
@@ -41,6 +42,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
RunConfig
.
Prepare
(
c
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
SSHConfig
.
Prepare
(
c
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
VBoxManageConfig
.
Prepare
(
c
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
VBoxVersionConfig
.
Prepare
(
c
.
tpl
)
...
)
// Warnings
var
warnings
[]
string
...
...
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