Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion upi/vsphere/powercli/upi-functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = @"
{
Expand Down
3 changes: 2 additions & 1 deletion upi/vsphere/powercli/upi.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down