VMware Networking Community
moellerjot
Enthusiast
Enthusiast

Trigger NSX-V Upgrade/Logbundle via powershell

Hi,
something needfull for manual nsxv EDGE upgrades. 

GetEdgeTechsupport.ps1 -> Get NSX-V EDGE Logbundle via Powershell. 

 

Param(
  [Parameter(Mandatory=$True,Position=1)]
   [string]$edge_id
   )

$NSX_Manager = "nsxv.myhome.com"
$NSX_Manager_User = "admin"
$NSX_Manager_Password = "password"
$fileout="00_pre_"+$edge_id+"_logbundle.gz"

if (!(Test-Path ".\out\$edge_id"))
{
   New-Item ".\out\$edge_id" -itemType Directory
   write-host "mkdir ./out/$edge_id ..."
}

$userpass  = $NSX_Manager_User + ":" + $NSX_Manager_Password
$bytes= [System.Text.Encoding]::UTF8.GetBytes($userpass)
$encodedlogin=[Convert]::ToBase64String($bytes)
$authheader = "Basic " + $encodedlogin
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization",$authheader)
$headers.Add("Accept","application/xml")
$headers.Add("Content-Type","application/xml")

#Trigger Logbundle via API 
$uri = "https://$NSX_Manager/api/4.0/edges/$edge_id/techsupportlogs"

try {
    $response = Invoke-RestMethod  -SkipCertificateCheck  -Uri $uri -Headers $headers -Method Get -ContentType "application/json" -OutFile .\out\$edge_id\$fileout
} catch {
    Write-Host "Exception in GET Edges:" $_.Exception
    Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
    Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
}

 

 

SetEdgeUpgrade.ps1 -> Tigger NSX-V Upgrade via Powershell. 

 

Param(
  [Parameter(Mandatory=$True,Position=1)]
   [string]$edge_id
   )

$NSX_Manager = "nsxv.myserver.com"
$NSX_Manager_User = "admin"
$NSX_Manager_Password = "password"

#Authentication Header
$userpass  = $NSX_Manager_User + “:” + $NSX_Manager_Password
$bytes= [System.Text.Encoding]::UTF8.GetBytes($userpass)
$encodedlogin=[Convert]::ToBase64String($bytes)
$authheader = "Basic " + $encodedlogin
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization",$authheader)
$headers.Add("Accept","application/xml")
$headers.Add("Content-Type","application/xml")


#Trigger Update without Check
$uri = "https://$NSX_Manager/api/4.0/edges/$edge_id/?action=upgrade"

try {
    $response = Invoke-Webrequest  -SkipCertificateCheck  -Uri $uri -Headers $headers -Method POST -ContentType "application/xml"  
} catch {
    Write-Host "Exception in GET Edges:" $_.Exception
    Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
    Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
}

 

 

Source: https://docs.vmware.com/en/VMware-NSX-Data-Center-for-vSphere/6.4/nsx_64_api.pdf
# totally unsupported

Labels (2)
Reply
0 Kudos
0 Replies