Skip to content

Commit 797268a

Browse files
committed
Added creation and cleanup of resource pools.
1 parent e1d7096 commit 797268a

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

upi/vsphere/upi-destroy.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Connect-VIServer -Server $vcenter -Credential (Import-Clixml $vcentercredpath)
1515
$metadata = Get-Content -Path ./metadata.json | ConvertFrom-Json
1616

1717
# Get tag for all resources we created
18-
$tagCategory = Get-TagCategory -Name "openshift-$($metadata.infraID)"
18+
$tagCategory = Get-TagCategory -Name "pwsh-upi-$($metadata.infraID)"
1919
$tag = Get-Tag -Category $tagCategory -Name "$($metadata.infraID)"
2020

2121
# Clean up all VMs
@@ -61,6 +61,13 @@ foreach ($policy in $storagePolicies) {
6161
}
6262
}
6363

64+
# Clean up all resource pools
65+
$rps = Get-TagAssignment -Tag $tag -Entity (Get-ResourcePool)
66+
foreach ($rp in $rps) {
67+
Write-Output "Removing resource pool $($rp.Entity)"
68+
Remove-ResourcePool -ResourcePool $($rp.Entity) -confirm:$false
69+
}
70+
6471
# Clean up all folders
6572
$folders = Get-TagAssignment -Tag $tag -Entity (Get-Folder)
6673
foreach ($folder in $folders) {

upi/vsphere/upi.ps1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ foreach ($fd in $fds)
160160
New-TagAssignment -Entity $folder -Tag $tag > $null
161161
}
162162

163+
# Create resource pool for all future VMs
164+
Write-Output "Checking for resource pool in failure domain $($fd.datacenter)/$($fd.cluster)"
165+
$rp = Get-ResourcePool -Name $($metadata.infraID) -Location $(Get-Cluster -Name $($fd.cluster)) -ErrorAction continue 2>$null
166+
167+
if (-Not $?) {
168+
Write-Output "Creating resource pool $($metadata.infraID) in datacenter $($fd.datacenter)"
169+
$rp = New-ResourcePool -Name $($metadata.infraID) -Location $(Get-Cluster -Name $($fd.cluster))
170+
New-TagAssignment -Entity $rp -Tag $tag > $null
171+
}
172+
163173
# If the rhcos virtual machine already exists
164174
Write-Output "Checking for vm template in failure domain $($fd.datacenter)/$($fd.cluster)"
165175
$template = Get-VM -Name $vm_template -Location $fd.datacenter -ErrorAction continue
@@ -215,7 +225,7 @@ if ($jobs.count -gt 0)
215225
Write-Output "Creating LB"
216226

217227
# Data needed for LB VM creation
218-
$rp = Get-Cluster -Name $fds[0].cluster -Server $vcenter
228+
$rp = Get-ResourcePool -Name $($metadata.infraID) -Location $(Get-Cluster -Name $($fds[0].cluster)) -Server $vcenter
219229
$datastoreInfo = Get-Datastore -Name $fds[0].datastore -Server $vcenter -Location $fds[0].datacenter
220230
$folder = Get-Folder -Name $metadata.infraID -Location $fds[0].datacenter
221231
$template = Get-VM -Name $vm_template -Location $fds[0].datacenter
@@ -250,7 +260,7 @@ foreach ($key in $vmHash.virtualmachines.Keys) {
250260
$name = "$($metadata.infraID)-$($key)"
251261
Write-Output "Creating $($name)"
252262

253-
$rp = Get-Cluster -Name $node.cluster -Server $node.server
263+
$rp = Get-ResourcePool -Name $($metadata.infraID) -Location $(Get-Cluster -Name $($node.cluster)) -Server $vcenter
254264
##$datastore = Get-Datastore -Name $node.datastore -Server $node.server
255265
$datastoreInfo = Get-Datastore -Name $node.datastore -Location $node.datacenter
256266

0 commit comments

Comments
 (0)