Skip to content

Commit 0f9f15b

Browse files
committed
Created new function to workaround issue with Set-HardDisk.
1 parent 65b89ed commit 0f9f15b

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

upi/vsphere/powercli/upi-functions.ps1

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ function New-OpenShiftVM {
5353
{
5454
Set-VM -VM $vm -MemoryMB $MemoryMB -NumCpu $NumCpu -CoresPerSocket 4 -Confirm:$false > $null
5555
}
56-
Get-HardDisk -VM $vm | Select-Object -First 1 | Set-HardDisk -CapacityGB 120 -Confirm:$false > $null
56+
#Get-HardDisk -VM $vm | Select-Object -First 1 | Set-HardDisk -CapacityGB 120 -Confirm:$false > $null
57+
updateDisk -VM $vm -CapacityGB 120
5758

5859
# Configure Network (Assuming template networking may not be correct if shared across clusters)
5960
$pg = Get-VirtualPortgroup -Name $Network -VMHost $(Get-VMHost -VM $vm) 2> $null
@@ -78,6 +79,38 @@ function New-OpenShiftVM {
7879
return $vm
7980
}
8081

82+
# This function was created to work around issue in vSphere 8.0 where vCenter crashed
83+
# when Set-HardDisk is called.
84+
function updateDisk {
85+
param (
86+
$CapacityGB,
87+
$VM
88+
)
89+
90+
$newDiskSizeKB = $CapacityGB * 1024 * 1024
91+
$newDiskSizeBytes = $newDiskSizeKB * 1024
92+
93+
$vmMo = get-view -id $VM.ExtensionData.MoRef
94+
95+
$devices = $vmMo.Config.Hardware.Device
96+
97+
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
98+
$spec.DeviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec[] (1)
99+
$spec.DeviceChange[0] = New-Object VMware.Vim.VirtualDeviceConfigSpec
100+
$spec.DeviceChange[0].Operation = 'edit'
101+
102+
foreach($d in $devices) {
103+
if ($d.DeviceInfo.Label.Contains("Hard disk")) {
104+
$spec.DeviceChange[0].Device = $d
105+
}
106+
}
107+
108+
$spec.DeviceChange[0].Device.CapacityInBytes = $newDiskSizeBytes
109+
$spec.DeviceChange[0].Device.CapacityInKB = $newDiskSizeKB
110+
111+
$vmMo.ReconfigVM_Task($spec) > $null
112+
}
113+
81114
function New-VMConfigs {
82115
$virtualMachines = @"
83116
{

upi/vsphere/powercli/upi.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ foreach ($fd in $fds)
211211

212212
New-TagAssignment -Entity $template -Tag $tag
213213
Set-VM -VM $template -MemoryGB 16 -NumCpu 4 -CoresPerSocket 4 -Confirm:$false > $null
214-
Get-HardDisk -VM $template | Select-Object -First 1 | Set-HardDisk -CapacityGB 120 -Confirm:$false > $null
214+
#Get-HardDisk -VM $template | Select-Object -First 1 | Set-HardDisk -CapacityGB 120 -Confirm:$false > $null
215+
updateDisk -VM $template -CapacityGB 120
215216
New-AdvancedSetting -Entity $template -name "disk.EnableUUID" -value 'TRUE' -confirm:$false -Force > $null
216217
New-AdvancedSetting -Entity $template -name "guestinfo.ignition.config.data.encoding" -value "base64" -confirm:$false -Force > $null
217218
#$snapshot = New-Snapshot -VM $template -Name "linked-clone" -Description "linked-clone" -Memory -Quiesce

0 commit comments

Comments
 (0)