Skip to content

Instantly share code, notes, and snippets.

@Zsoldier
Created March 10, 2021 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zsoldier/9b99bb6df3bcdb4a86273da8905f9461 to your computer and use it in GitHub Desktop.
Save Zsoldier/9b99bb6df3bcdb4a86273da8905f9461 to your computer and use it in GitHub Desktop.
Get BGP route table information from NSX-T T0.
$NSXMgr = Read-Host "Please provide NSX-T DNS name or IP address."
$Credential = Get-Credential -Message "Please provide NSX-T username and password."
$skipcertcheck = $true
$AuthMethod = Basic
$policyapi = "/policy/api/v1"
$base_url = ("https://" + $NSXMgr + $policyapi)
$endpoint = "/infra/tier-0s/"
$T0List = Invoke-restmethod -Uri ($base_url + $endpoint) -Method GET -Credential $Credential -SkipCertificateCheck:$skipcertcheck -Authentication:$AuthMethod
Foreach ($T0 in $T0List.Results) {
$endpoint = ($T0List.Results.Path + "/locale-services")
$T0Locale = Invoke-restmethod -Uri ($base_url + $endpoint) -Method GET -Credential $Credential -SkipCertificateCheck:$skipcertcheck -Authentication:$AuthMethod
$EndPoint = ($T0Locale.Results.Path + "/bgp/neighbors/")
$T0Neighbors = Invoke-restmethod -Uri ($base_url + $endpoint) -Method GET -Credential $Credential -SkipCertificateCheck:$skipcertcheck -Authentication:$AuthMethod
$T0RouteData = @()
Foreach ($Neighbor in $T0Neighbors.results) {
$EndPoint = ($Neighbor.Path + "/routes")
$data = (Invoke-restmethod -Uri ($base_url + $endpoint) -Method GET -Credential $Credential -SkipCertificateCheck:$skipcertcheck -Authentication:$AuthMethod).results[0].egde_node_routes | % { $_.routes } | select network, as_path | Sort-Object network
Foreach ($route in $data) {
$tmpObj = "" | Select T0_id, network, as_path
$tmpObj.T0_id = $Neighbor.id
$tmpObj.network = $route.network
$tmpObj.as_path = $route.as_path
$T0RouteData += $tmpObj
}
$T0RouteData
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment