Skip to content

Commit cbe9796

Browse files
committed
Changed login logic for threads to use existing cli context.
1 parent 0838779 commit cbe9796

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

upi/vsphere/powercli/upi-functions.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ function New-OpenshiftVMs {
219219
}
220220

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

227227
$name = "$($metadata.infraID)-$($key)"
228228
Write-Output "Creating $($name)"
@@ -280,7 +280,7 @@ function New-OpenshiftVMs {
280280
else {
281281
$vm | Start-VM
282282
}
283-
} -ArgumentList @($key,$node,$vm_template,$metadata,$tag,$SCRIPTDIR)
283+
} -ArgumentList @($key,$node,$vm_template,$metadata,$tag,$SCRIPTDIR,$cliContext)
284284
Write-Progress -id 222 -Activity "Creating virtual machines" -PercentComplete ($vmStep * $vmCount)
285285
$vmCount++
286286
}

upi/vsphere/powercli/upi.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
$MYINV = $MyInvocation
44
$SCRIPTDIR = split-path $MYINV.MyCommand.Path
55

6+
Write-Output "SCRIPT DIR: $($SCRIPTDIR)"
7+
68
. .\variables.ps1
79
. ${SCRIPTDIR}\upi-functions.ps1
810

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

1517
# Connect to vCenter
1618
Connect-VIServer -Server $vcenter -Credential (Import-Clixml $vcentercredpath)
19+
$cliContext = Get-PowerCLIContext
1720

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

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

0 commit comments

Comments
 (0)