Deleting floppy images on teardown (#159)
This commit is contained in:
parent
e4f6d5d691
commit
af6db0ff2d
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue