packer-cn/builder/vmware/iso/step_compact_disk.go

45 lines
1.1 KiB
Go
Raw Normal View History

2013-12-24 00:58:41 -05:00
package iso
2013-07-01 22:25:33 -04:00
import (
"fmt"
"github.com/mitchellh/multistep"
2013-12-24 13:31:57 -05:00
vmwcommon "github.com/mitchellh/packer/builder/vmware/common"
2013-07-01 22:25:33 -04:00
"github.com/mitchellh/packer/packer"
2013-07-02 20:22:11 -04:00
"log"
2013-07-01 22:25:33 -04:00
)
2013-07-02 20:22:11 -04:00
// This step compacts the virtual disk for the VM unless the "skip_compaction"
// boolean is true.
2013-07-01 22:25:33 -04:00
//
// Uses:
2013-07-02 20:22:11 -04:00
// config *config
2013-07-01 22:25:33 -04:00
// driver Driver
// full_disk_path string
2013-07-01 22:25:33 -04:00
// ui packer.Ui
//
// Produces:
// <nothing>
type stepCompactDisk struct{}
2013-08-31 15:50:25 -04:00
func (stepCompactDisk) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(*config)
2013-12-24 13:31:57 -05:00
driver := state.Get("driver").(vmwcommon.Driver)
2013-08-31 15:50:25 -04:00
ui := state.Get("ui").(packer.Ui)
full_disk_path := state.Get("full_disk_path").(string)
2013-07-01 22:25:33 -04:00
2013-07-02 20:22:11 -04:00
if config.SkipCompaction == true {
log.Println("Skipping disk compaction step...")
return multistep.ActionContinue
}
2013-07-01 22:25:33 -04:00
ui.Say("Compacting the disk image")
2013-07-02 01:12:57 -04:00
if err := driver.CompactDisk(full_disk_path); err != nil {
2013-08-31 15:50:25 -04:00
state.Put("error", fmt.Errorf("Error compacting disk: %s", err))
2013-07-01 22:25:33 -04:00
return multistep.ActionHalt
}
return multistep.ActionContinue
}
2013-08-31 15:50:25 -04:00
func (stepCompactDisk) Cleanup(multistep.StateBag) {}