builder/virtualbox: export to ovf or ova (default ovf)
This commit is contained in:
parent
fcb24f6896
commit
a19bd564d3
|
@ -48,6 +48,7 @@ type config struct {
|
||||||
VBoxVersionFile string `mapstructure:"virtualbox_version_file"`
|
VBoxVersionFile string `mapstructure:"virtualbox_version_file"`
|
||||||
VBoxManage [][]string `mapstructure:"vboxmanage"`
|
VBoxManage [][]string `mapstructure:"vboxmanage"`
|
||||||
VMName string `mapstructure:"vm_name"`
|
VMName string `mapstructure:"vm_name"`
|
||||||
|
Format string `mapstructure:"format"`
|
||||||
|
|
||||||
RawBootWait string `mapstructure:"boot_wait"`
|
RawBootWait string `mapstructure:"boot_wait"`
|
||||||
RawSingleISOUrl string `mapstructure:"iso_url"`
|
RawSingleISOUrl string `mapstructure:"iso_url"`
|
||||||
|
@ -131,6 +132,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
||||||
b.config.VMName = fmt.Sprintf("packer-%s", b.config.PackerBuildName)
|
b.config.VMName = fmt.Sprintf("packer-%s", b.config.PackerBuildName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if b.config.Format == "" {
|
||||||
|
b.config.Format = "ovf"
|
||||||
|
}
|
||||||
|
|
||||||
// Errors
|
// Errors
|
||||||
templates := map[string]*string{
|
templates := map[string]*string{
|
||||||
"guest_additions_sha256": &b.config.GuestAdditionsSHA256,
|
"guest_additions_sha256": &b.config.GuestAdditionsSHA256,
|
||||||
|
@ -145,6 +150,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
||||||
"ssh_username": &b.config.SSHUser,
|
"ssh_username": &b.config.SSHUser,
|
||||||
"virtualbox_version_file": &b.config.VBoxVersionFile,
|
"virtualbox_version_file": &b.config.VBoxVersionFile,
|
||||||
"vm_name": &b.config.VMName,
|
"vm_name": &b.config.VMName,
|
||||||
|
"format": &b.config.Format,
|
||||||
"boot_wait": &b.config.RawBootWait,
|
"boot_wait": &b.config.RawBootWait,
|
||||||
"shutdown_timeout": &b.config.RawShutdownTimeout,
|
"shutdown_timeout": &b.config.RawShutdownTimeout,
|
||||||
"ssh_wait_timeout": &b.config.RawSSHWaitTimeout,
|
"ssh_wait_timeout": &b.config.RawSSHWaitTimeout,
|
||||||
|
@ -197,6 +203,11 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !(b.config.Format == "ovf" || b.config.Format == "ova") {
|
||||||
|
errs = packer.MultiErrorAppend(
|
||||||
|
errs, errors.New("invalid format, only 'ovf' or 'ova' are allowed"))
|
||||||
|
}
|
||||||
|
|
||||||
if b.config.HTTPPortMin > b.config.HTTPPortMax {
|
if b.config.HTTPPortMin > b.config.HTTPPortMax {
|
||||||
errs = packer.MultiErrorAppend(
|
errs = packer.MultiErrorAppend(
|
||||||
errs, errors.New("http_port_min must be less than http_port_max"))
|
errs, errors.New("http_port_min must be less than http_port_max"))
|
||||||
|
|
|
@ -58,6 +58,10 @@ func TestBuilderPrepare_Defaults(t *testing.T) {
|
||||||
if b.config.VMName != "packer-foo" {
|
if b.config.VMName != "packer-foo" {
|
||||||
t.Errorf("bad vm name: %s", b.config.VMName)
|
t.Errorf("bad vm name: %s", b.config.VMName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if b.config.Format != "ovf" {
|
||||||
|
t.Errorf("bad format: %s", b.config.Format)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuilderPrepare_BootWait(t *testing.T) {
|
func TestBuilderPrepare_BootWait(t *testing.T) {
|
||||||
|
@ -248,6 +252,34 @@ func TestBuilderPrepare_HTTPPort(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuilderPrepare_Format(t *testing.T) {
|
||||||
|
var b Builder
|
||||||
|
config := testConfig()
|
||||||
|
|
||||||
|
// Bad
|
||||||
|
config["format"] = "illegal value"
|
||||||
|
err := b.Prepare(config)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("should have error")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Good
|
||||||
|
config["format"] = "ova"
|
||||||
|
b = Builder{}
|
||||||
|
err = b.Prepare(config)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not have error: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Good
|
||||||
|
config["format"] = "ovf"
|
||||||
|
b = Builder{}
|
||||||
|
err = b.Prepare(config)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not have error: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestBuilderPrepare_InvalidKey(t *testing.T) {
|
func TestBuilderPrepare_InvalidKey(t *testing.T) {
|
||||||
var b Builder
|
var b Builder
|
||||||
config := testConfig()
|
config := testConfig()
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (s *stepExport) Run(state map[string]interface{}) multistep.StepAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export the VM to an OVF
|
// Export the VM to an OVF
|
||||||
outputPath := filepath.Join(config.OutputDir, "packer.ovf")
|
outputPath := filepath.Join(config.OutputDir, "packer." + config.Format)
|
||||||
|
|
||||||
command = []string{
|
command = []string{
|
||||||
"export",
|
"export",
|
||||||
|
|
Loading…
Reference in New Issue