Merge pull request #6206 from hashicorp/fix4679
builder/vmware-esxi: remove floppy files when done
This commit is contained in:
commit
5c9b47c808
|
@ -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",
|
||||
|
|
|
@ -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 ""
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue