Merge pull request #7048 from hashicorp/follow_up_7019

fix defaulting/lack thereof for cpu count and memory in vmware template
This commit is contained in:
Adrien Delorme 2018-11-28 11:08:14 +01:00 committed by GitHub
commit 2174652876
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 10 deletions

View File

@ -49,7 +49,10 @@ func (a *artifact) State(name string) interface{} {
}
func (a *artifact) Destroy() error {
return a.dir.RemoveAll()
if a.dir != nil {
return a.dir.RemoveAll()
}
return nil
}
func NewArtifact(remoteType string, format string, exportOutputPath string, vmName string, skipExport bool, keepRegistered bool, state multistep.StateBag) (packer.Artifact, error) {

View File

@ -315,6 +315,18 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist
templateData.Serial_Host = ""
templateData.Serial_Auto = "FALSE"
// Set the number of cpus if it was specified
if config.HWConfig.CpuCount > 0 {
templateData.CpuCount = strconv.Itoa(config.HWConfig.CpuCount)
}
// Apply the memory size that was specified
if config.HWConfig.MemorySize > 0 {
templateData.MemorySize = strconv.Itoa(config.HWConfig.MemorySize)
} else {
templateData.MemorySize = "512"
}
switch serial.Union.(type) {
case *vmwcommon.SerialConfigPipe:
templateData.Serial_Type = "pipe"
@ -412,15 +424,8 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist
/// Now to handle options that will modify the template
vmxData := vmwcommon.ParseVMX(vmxContents)
// Set the number of cpus if it was specified
if config.HWConfig.CpuCount > 0 {
vmxData["numvcpus"] = strconv.Itoa(config.HWConfig.CpuCount)
}
// Apply the memory size that was specified
if config.HWConfig.MemorySize > 0 {
vmxData["memsize"] = strconv.Itoa(config.HWConfig.MemorySize)
if vmxData["numvcpus"] == "" {
delete(vmxData, "numvcpus")
}
/// Write the vmxData to the vmxPath