github.com/mitchellh/packer@v1.3.2/builder/qemu/step_resize_disk.go (about)

     1  package qemu
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"path/filepath"
     7  
     8  	"github.com/hashicorp/packer/helper/multistep"
     9  	"github.com/hashicorp/packer/packer"
    10  )
    11  
    12  // This step resizes the virtual disk that will be used as the
    13  // hard drive for the virtual machine.
    14  type stepResizeDisk struct{}
    15  
    16  func (s *stepResizeDisk) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
    17  	config := state.Get("config").(*Config)
    18  	driver := state.Get("driver").(Driver)
    19  	ui := state.Get("ui").(packer.Ui)
    20  	path := filepath.Join(config.OutputDir, config.VMName)
    21  
    22  	command := []string{
    23  		"resize",
    24  		"-f", config.Format,
    25  		path,
    26  		fmt.Sprintf("%vM", config.DiskSize),
    27  	}
    28  
    29  	if config.DiskImage == false {
    30  		return multistep.ActionContinue
    31  	}
    32  
    33  	ui.Say("Resizing hard drive...")
    34  	if err := driver.QemuImg(command...); err != nil {
    35  		err := fmt.Errorf("Error creating hard drive: %s", err)
    36  		state.Put("error", err)
    37  		ui.Error(err.Error())
    38  		return multistep.ActionHalt
    39  	}
    40  
    41  	return multistep.ActionContinue
    42  }
    43  
    44  func (s *stepResizeDisk) Cleanup(state multistep.StateBag) {}