github.com/rothwerx/packer@v0.9.0/builder/vmware/iso/step_create_disk.go (about) 1 package iso 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/multistep" 6 vmwcommon "github.com/mitchellh/packer/builder/vmware/common" 7 "github.com/mitchellh/packer/packer" 8 "path/filepath" 9 ) 10 11 // This step creates the virtual disks for the VM. 12 // 13 // Uses: 14 // config *config 15 // driver Driver 16 // ui packer.Ui 17 // 18 // Produces: 19 // full_disk_path (string) - The full path to the created disk. 20 type stepCreateDisk struct{} 21 22 func (stepCreateDisk) Run(state multistep.StateBag) multistep.StepAction { 23 config := state.Get("config").(*Config) 24 driver := state.Get("driver").(vmwcommon.Driver) 25 ui := state.Get("ui").(packer.Ui) 26 27 ui.Say("Creating virtual machine disk") 28 full_disk_path := filepath.Join(config.OutputDir, config.DiskName+".vmdk") 29 if err := driver.CreateDisk(full_disk_path, fmt.Sprintf("%dM", config.DiskSize), config.DiskTypeId); err != nil { 30 err := fmt.Errorf("Error creating disk: %s", err) 31 state.Put("error", err) 32 ui.Error(err.Error()) 33 return multistep.ActionHalt 34 } 35 36 state.Put("full_disk_path", full_disk_path) 37 38 if len(config.AdditionalDiskSize) > 0 { 39 // stash the disk paths we create 40 additional_paths := make([]string, len(config.AdditionalDiskSize)) 41 42 ui.Say("Creating additional hard drives...") 43 for i, additionalsize := range config.AdditionalDiskSize { 44 additionalpath := filepath.Join(config.OutputDir, fmt.Sprintf("%s-%d.vmdk", config.DiskName, i+1)) 45 size := fmt.Sprintf("%dM", uint64(additionalsize)) 46 47 if err := driver.CreateDisk(additionalpath, size, config.DiskTypeId); err != nil { 48 err := fmt.Errorf("Error creating additional disk: %s", err) 49 state.Put("error", err) 50 ui.Error(err.Error()) 51 return multistep.ActionHalt 52 } 53 54 additional_paths[i] = additionalpath 55 } 56 57 state.Put("additional_disk_paths", additional_paths) 58 } 59 60 return multistep.ActionContinue 61 } 62 63 func (stepCreateDisk) Cleanup(multistep.StateBag) {}