github.com/alouche/packer@v0.3.7/builder/vmware/step_compact_disk.go (about)

     1  package vmware
     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  //   config *config
    15  //   driver Driver
    16  //   full_disk_path string
    17  //   ui     packer.Ui
    18  //
    19  // Produces:
    20  //   <nothing>
    21  type stepCompactDisk struct{}
    22  
    23  func (stepCompactDisk) Run(state multistep.StateBag) multistep.StepAction {
    24  	config := state.Get("config").(*config)
    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 config.SkipCompaction == true {
    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) {}