Deleting floppy images on teardown (#159)

This commit is contained in:
Konstantin Toshchev 2018-10-18 16:43:17 +03:00 committed by GitHub
parent e4f6d5d691
commit af6db0ff2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 1 deletions

View File

@ -67,4 +67,30 @@ func (s *StepAddFloppy) Run(_ context.Context, state multistep.StateBag) multist
return multistep.ActionContinue
}
func (s *StepAddFloppy) Cleanup(state multistep.StateBag) {}
func (s *StepAddFloppy) Cleanup(state multistep.StateBag) {
_, cancelled := state.GetOk(multistep.StateCancelled)
_, halted := state.GetOk(multistep.StateHalted)
if !cancelled && !halted {
return
}
ui := state.Get("ui").(packer.Ui)
d := state.Get("driver").(*driver.Driver)
if UploadedFloppyPath, ok := state.GetOk("uploaded_floppy_path"); ok {
ui.Say("Deleting Floppy image ...")
ds, err := d.FindDatastore(s.Datastore, s.Host)
if err != nil {
state.Put("error", err)
return
}
err_del := ds.Delete(UploadedFloppyPath.(string))
if err_del != nil {
state.Put("error", err)
return
}
}
}