Skip to content

Commit

Permalink
Generalize SkipFloppy to SkipDevices
Browse files Browse the repository at this point in the history
It's not just floppies, it doesn't make sense to create any new
temporaryDevices in between StepCleanFiles and StepCleanVMX.
  • Loading branch information
puetzk committed Aug 17, 2021
1 parent 84c89ec commit f83a7fd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
39 changes: 17 additions & 22 deletions builder/vmware/common/step_configure_vmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
type StepConfigureVMX struct {
CustomData map[string]string
DisplayName string
SkipFloppy bool
SkipDevices bool
VMName string
DiskAdapterType string
CDROMAdapterType string
Expand Down Expand Up @@ -65,9 +65,10 @@ func (s *StepConfigureVMX) Run(ctx context.Context, state multistep.StateBag) mu
vmxData[k] = v
}

// Set a floppy disk, but only if we should
if !s.SkipFloppy {
// Grab list of temporary builder devices so we can append the floppy to it
// StepConfigureVMX runs both before and after provisioning (for VmxDataPost),
// the latter time shouldn't create temporary devices
if !s.SkipDevices {
// Grab list of temporary builder devices so we can append to it
tmpBuildDevices := state.Get("temporaryDevices").([]string)

// Set a floppy disk if we have one
Expand All @@ -81,24 +82,18 @@ func (s *StepConfigureVMX) Run(ctx context.Context, state multistep.StateBag) mu
tmpBuildDevices = append(tmpBuildDevices, "floppy0")
}

// Build the list back in our statebag
state.Put("temporaryDevices", tmpBuildDevices)
}

// Add our custom CD, if it exists
if cdPath, ok := state.GetOk("cd_path"); ok {
// Grab list of temporary builder devices so we can append the cd to it
tmpBuildDevices := state.Get("temporaryDevices").([]string)

if cdPath != "" {
diskAndCDConfigData := DefaultDiskAndCDROMTypes(s.DiskAdapterType, s.CDROMAdapterType)
cdromPrefix := diskAndCDConfigData.CDROMType + "1:" + diskAndCDConfigData.CDROMType_PrimarySecondary
vmxData[cdromPrefix+".present"] = "TRUE"
vmxData[cdromPrefix+".filename"] = cdPath.(string)
vmxData[cdromPrefix+".devicetype"] = "cdrom-image"

// Add it to our list of build devices to later remove
tmpBuildDevices = append(tmpBuildDevices, cdromPrefix)
// Add our custom CD, if it exists
if cdPath, ok := state.GetOk("cd_path"); ok {
if cdPath != "" {
diskAndCDConfigData := DefaultDiskAndCDROMTypes(s.DiskAdapterType, s.CDROMAdapterType)
cdromPrefix := diskAndCDConfigData.CDROMType + "1:" + diskAndCDConfigData.CDROMType_PrimarySecondary
vmxData[cdromPrefix+".present"] = "TRUE"
vmxData[cdromPrefix+".filename"] = cdPath.(string)
vmxData[cdromPrefix+".devicetype"] = "cdrom-image"

// Add it to our list of build devices to later remove
tmpBuildDevices = append(tmpBuildDevices, cdromPrefix)
}
}

// Build the list back in our statebag
Expand Down
2 changes: 1 addition & 1 deletion builder/vmware/iso/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
},
&vmwcommon.StepConfigureVMX{
CustomData: b.config.VMXDataPost,
SkipFloppy: true,
SkipDevices: true,
VMName: b.config.VMName,
DisplayName: b.config.VMXDisplayName,
},
Expand Down
2 changes: 1 addition & 1 deletion builder/vmware/vmx/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
},
&vmwcommon.StepConfigureVMX{
CustomData: b.config.VMXDataPost,
SkipFloppy: true,
SkipDevices: true,
VMName: b.config.VMName,
DisplayName: b.config.VMXDisplayName,
},
Expand Down

0 comments on commit f83a7fd

Please sign in to comment.