packer-cn/builder/vmware/iso/step_create_disk.go

42 lines
1.1 KiB
Go
Raw Normal View History

2013-12-24 00:58:41 -05:00
package iso
import (
"fmt"
"github.com/mitchellh/multistep"
2013-12-24 13:31:57 -05:00
vmwcommon "github.com/mitchellh/packer/builder/vmware/common"
"github.com/mitchellh/packer/packer"
2013-07-02 01:12:57 -04:00
"path/filepath"
)
2013-06-05 17:49:04 -04:00
// This step creates the virtual disks for the VM.
//
// Uses:
// config *config
2013-06-06 15:19:38 -04:00
// driver Driver
2013-06-05 17:49:04 -04:00
// ui packer.Ui
//
// Produces:
// full_disk_path (string) - The full path to the created disk.
type stepCreateDisk struct{}
2013-08-31 15:50:25 -04:00
func (stepCreateDisk) Run(state multistep.StateBag) multistep.StepAction {
2015-05-27 17:16:28 -04:00
config := state.Get("config").(*Config)
2013-12-24 13:31:57 -05:00
driver := state.Get("driver").(vmwcommon.Driver)
2013-08-31 15:50:25 -04:00
ui := state.Get("ui").(packer.Ui)
ui.Say("Creating virtual machine disk")
2013-07-02 01:12:57 -04:00
full_disk_path := filepath.Join(config.OutputDir, config.DiskName+".vmdk")
if err := driver.CreateDisk(full_disk_path, fmt.Sprintf("%dM", config.DiskSize), config.DiskTypeId); err != nil {
2013-06-20 00:20:48 -04:00
err := fmt.Errorf("Error creating disk: %s", err)
2013-08-31 15:50:25 -04:00
state.Put("error", err)
2013-06-20 00:20:48 -04:00
ui.Error(err.Error())
return multistep.ActionHalt
}
2013-08-31 15:50:25 -04:00
state.Put("full_disk_path", full_disk_path)
return multistep.ActionContinue
}
2013-08-31 15:50:25 -04:00
func (stepCreateDisk) Cleanup(multistep.StateBag) {}