[PowerShell] Getting VMware ESXi Host Results (backend storage) from OnCommand Insight Rest API

One of the most powerful abilities of NetApp's OnCommand Insight (and Cloud Insights) is the ability to do the end-to-end mapping from VM/datastore/ESXi host, back to the actual storage array and storage volume in question.

In the following piece of PowerShell, we get the storage information from a random ESXi host in the cluster, so we can use that data to more intelligently place VMs (i.e. trying not to oversubscribe storage arrays too much!)

Try{ ##LB1

$HostResults = Invoke-RestMethod -Uri "https://$($OCIs.server)/rest/v1/search?query=$($esxhost.value.split('.')[0])" -Headers $Headers

If ($HostResults.foundResults){ ##LB2

$StorageVolumes = (Invoke-RestMethod -Uri "https://$($OCIs.server)/rest/v1/assets/hosts/$($HostResults.tophit.id)/storageResources" -Headers $Headers) | Get-Random

If ($StorageVolumes){ ##LB3

$Array = Invoke-RestMethod -Uri "https://$($OCIs.server)/rest/v1/assets/volumes/$($StorageVolumes.id)/storage" -Headers $Headers

If ($Array){ ##LB4

$storagePools = Invoke-RestMethod -Uri "https://$($OCIs.server)/rest/v1/assets/storages/$($Array.ID)/storagePools" -Headers $Headers

} ##RB4

} ##RB3

} ##RB2

} ##RB1


~~~~~


Note: If you want tips on how to setup the $headers, the following NetApp community post is useful:

Solved: Update Annotations using REST API in OCI - NetApp Community

$AuthInfo = ("{0}:{1}" -f $Credentials.Username, $Credentials.Password )

$AuthInfo = [System.Text.Encoding]::UTF8.GetBytes( $AuthInfo )

$AuthInfo = [System.Convert]::ToBase64String( $AuthInfo )

$Headers  = @{ Authorization=( "Basic {0}" -f $AuthInfo ) }

Comments