allow user defined output filename

This commit is contained in:
Megan Marsh 2020-05-05 16:09:05 -07:00
parent dcd8673817
commit 73eda08540
5 changed files with 12 additions and 1 deletions

View File

@ -17,6 +17,10 @@ type OutputConfig struct {
// the builder. By default this is output-BUILDNAME where "BUILDNAME" is the
// name of the build.
OutputDir string `mapstructure:"output_directory" required:"false"`
// This is the base name of the file (excluding the file extension) where
// the resulting virtual machine will be created. By default this is the
// `vm_name`.
OutputFilename string `mapstructure:"output_filename" required:"false"`
}
func (c *OutputConfig) Prepare(ctx *interpolate.Context, pc *common.PackerConfig) []error {

View File

@ -19,6 +19,7 @@ import (
type StepExport struct {
Format string
OutputDir string
OutputFilename string
ExportOpts []string
Bundling VBoxBundleConfig
SkipNatMapping bool
@ -37,6 +38,9 @@ func (s *StepExport) Run(ctx context.Context, state multistep.StateBag) multiste
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
vmName := state.Get("vmName").(string)
if s.OutputFilename == "" {
s.OutputFilename = vmName
}
// Skip export if requested
if s.SkipExport {
@ -61,7 +65,7 @@ func (s *StepExport) Run(ctx context.Context, state multistep.StateBag) multiste
}
// Export the VM to an OVF
outputPath := filepath.Join(s.OutputDir, vmName+"."+s.Format)
outputPath := filepath.Join(s.OutputDir, s.OutputFilename+"."+s.Format)
command := []string{
"export",

View File

@ -396,6 +396,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
&vboxcommon.StepExport{
Format: b.config.Format,
OutputDir: b.config.OutputDir,
OutputFilename: b.config.OutputFilename,
ExportOpts: b.config.ExportConfig.ExportOpts,
Bundling: b.config.VBoxBundleConfig,
SkipNatMapping: b.config.SkipNatMapping,

View File

@ -158,6 +158,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
&vboxcommon.StepExport{
Format: b.config.Format,
OutputDir: b.config.OutputDir,
OutputFilename: b.config.OutputFilename,
ExportOpts: b.config.ExportConfig.ExportOpts,
SkipNatMapping: b.config.SkipNatMapping,
SkipExport: b.config.SkipExport,

View File

@ -141,6 +141,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
&vboxcommon.StepExport{
Format: b.config.Format,
OutputDir: b.config.OutputDir,
OutputFilename: b.config.OutputFilename,
ExportOpts: b.config.ExportOpts,
SkipNatMapping: b.config.SkipNatMapping,
SkipExport: b.config.SkipExport,