builder/vmware-esxi: remove floppy files when done

pull/6206/head
Matthew Hooker 9 years ago
parent bda2d8c947
commit 451e3d0554
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1

@ -293,8 +293,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Directories: b.config.FloppyConfig.FloppyDirectories,
},
&stepRemoteUpload{
Key: "floppy_path",
Message: "Uploading Floppy to remote machine...",
Key: "floppy_path",
Message: "Uploading Floppy to remote machine...",
DoCleanup: true,
},
&stepRemoteUpload{
Key: "iso_path",

@ -569,6 +569,10 @@ func (d *ESX5Driver) mkdir(path string) error {
return d.sh("mkdir", "-p", path)
}
func (d *ESX5Driver) remove(path string) error {
return d.sh("rm", "-rf", path)
}
func (d *ESX5Driver) upload(dst, src string) error {
f, err := os.Open(src)
if err != nil {

@ -27,6 +27,9 @@ type RemoteDriver interface {
// Uploads a local file to remote side.
upload(dst, src string) error
// Forcefully remove a path from the remote side.
remove(path string) error
// Reload VM on remote side.
ReloadVM() error
}

@ -61,6 +61,10 @@ func (d *RemoteDriverMock) IsDestroyed() (bool, error) {
}
func (d *RemoteDriverMock) upload(dst, src string) error {
return nil
}
func (d *RemoteDriverMock) remove(path string) error {
return d.uploadErr
}

@ -13,8 +13,9 @@ import (
// stepRemoteUpload uploads some thing from the state bag to a remote driver
// (if it can) and stores that new remote path into the state bag.
type stepRemoteUpload struct {
Key string
Message string
Key string
Message string
DoCleanup bool
}
func (s *stepRemoteUpload) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
@ -50,4 +51,27 @@ func (s *stepRemoteUpload) Run(_ context.Context, state multistep.StateBag) mult
}
func (s *stepRemoteUpload) Cleanup(state multistep.StateBag) {
if !s.DoCleanup {
return
}
driver := state.Get("driver").(vmwcommon.Driver)
// ui := state.Get("ui").(packer.Ui)
remote, ok := driver.(RemoteDriver)
if !ok {
return
}
path, ok := state.Get(s.Key).(string)
if !ok {
return
}
log.Printf("Cleaning up remote path: %s", path)
err := remote.remove(path)
if err != nil {
log.Printf("Error cleaning up: %s", err)
}
}

Loading…
Cancel
Save