From 0f9f15baac5ffc90b8a0e131d00147cca3e57189 Mon Sep 17 00:00:00 2001 From: vr4manta Date: Thu, 25 Apr 2024 07:35:08 -0400 Subject: [PATCH] Created new function to workaround issue with Set-HardDisk. --- upi/vsphere/powercli/upi-functions.ps1 | 35 +++++++++++++++++++++++++- upi/vsphere/powercli/upi.ps1 | 3 ++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/upi/vsphere/powercli/upi-functions.ps1 b/upi/vsphere/powercli/upi-functions.ps1 index 5bd123ce79e..d43b782e9f2 100644 --- a/upi/vsphere/powercli/upi-functions.ps1 +++ b/upi/vsphere/powercli/upi-functions.ps1 @@ -53,7 +53,8 @@ function New-OpenShiftVM { { Set-VM -VM $vm -MemoryMB $MemoryMB -NumCpu $NumCpu -CoresPerSocket 4 -Confirm:$false > $null } - Get-HardDisk -VM $vm | Select-Object -First 1 | Set-HardDisk -CapacityGB 120 -Confirm:$false > $null + #Get-HardDisk -VM $vm | Select-Object -First 1 | Set-HardDisk -CapacityGB 120 -Confirm:$false > $null + updateDisk -VM $vm -CapacityGB 120 # Configure Network (Assuming template networking may not be correct if shared across clusters) $pg = Get-VirtualPortgroup -Name $Network -VMHost $(Get-VMHost -VM $vm) 2> $null @@ -78,6 +79,38 @@ function New-OpenShiftVM { return $vm } +# This function was created to work around issue in vSphere 8.0 where vCenter crashed +# when Set-HardDisk is called. +function updateDisk { + param ( + $CapacityGB, + $VM + ) + + $newDiskSizeKB = $CapacityGB * 1024 * 1024 + $newDiskSizeBytes = $newDiskSizeKB * 1024 + + $vmMo = get-view -id $VM.ExtensionData.MoRef + + $devices = $vmMo.Config.Hardware.Device + + $spec = New-Object VMware.Vim.VirtualMachineConfigSpec + $spec.DeviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec[] (1) + $spec.DeviceChange[0] = New-Object VMware.Vim.VirtualDeviceConfigSpec + $spec.DeviceChange[0].Operation = 'edit' + + foreach($d in $devices) { + if ($d.DeviceInfo.Label.Contains("Hard disk")) { + $spec.DeviceChange[0].Device = $d + } + } + + $spec.DeviceChange[0].Device.CapacityInBytes = $newDiskSizeBytes + $spec.DeviceChange[0].Device.CapacityInKB = $newDiskSizeKB + + $vmMo.ReconfigVM_Task($spec) > $null +} + function New-VMConfigs { $virtualMachines = @" { diff --git a/upi/vsphere/powercli/upi.ps1 b/upi/vsphere/powercli/upi.ps1 index 330c5b732f2..81d7b6106d5 100644 --- a/upi/vsphere/powercli/upi.ps1 +++ b/upi/vsphere/powercli/upi.ps1 @@ -211,7 +211,8 @@ foreach ($fd in $fds) New-TagAssignment -Entity $template -Tag $tag Set-VM -VM $template -MemoryGB 16 -NumCpu 4 -CoresPerSocket 4 -Confirm:$false > $null - Get-HardDisk -VM $template | Select-Object -First 1 | Set-HardDisk -CapacityGB 120 -Confirm:$false > $null + #Get-HardDisk -VM $template | Select-Object -First 1 | Set-HardDisk -CapacityGB 120 -Confirm:$false > $null + updateDisk -VM $template -CapacityGB 120 New-AdvancedSetting -Entity $template -name "disk.EnableUUID" -value 'TRUE' -confirm:$false -Force > $null New-AdvancedSetting -Entity $template -name "guestinfo.ignition.config.data.encoding" -value "base64" -confirm:$false -Force > $null #$snapshot = New-Snapshot -VM $template -Name "linked-clone" -Description "linked-clone" -Memory -Quiesce