From 797268a09afa4fc6e7bedce14b6de075cb32e1d1 Mon Sep 17 00:00:00 2001 From: vr4manta Date: Wed, 27 Mar 2024 11:30:15 -0400 Subject: [PATCH] Added creation and cleanup of resource pools. --- upi/vsphere/upi-destroy.ps1 | 9 ++++++++- upi/vsphere/upi.ps1 | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/upi/vsphere/upi-destroy.ps1 b/upi/vsphere/upi-destroy.ps1 index 6e3586478c..922fdce861 100644 --- a/upi/vsphere/upi-destroy.ps1 +++ b/upi/vsphere/upi-destroy.ps1 @@ -15,7 +15,7 @@ Connect-VIServer -Server $vcenter -Credential (Import-Clixml $vcentercredpath) $metadata = Get-Content -Path ./metadata.json | ConvertFrom-Json # Get tag for all resources we created -$tagCategory = Get-TagCategory -Name "openshift-$($metadata.infraID)" +$tagCategory = Get-TagCategory -Name "pwsh-upi-$($metadata.infraID)" $tag = Get-Tag -Category $tagCategory -Name "$($metadata.infraID)" # Clean up all VMs @@ -61,6 +61,13 @@ foreach ($policy in $storagePolicies) { } } +# Clean up all resource pools +$rps = Get-TagAssignment -Tag $tag -Entity (Get-ResourcePool) +foreach ($rp in $rps) { + Write-Output "Removing resource pool $($rp.Entity)" + Remove-ResourcePool -ResourcePool $($rp.Entity) -confirm:$false +} + # Clean up all folders $folders = Get-TagAssignment -Tag $tag -Entity (Get-Folder) foreach ($folder in $folders) { diff --git a/upi/vsphere/upi.ps1 b/upi/vsphere/upi.ps1 index 72786b5487..c2d81a355f 100644 --- a/upi/vsphere/upi.ps1 +++ b/upi/vsphere/upi.ps1 @@ -160,6 +160,16 @@ foreach ($fd in $fds) New-TagAssignment -Entity $folder -Tag $tag > $null } + # Create resource pool for all future VMs + Write-Output "Checking for resource pool in failure domain $($fd.datacenter)/$($fd.cluster)" + $rp = Get-ResourcePool -Name $($metadata.infraID) -Location $(Get-Cluster -Name $($fd.cluster)) -ErrorAction continue 2>$null + + if (-Not $?) { + Write-Output "Creating resource pool $($metadata.infraID) in datacenter $($fd.datacenter)" + $rp = New-ResourcePool -Name $($metadata.infraID) -Location $(Get-Cluster -Name $($fd.cluster)) + New-TagAssignment -Entity $rp -Tag $tag > $null + } + # If the rhcos virtual machine already exists Write-Output "Checking for vm template in failure domain $($fd.datacenter)/$($fd.cluster)" $template = Get-VM -Name $vm_template -Location $fd.datacenter -ErrorAction continue @@ -215,7 +225,7 @@ if ($jobs.count -gt 0) Write-Output "Creating LB" # Data needed for LB VM creation -$rp = Get-Cluster -Name $fds[0].cluster -Server $vcenter +$rp = Get-ResourcePool -Name $($metadata.infraID) -Location $(Get-Cluster -Name $($fds[0].cluster)) -Server $vcenter $datastoreInfo = Get-Datastore -Name $fds[0].datastore -Server $vcenter -Location $fds[0].datacenter $folder = Get-Folder -Name $metadata.infraID -Location $fds[0].datacenter $template = Get-VM -Name $vm_template -Location $fds[0].datacenter @@ -250,7 +260,7 @@ foreach ($key in $vmHash.virtualmachines.Keys) { $name = "$($metadata.infraID)-$($key)" Write-Output "Creating $($name)" - $rp = Get-Cluster -Name $node.cluster -Server $node.server + $rp = Get-ResourcePool -Name $($metadata.infraID) -Location $(Get-Cluster -Name $($node.cluster)) -Server $vcenter ##$datastore = Get-Datastore -Name $node.datastore -Server $node.server $datastoreInfo = Get-Datastore -Name $node.datastore -Location $node.datacenter