github.com/sneal/packer@v0.5.2/builder/vmware/common/step_compact_disk.go (about)

     1  package common
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/mitchellh/multistep"
     6  	"github.com/mitchellh/packer/packer"
     7  	"log"
     8  )
     9  
    10  // This step compacts the virtual disk for the VM unless the "skip_compaction"
    11  // boolean is true.
    12  //
    13  // Uses:
    14  //   driver Driver
    15  //   full_disk_path string
    16  //   ui     packer.Ui
    17  //
    18  // Produces:
    19  //   <nothing>
    20  type StepCompactDisk struct {
    21  	Skip bool
    22  }
    23  
    24  func (s StepCompactDisk) Run(state multistep.StateBag) multistep.StepAction {
    25  	driver := state.Get("driver").(Driver)
    26  	ui := state.Get("ui").(packer.Ui)
    27  	full_disk_path := state.Get("full_disk_path").(string)
    28  
    29  	if s.Skip {
    30  		log.Println("Skipping disk compaction step...")
    31  		return multistep.ActionContinue
    32  	}
    33  
    34  	ui.Say("Compacting the disk image")
    35  	if err := driver.CompactDisk(full_disk_path); err != nil {
    36  		state.Put("error", fmt.Errorf("Error compacting disk: %s", err))
    37  		return multistep.ActionHalt
    38  	}
    39  
    40  	return multistep.ActionContinue
    41  }
    42  
    43  func (StepCompactDisk) Cleanup(multistep.StateBag) {}