diff --git a/builder/virtualbox/builder.go b/builder/virtualbox/builder.go index 2d61fe2d9..69ff257e8 100644 --- a/builder/virtualbox/builder.go +++ b/builder/virtualbox/builder.go @@ -225,6 +225,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe new(stepTypeBootCommand), new(stepWaitForSSH), new(stepUploadVersion), + new(stepUploadGuestAdditions), new(stepProvision), new(stepShutdown), new(stepExport), diff --git a/builder/virtualbox/step_upload_guest_additions.go b/builder/virtualbox/step_upload_guest_additions.go new file mode 100644 index 000000000..0a37d3903 --- /dev/null +++ b/builder/virtualbox/step_upload_guest_additions.go @@ -0,0 +1,35 @@ +package virtualbox + +import ( + "fmt" + "github.com/mitchellh/multistep" + "github.com/mitchellh/packer/packer" + "os" +) + +// This step uploads a file containing the VirtualBox version, which +// can be useful for various provisioning reasons. +type stepUploadGuestAdditions struct{} + +func (s *stepUploadGuestAdditions) Run(state map[string]interface{}) multistep.StepAction { + comm := state["communicator"].(packer.Communicator) + config := state["config"].(*config) + guestAdditionsPath := state["guest_additions_path"].(string) + ui := state["ui"].(packer.Ui) + + f, err := os.Open(guestAdditionsPath) + if err != nil { + state["error"] = fmt.Errorf("Error opening guest additions ISO: %s", err) + return multistep.ActionHalt + } + + ui.Say("Upload VirtualBox guest additions ISO...") + if err := comm.Upload(config.GuestAdditionsPath, f); err != nil { + state["error"] = fmt.Errorf("Error uploading guest additions: %s", err) + return multistep.ActionHalt + } + + return multistep.ActionContinue +} + +func (s *stepUploadGuestAdditions) Cleanup(state map[string]interface{}) {}