Files
Packer-Cn/builder/parallels/common/step_compact_disk.go
T

56 lines
1.3 KiB
Go
Raw Normal View History

2015-06-21 13:35:52 +03:00
package common
import (
2018-01-22 15:32:33 -08:00
"context"
2015-06-21 13:35:52 +03:00
"fmt"
2016-12-11 21:13:37 +02:00
2018-01-19 16:18:44 -08:00
"github.com/hashicorp/packer/helper/multistep"
2017-04-04 13:39:01 -07:00
"github.com/hashicorp/packer/packer"
2015-06-21 13:35:52 +03:00
)
2016-12-12 00:37:41 +02:00
// StepCompactDisk is a step that removes all empty blocks from expanding
// Parallels virtual disks and reduces the result disk size
2015-06-21 13:35:52 +03:00
//
// Uses:
// driver Driver
// vmName string
// ui packer.Ui
//
// Produces:
// <nothing>
type StepCompactDisk struct {
Skip bool
}
2016-12-16 21:51:55 +02:00
// Run runs the compaction of the virtual disk attached to the VM.
func (s *StepCompactDisk) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
2015-06-21 13:35:52 +03:00
driver := state.Get("driver").(Driver)
vmName := state.Get("vmName").(string)
ui := state.Get("ui").(packer.Ui)
if s.Skip {
ui.Say("Skipping disk compaction step...")
return multistep.ActionContinue
}
ui.Say("Compacting the disk image")
diskPath, err := driver.DiskPath(vmName)
if err != nil {
2016-12-11 23:12:55 +02:00
err = fmt.Errorf("Error detecting virtual disk path: %s", err)
2015-06-21 13:35:52 +03:00
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
if err := driver.CompactDisk(diskPath); err != nil {
state.Put("error", fmt.Errorf("Error compacting disk: %s", err))
ui.Error(err.Error())
return multistep.ActionHalt
}
return multistep.ActionContinue
}
2016-12-16 21:51:55 +02:00
// Cleanup does nothing.
2015-06-21 13:35:52 +03:00
func (*StepCompactDisk) Cleanup(multistep.StateBag) {}