Skip to content

Commit

Permalink
Changed login logic for threads to use existing cli context.
Browse files Browse the repository at this point in the history
  • Loading branch information
vr4manta committed Apr 15, 2024
1 parent 0838779 commit cbe9796
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions upi/vsphere/powercli/upi-functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ function New-OpenshiftVMs {
}

$jobs += Start-ThreadJob -n "create-vm-$($metadata.infraID)-$($key)" -ScriptBlock {
param($key,$node,$vm_template,$metadata,$tag,$scriptdir)
param($key,$node,$vm_template,$metadata,$tag,$scriptdir,$cliContext)
. .\variables.ps1
. ${scriptdir}\upi-functions.ps1
Connect-VIServer -Server $vcenter -Credential (Import-Clixml $vcentercredpath)
Use-PowerCLIContext -PowerCLIContext $cliContext

$name = "$($metadata.infraID)-$($key)"
Write-Output "Creating $($name)"
Expand Down Expand Up @@ -280,7 +280,7 @@ function New-OpenshiftVMs {
else {
$vm | Start-VM
}
} -ArgumentList @($key,$node,$vm_template,$metadata,$tag,$SCRIPTDIR)
} -ArgumentList @($key,$node,$vm_template,$metadata,$tag,$SCRIPTDIR,$cliContext)
Write-Progress -id 222 -Activity "Creating virtual machines" -PercentComplete ($vmStep * $vmCount)
$vmCount++
}
Expand Down
9 changes: 6 additions & 3 deletions upi/vsphere/powercli/upi.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
$MYINV = $MyInvocation
$SCRIPTDIR = split-path $MYINV.MyCommand.Path

Write-Output "SCRIPT DIR: $($SCRIPTDIR)"

. .\variables.ps1
. ${SCRIPTDIR}\upi-functions.ps1

Expand All @@ -14,6 +16,7 @@ $Env:GOVC_INSECURE = 1

# Connect to vCenter
Connect-VIServer -Server $vcenter -Credential (Import-Clixml $vcentercredpath)
$cliContext = Get-PowerCLIContext

if ($downloadInstaller) {
Write-Output "Downloading the most recent $($version) installer"
Expand Down Expand Up @@ -186,14 +189,14 @@ foreach ($fd in $fds)
$ovfConfig.NetworkMapping.VM_Network.Value = $fd.network
Write-Output "OVF: $($ovfConfig)"
$jobs += Start-ThreadJob -n "upload-template-$($fd.cluster)" -ScriptBlock {
param($Version,$vm_template,$ovfConfig,$vmhost,$datastoreInfo,$folder,$tag,$scriptdir)
param($Version,$vm_template,$ovfConfig,$vmhost,$datastoreInfo,$folder,$tag,$scriptdir,$cliContext)
. .\variables.ps1
. ${scriptdir}\upi-functions.ps1
Write-Output "Version: $($Version)"
Write-Output "VM Template: $($vm_template)"
Write-Output "OVF Config: $($ovfConfig)"
Write-Output "VM Host: $($vmhost)"
Connect-VIServer -Server $vcenter -Credential (Import-Clixml $vcentercredpath)
Use-PowerCLIContext -PowerCLIContext $cliContext
$template = Import-Vapp -Source "template-$($Version).ova" -Name $vm_template -OvfConfiguration $ovfConfig -VMHost $vmhost -Datastore $datastoreInfo -InventoryLocation $folder -Force:$true

$templateVIObj = Get-View -VIObject $template.Name
Expand All @@ -212,7 +215,7 @@ foreach ($fd in $fds)
New-AdvancedSetting -Entity $template -name "disk.EnableUUID" -value 'TRUE' -confirm:$false -Force > $null
New-AdvancedSetting -Entity $template -name "guestinfo.ignition.config.data.encoding" -value "base64" -confirm:$false -Force > $null
#$snapshot = New-Snapshot -VM $template -Name "linked-clone" -Description "linked-clone" -Memory -Quiesce
} -ArgumentList @($Version,$vm_template,$ovfConfig,$vmhost,$datastoreInfo,$folder,$tag,$SCRIPTDIR)
} -ArgumentList @($Version,$vm_template,$ovfConfig,$vmhost,$datastoreInfo,$folder,$tag,$SCRIPTDIR,$cliContext)
}
}

Expand Down

0 comments on commit cbe9796

Please sign in to comment.