Skip to content

Commit 963999c

Browse files
committed
Reduced number of VMs to create at once.
1 parent 797268a commit 963999c

File tree

3 files changed

+95
-2
lines changed

3 files changed

+95
-2
lines changed

upi/vsphere/upi-destroy.ps1

Lines changed: 1 addition & 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 "pwsh-upi-$($metadata.infraID)"
18+
$tagCategory = Get-TagCategory -Name "openshift-$($metadata.infraID)"
1919
$tag = Get-Tag -Category $tagCategory -Name "$($metadata.infraID)"
2020

2121
# Clean up all VMs

upi/vsphere/upi-functions.ps1

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,93 @@ function New-VMNetworkConfig {
198198
}
199199
"@
200200
return ConvertFrom-Json -InputObject $network
201+
}
202+
203+
function New-OpenshiftVMs {
204+
param(
205+
$NodeType
206+
)
207+
208+
Write-Output "Creating $($NodeType) VMs"
209+
210+
$jobs = @()
211+
$vmStep = (100 / $vmHash.virtualmachines.Count)
212+
$vmCount = 1
213+
foreach ($key in $vmHash.virtualmachines.Keys) {
214+
$node = $vmHash.virtualmachines[$key]
215+
216+
if ($NodeType -ne $node.type) {
217+
continue
218+
}
219+
220+
$jobs += Start-ThreadJob -n "create-vm-$($metadata.infraID)-$($key)" -ScriptBlock {
221+
param($key,$node,$vm_template,$metadata,$tag)
222+
. .\variables.ps1
223+
. .\upi-functions.ps1
224+
Connect-VIServer -Server $vcenter -Credential (Import-Clixml $vcentercredpath)
225+
226+
$name = "$($metadata.infraID)-$($key)"
227+
Write-Output "Creating $($name)"
228+
229+
$rp = Get-ResourcePool -Name $($metadata.infraID) -Location $(Get-Cluster -Name $($node.cluster)) -Server $vcenter
230+
##$datastore = Get-Datastore -Name $node.datastore -Server $node.server
231+
$datastoreInfo = Get-Datastore -Name $node.datastore -Location $node.datacenter
232+
233+
# Pull network config for each node
234+
if ($node.type -eq "master") {
235+
$numCPU = $control_plane_num_cpus
236+
$memory = $control_plane_memory
237+
} elseif ($node.type -eq "worker") {
238+
$numCPU = $compute_num_cpus
239+
$memory = $compute_memory
240+
} else {
241+
# should only be bootstrap
242+
$numCPU = $control_plane_num_cpus
243+
$memory = $control_plane_memory
244+
}
245+
$ip = $node.ip
246+
$network = New-VMNetworkConfig -Hostname $name -IPAddress $ip -Netmask $netmask -Gateway $gateway -DNS $dns
247+
248+
# Get the content of the ignition file per machine type (bootstrap, master, worker)
249+
$bytes = Get-Content -Path "./$($node.type).ign" -AsByteStream
250+
$ignition = [Convert]::ToBase64String($bytes)
251+
252+
# Get correct template / folder
253+
$folder = Get-Folder -Name $metadata.infraID -Location $node.datacenter
254+
$template = Get-VM -Name $vm_template -Location $($node.datacenter)
255+
256+
# Clone the virtual machine from the imported template
257+
#$vm = New-OpenShiftVM -Template $template -Name $name -ResourcePool $rp -Datastore $datastoreInfo -Location $folder -LinkedClone -ReferenceSnapshot $snapshot -IgnitionData $ignition -Tag $tag -Networking $network -NumCPU $numCPU -MemoryMB $memory
258+
$vm = New-OpenShiftVM -Template $template -Name $name -ResourcePool $rp -Datastore $datastoreInfo -Location $folder -IgnitionData $ignition -Tag $tag -Networking $network -Network $node.network -NumCPU $numCPU -MemoryMB $memory
259+
260+
# Assign tag so we can later clean up
261+
# New-TagAssignment -Entity $vm -Tag $tag
262+
# New-AdvancedSetting -Entity $vm -name "guestinfo.ignition.config.data" -value $ignition -confirm:$false -Force > $null
263+
# New-AdvancedSetting -Entity $vm -name "guestinfo.hostname" -value $name -Confirm:$false -Force > $null
264+
265+
if ($node.type -eq "master" -And $delayVMStart) {
266+
# To give bootstrap some time to start, lets wait 2 minutes
267+
Start-ThreadJob -ThrottleLimit 5 -InputObject $vm {
268+
Start-Sleep -Seconds 90
269+
$input | Start-VM
270+
}
271+
} elseif ($node.type -eq "worker" -And $delayVMStart) {
272+
# Workers are not needed right away, gotta wait till masters
273+
# have started machine-server. wait 7 minutes to start.
274+
Start-ThreadJob -ThrottleLimit 5 -InputObject $vm {
275+
Start-Sleep -Seconds 600
276+
$input | Start-VM
277+
}
278+
}
279+
else {
280+
$vm | Start-VM
281+
}
282+
} -ArgumentList @($key,$node,$vm_template,$metadata,$tag)
283+
Write-Progress -id 222 -Activity "Creating virtual machines" -PercentComplete ($vmStep * $vmCount)
284+
$vmCount++
285+
}
286+
Wait-Job -Job $jobs
287+
foreach ($job in $jobs) {
288+
Receive-Job -Job $job
289+
}
201290
}

upi/vsphere/upi.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ $vmHash = ConvertFrom-Json -InputObject $virtualmachines -AsHashtable
245245

246246
Write-Progress -id 222 -Activity "Creating virtual machines" -PercentComplete 0
247247

248+
New-OpenshiftVMs "bootstrap"
249+
New-OpenshiftVMs "master"
250+
New-OpenshiftVMs "worker"
251+
<#
248252
$jobs = @()
249253
$vmStep = (100 / $vmHash.virtualmachines.Count)
250254
$vmCount = 1
@@ -321,7 +325,7 @@ Wait-Job -Job $jobs
321325
foreach ($job in $jobs) {
322326
Receive-Job -Job $job
323327
}
324-
328+
#>
325329
Write-Progress -id 222 -Activity "Completed virtual machines" -PercentComplete 100 -Completed
326330

327331
## This is nice to have to clear screen when doing things manually. Maybe i'll

0 commit comments

Comments
 (0)