diff --git a/iso/builder.go b/iso/builder.go index e92a0c548..412b7035f 100644 --- a/iso/builder.go +++ b/iso/builder.go @@ -32,12 +32,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe var steps []multistep.Step - var stepAddFloppy = &StepAddFloppy{ - Config: &b.config.FloppyConfig, - Datastore: b.config.Datastore, - Host: b.config.Host, - } - steps = append(steps, &common.StepConnect{ Config: &b.config.ConnectConfig, @@ -52,7 +46,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Files: b.config.FloppyFiles, Directories: b.config.FloppyDirectories, }, - stepAddFloppy, + &StepAddFloppy{ + Config: &b.config.FloppyConfig, + Datastore: b.config.Datastore, + Host: b.config.Host, + }, &StepConfigParams{ Config: &b.config.ConfigParamsConfig, }, @@ -82,9 +80,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe steps = append(steps, &StepRemoveCDRom{}, &StepRemoveFloppy{ - Datastore: b.config.Datastore, - Host: b.config.Host, - UploadedFloppyPath: stepAddFloppy.uploadedFloppyPath, + Datastore: b.config.Datastore, + Host: b.config.Host, }, &common.StepCreateSnapshot{ CreateSnapshot: b.config.CreateSnapshot, diff --git a/iso/step_add_floppy.go b/iso/step_add_floppy.go index cde7c630e..92a9c002d 100644 --- a/iso/step_add_floppy.go +++ b/iso/step_add_floppy.go @@ -30,8 +30,6 @@ type StepAddFloppy struct { Config *FloppyConfig Datastore string Host string - - uploadedFloppyPath string } func (s *StepAddFloppy) Run(state multistep.StateBag) multistep.StepAction { @@ -65,9 +63,8 @@ func (s *StepAddFloppy) runImpl(state multistep.StateBag) error { if err := ds.UploadFile(tmpFloppy.(string), uploadPath); err != nil { return fmt.Errorf("error uploading floppy image: %v", err) } + state.Put("uploaded_floppy_path", uploadPath) - // remember the path to the temporary floppy image to remove it after the build is finished - s.uploadedFloppyPath = uploadPath floppyIMGPath := ds.ResolvePath(uploadPath) ui.Say("Adding generated Floppy...") err = vm.AddFloppy(floppyIMGPath) diff --git a/iso/step_remove_cdrom.go b/iso/step_remove_cdrom.go index 43b57b3ca..74f1dba91 100644 --- a/iso/step_remove_cdrom.go +++ b/iso/step_remove_cdrom.go @@ -15,6 +15,7 @@ func (s *StepRemoveCDRom) Run(state multistep.StateBag) multistep.StepAction { ui := state.Get("ui").(packer.Ui) vm := state.Get("vm").(*driver.VirtualMachine) + ui.Say("Deleting CD-ROM drives...") devices, err := vm.Devices() if err != nil { ui.Error(fmt.Sprintf("error removing cdroms: %v", err)) diff --git a/iso/step_remove_floppy.go b/iso/step_remove_floppy.go index 9018d3a5f..1fc4f07fb 100644 --- a/iso/step_remove_floppy.go +++ b/iso/step_remove_floppy.go @@ -10,9 +10,8 @@ import ( ) type StepRemoveFloppy struct { - Datastore string - Host string - UploadedFloppyPath string + Datastore string + Host string } func (s *StepRemoveFloppy) Run(state multistep.StateBag) multistep.StepAction { @@ -20,25 +19,35 @@ func (s *StepRemoveFloppy) Run(state multistep.StateBag) multistep.StepAction { vm := state.Get("vm").(*driver.VirtualMachine) d := state.Get("driver").(*driver.Driver) + var UploadedFloppyPath string + switch s := state.Get("uploaded_floppy_path").(type) { + case string: + UploadedFloppyPath = s + case nil: + UploadedFloppyPath = "" + } + + ui.Say("Deleting Floppy drives...") devices, err := vm.Devices() if err != nil { ui.Error(fmt.Sprintf("error removing floppy: %v", err)) return multistep.ActionHalt } - cdroms := devices.SelectByType((*types.VirtualFloppy)(nil)) - if err = vm.RemoveDevice(false, cdroms...); err != nil { + floppies := devices.SelectByType((*types.VirtualFloppy)(nil)) + if err = vm.RemoveDevice(false, floppies...); err != nil { ui.Error(fmt.Sprintf("error removing floppy: %v", err)) return multistep.ActionHalt } - if s.UploadedFloppyPath != "" { + if UploadedFloppyPath != "" { + ui.Say("Deleting Floppy image...") ds, err := d.FindDatastore(s.Datastore, s.Host) if err != nil { ui.Error(err.Error()) return multistep.ActionHalt } - if err := ds.Delete(s.UploadedFloppyPath); err != nil { - ui.Error(fmt.Sprintf("Error deleting floppy image '%v': %v", s.UploadedFloppyPath, err.Error())) + if err := ds.Delete(UploadedFloppyPath); err != nil { + ui.Error(fmt.Sprintf("Error deleting floppy image '%v': %v", UploadedFloppyPath, err.Error())) return multistep.ActionHalt } }