Initial work to implement additional disk support in the vmware-iso builder
* Matches the syntax from mitchellh/packer#703 * Creates disk(s), adds them to the vmx template, and runs compact at the end
This commit is contained in:
parent
793698f8a7
commit
fab9ca9cdb
|
@ -37,6 +37,18 @@ func (s StepCompactDisk) Run(state multistep.StateBag) multistep.StepAction {
|
|||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
moreDisks := state.Get("additional_disk_paths").([]string)
|
||||
if len(moreDisks) > 0 {
|
||||
for i, path := range moreDisks {
|
||||
ui.Say(fmt.Sprintf("Compacting additional disk image %d",i+1))
|
||||
if err := driver.CompactDisk(path); err != nil {
|
||||
state.Put("error", fmt.Errorf("Error compacting additional disk %d: %s", i+1, err))
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ type Config struct {
|
|||
vmwcommon.ToolsConfig `mapstructure:",squash"`
|
||||
vmwcommon.VMXConfig `mapstructure:",squash"`
|
||||
|
||||
AdditionalDiskSize []uint `mapstructure:"additionaldisk_size"`
|
||||
DiskName string `mapstructure:"vmdk_name"`
|
||||
DiskSize uint `mapstructure:"disk_size"`
|
||||
DiskTypeId string `mapstructure:"disk_type_id"`
|
||||
|
|
|
@ -35,6 +35,28 @@ func (stepCreateDisk) Run(state multistep.StateBag) multistep.StepAction {
|
|||
|
||||
state.Put("full_disk_path", full_disk_path)
|
||||
|
||||
if len(config.AdditionalDiskSize) > 0 {
|
||||
// stash the disk paths we create
|
||||
additional_paths := make([]string,len(config.AdditionalDiskSize))
|
||||
|
||||
ui.Say("Creating additional hard drives...")
|
||||
for i, additionalsize := range config.AdditionalDiskSize {
|
||||
additionalpath := filepath.Join(config.OutputDir, fmt.Sprintf("%s-%d.vmdk",config.DiskName,i+1))
|
||||
size := fmt.Sprintf("%dM", uint64(additionalsize))
|
||||
|
||||
if err := driver.CreateDisk(additionalpath, size, config.DiskTypeId); err != nil {
|
||||
err := fmt.Errorf("Error creating additional disk: %s", err)
|
||||
state.Put("error",err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
additional_paths[i] = additionalpath
|
||||
}
|
||||
|
||||
state.Put("additional_disk_paths", additional_paths)
|
||||
}
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,11 @@ type vmxTemplateData struct {
|
|||
Version string
|
||||
}
|
||||
|
||||
type additionalDiskTemplateData struct {
|
||||
DiskNumber int
|
||||
DiskName string
|
||||
}
|
||||
|
||||
// This step creates the VMX file for the VM.
|
||||
//
|
||||
// Uses:
|
||||
|
@ -71,6 +76,25 @@ func (s *stepCreateVMX) Run(state multistep.StateBag) multistep.StepAction {
|
|||
vmxTemplate = string(rawBytes)
|
||||
}
|
||||
|
||||
if len(config.AdditionalDiskSize) > 0 {
|
||||
for i, _ := range config.AdditionalDiskSize {
|
||||
data := &additionalDiskTemplateData{
|
||||
DiskNumber: i+1,
|
||||
DiskName: config.DiskName,
|
||||
}
|
||||
|
||||
diskTemplate, err := config.tpl.Process(DefaultAdditionalDiskTemplate,data)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error preparing VMX template for additional disk: %s", err)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
vmxTemplate += diskTemplate
|
||||
}
|
||||
}
|
||||
|
||||
vmxContents, err := interpolate.Render(vmxTemplate, &ctx)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error procesing VMX template: %s", err)
|
||||
|
@ -191,3 +215,9 @@ vmci0.pciSlotNumber = "35"
|
|||
vmci0.present = "TRUE"
|
||||
vmotion.checkpointFBSize = "65536000"
|
||||
`
|
||||
|
||||
const DefaultAdditionalDiskTemplate = `
|
||||
scsi0:{{ .DiskNumber }}.fileName = "{{ .DiskName}}-{{ .DiskNumber }}.vmdk"
|
||||
scsi0:{{ .DiskNumber }}.present = "TRUE"
|
||||
scsi0:{{ .DiskNumber }}.redo = ""
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue