From 6516e5a6272418958c2a4ceb2c0f02390e83d7cc Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 12 Jun 2013 18:07:08 -0700 Subject: [PATCH] builder/virtualbox: export --- builder/virtualbox/builder.go | 1 + builder/virtualbox/step_export.go | 46 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 builder/virtualbox/step_export.go diff --git a/builder/virtualbox/builder.go b/builder/virtualbox/builder.go index b06466c57..147952366 100644 --- a/builder/virtualbox/builder.go +++ b/builder/virtualbox/builder.go @@ -196,6 +196,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe new(stepWaitForSSH), new(stepProvision), new(stepShutdown), + new(stepExport), } // Setup the state bag diff --git a/builder/virtualbox/step_export.go b/builder/virtualbox/step_export.go new file mode 100644 index 000000000..d2a04a857 --- /dev/null +++ b/builder/virtualbox/step_export.go @@ -0,0 +1,46 @@ +package virtualbox + +import ( + "fmt" + "github.com/mitchellh/multistep" + "github.com/mitchellh/packer/packer" + "path/filepath" +) + +// This step creates the virtual disk that will be used as the +// hard drive for the virtual machine. +// +// Uses: +// +// Produces: +// exportPath string - The path to the resulting export. +type stepExport struct{} + +func (s *stepExport) Run(state map[string]interface{}) multistep.StepAction { + config := state["config"].(*config) + driver := state["driver"].(Driver) + ui := state["ui"].(packer.Ui) + vmName := state["vmName"].(string) + + outputPath := filepath.Join(config.OutputDir, "packer.ovf") + + command := []string{ + "export", + vmName, + "--output", + outputPath, + } + + ui.Say("Exporting virtual machine...") + err := driver.VBoxManage(command...) + if err != nil { + ui.Error(fmt.Sprintf("Error exporting virtual machine: %s", err)) + return multistep.ActionHalt + } + + state["exportPath"] = outputPath + + return multistep.ActionContinue +} + +func (s *stepExport) Cleanup(state map[string]interface{}) {}