Commit 3ba9d70b authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

Merge pull request #1382 from sneal/AdditionalDisksForVMwareISO

Additional disks for vmware iso
parents 802a7668 e9a491ae
......@@ -36,6 +36,18 @@ func (s StepCompactDisk) Run(state multistep.StateBag) multistep.StepAction {
state.Put("error", fmt.Errorf("Error compacting disk: %s", err))
return multistep.ActionHalt
}
if state.Get("additional_disk_paths") != nil {
if moreDisks := state.Get("additional_disk_paths").([]string); 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:
......@@ -40,15 +45,6 @@ func (s *stepCreateVMX) Run(state multistep.StateBag) multistep.StepAction {
ui.Say("Building and writing VMX file")
ctx := config.ctx
ctx.Data = &vmxTemplateData{
Name: config.VMName,
GuestOS: config.GuestOSType,
DiskName: config.DiskName,
Version: config.Version,
ISOPath: isoPath,
}
vmxTemplate := DefaultVMXTemplate
if config.VMXTemplatePath != "" {
f, err := os.Open(config.VMXTemplatePath)
......@@ -71,6 +67,35 @@ func (s *stepCreateVMX) Run(state multistep.StateBag) multistep.StepAction {
vmxTemplate = string(rawBytes)
}
ctx := config.ctx
if len(config.AdditionalDiskSize) > 0 {
for i, _ := range config.AdditionalDiskSize {
ctx.Data = &additionalDiskTemplateData{
DiskNumber: i + 1,
DiskName: config.DiskName,
}
diskTemplate, err := interpolate.Render(DefaultAdditionalDiskTemplate, &ctx)
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
}
}
ctx.Data = &vmxTemplateData{
Name: config.VMName,
GuestOS: config.GuestOSType,
DiskName: config.DiskName,
Version: config.Version,
ISOPath: isoPath,
}
vmxContents, err := interpolate.Render(vmxTemplate, &ctx)
if err != nil {
err := fmt.Errorf("Error procesing VMX template: %s", err)
......@@ -191,3 +216,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 = ""
`
......@@ -72,6 +72,12 @@ each category, the available options are alphabetized and described.
### Optional:
* `additionaldisk_size` (array of integers) - The size(s) of any additional
hard disks for the VM in megabytes. If this is not specified then the VM will
only contain a primary hard disk. The builder uses expandable, not fixed-size
virtual hard disks, so the actual file representing the disk will not use the
full size unless it is full.
* `boot_command` (array of strings) - This is an array of commands to type
when the virtual machine is first booted. The goal of these commands should
be to type just enough to initialize the operating system installer. Special
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment