1
0
mirror of https://github.com/openshift/installer.git synced 2026-02-05 06:46:36 +01:00

Added creation and cleanup of resource pools.

This commit is contained in:
vr4manta
2024-03-27 11:30:15 -04:00
parent e1d7096ec0
commit 797268a09a
2 changed files with 20 additions and 3 deletions

View File

@@ -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) {

View File

@@ -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