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

49 lines
1.2 KiB
Go
Raw Normal View History

2013-12-25 01:09:22 -05:00
package common
2013-07-01 22:25:33 -04:00
import (
"context"
2013-07-01 22:25:33 -04:00
"fmt"
"log"
2020-12-17 16:29:25 -05:00
"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
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:
// driver Driver
// disk_full_paths ([]string) - The full paths to all created disks
// ui packersdk.Ui
2013-07-01 22:25:33 -04:00
//
// Produces:
// <nothing>
2013-12-25 01:09:22 -05:00
type StepCompactDisk struct {
Skip bool
}
2013-07-01 22:25:33 -04:00
func (s StepCompactDisk) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
2013-12-25 01:09:22 -05:00
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packersdk.Ui)
diskFullPaths := state.Get("disk_full_paths").([]string)
2013-07-01 22:25:33 -04:00
2013-12-25 01:09:22 -05:00
if s.Skip {
2013-07-02 20:22:11 -04:00
log.Println("Skipping disk compaction step...")
return multistep.ActionContinue
}
ui.Say("Compacting all attached virtual disks...")
for i, diskFullPath := range diskFullPaths {
ui.Message(fmt.Sprintf("Compacting virtual disk %d", i+1))
if err := driver.CompactDisk(diskFullPath); err != nil {
state.Put("error", fmt.Errorf("Error compacting disk: %s", err))
return multistep.ActionHalt
}
}
2013-07-01 22:25:33 -04:00
return multistep.ActionContinue
}
2013-12-25 01:09:22 -05:00
func (StepCompactDisk) Cleanup(multistep.StateBag) {}