Merge pull request #6206 from hashicorp/fix4679

builder/vmware-esxi: remove floppy files when done
This commit is contained in:
Matthew Hooker 2018-04-26 14:05:52 -07:00 committed by GitHub
commit 5c9b47c808
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 4 deletions

View File

@ -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",

View File

@ -138,6 +138,12 @@ func (d *ESX5Driver) UploadISO(localPath string, checksum string, checksumType s
return finalPath, nil
}
func (d *ESX5Driver) RemoveCache(localPath string) error {
finalPath := d.cachePath(localPath)
log.Printf("Removing remote cache path %s (local %s)", finalPath, localPath)
return d.sh("rm", "-f", finalPath)
}
func (d *ESX5Driver) ToolsIsoPath(string) string {
return ""
}

View File

@ -12,6 +12,9 @@ type RemoteDriver interface {
// exists.
UploadISO(string, string, string) (string, error)
// RemoveCache deletes localPath from the remote cache.
RemoveCache(localPath string) error
// Adds a VM to inventory specified by the path to the VMX given.
Register(string) error

View File

@ -64,6 +64,10 @@ func (d *RemoteDriverMock) upload(dst, src string) error {
return d.uploadErr
}
func (d *RemoteDriverMock) RemoveCache(localPath string) error {
return nil
}
func (d *RemoteDriverMock) ReloadVM() error {
return d.ReloadVMErr
}

View File

@ -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,25 @@ 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)
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.RemoveCache(path)
if err != nil {
log.Printf("Error cleaning up: %s", err)
}
}