2013-12-24 00:58:41 -05:00
|
|
|
package iso
|
2013-06-04 18:00:58 -04:00
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2013-06-04 18:00:58 -04:00
|
|
|
"fmt"
|
2018-01-22 20:21:10 -05:00
|
|
|
"path/filepath"
|
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
vmwcommon "github.com/hashicorp/packer/builder/vmware/common"
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2013-06-04 18:00:58 -04:00
|
|
|
)
|
|
|
|
|
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:
|
2013-07-02 12:09:55 -04:00
|
|
|
// full_disk_path (string) - The full path to the created disk.
|
2013-06-04 18:00:58 -04:00
|
|
|
type stepCreateDisk struct{}
|
|
|
|
|
2018-01-22 18:31:41 -05:00
|
|
|
func (stepCreateDisk) Run(_ context.Context, 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)
|
2013-06-04 18:00:58 -04:00
|
|
|
|
|
|
|
ui.Say("Creating virtual machine disk")
|
2013-07-02 01:12:57 -04:00
|
|
|
full_disk_path := filepath.Join(config.OutputDir, config.DiskName+".vmdk")
|
2013-08-22 14:40:56 -04:00
|
|
|
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())
|
2013-06-04 18:00:58 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2013-08-31 15:50:25 -04:00
|
|
|
state.Put("full_disk_path", full_disk_path)
|
2014-03-04 15:00:24 -05:00
|
|
|
|
2014-03-04 13:23:07 -05:00
|
|
|
if len(config.AdditionalDiskSize) > 0 {
|
|
|
|
// stash the disk paths we create
|
2014-03-04 15:00:24 -05:00
|
|
|
additional_paths := make([]string, len(config.AdditionalDiskSize))
|
|
|
|
|
2014-03-04 13:23:07 -05:00
|
|
|
ui.Say("Creating additional hard drives...")
|
|
|
|
for i, additionalsize := range config.AdditionalDiskSize {
|
2014-03-04 15:00:24 -05:00
|
|
|
additionalpath := filepath.Join(config.OutputDir, fmt.Sprintf("%s-%d.vmdk", config.DiskName, i+1))
|
2014-03-04 13:23:07 -05:00
|
|
|
size := fmt.Sprintf("%dM", uint64(additionalsize))
|
2014-03-04 15:00:24 -05:00
|
|
|
|
2014-03-04 13:23:07 -05:00
|
|
|
if err := driver.CreateDisk(additionalpath, size, config.DiskTypeId); err != nil {
|
|
|
|
err := fmt.Errorf("Error creating additional disk: %s", err)
|
2014-03-04 15:00:24 -05:00
|
|
|
state.Put("error", err)
|
2014-03-04 13:23:07 -05:00
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2014-03-04 15:00:24 -05:00
|
|
|
|
2014-03-04 13:23:07 -05:00
|
|
|
additional_paths[i] = additionalpath
|
|
|
|
}
|
2014-03-04 15:00:24 -05:00
|
|
|
|
2014-03-04 13:23:07 -05:00
|
|
|
state.Put("additional_disk_paths", additional_paths)
|
|
|
|
}
|
2013-07-02 12:09:55 -04:00
|
|
|
|
2013-06-04 18:00:58 -04:00
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2013-08-31 15:50:25 -04:00
|
|
|
func (stepCreateDisk) Cleanup(multistep.StateBag) {}
|