Skip to content

Commit

Permalink
Added creation and cleanup of resource pools.
Browse files Browse the repository at this point in the history
  • Loading branch information
vr4manta committed Mar 27, 2024
1 parent 6d826ab commit b643235
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 8 additions & 1 deletion upi/vsphere/upi-destroy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 12 additions & 2 deletions upi/vsphere/upi.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit b643235

Please sign in to comment.