Reputation: 1
How can i fetch the cluster report from the Nutanix prism portal using powershell (API or module)?
I need to fetch the cluster details like total capacity, free capacity, usage capacity etc.
Upvotes: 0
Views: 1103
Reputation: 3181
There seems to be a lot of confusion (at least for me) regarding what version of the API you have. Below is my configuration with the API version listed at the bottom. If you have what I have, you have the API that I have.
Prism Central:
Prism Element:
Common Code:
#This looks stupid, but you need the plaintext password later
$Pwd="<password>"
$SecurePwd=ConvertTo-SecureString -String $Pwd -AsPlainText -Force
$Cred=[System.Management.Automation.PSCredential]::new("<user name>",$SecurePwd)
#region you only need this section if you don't trust the certificate
$TypeDef=@"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; }
}
"@
Add-Type -TypeDefinition $TypeDef -Language CSharp
[System.Net.ServicePointManager]::CertificatePolicy=New-Object TrustAllCertsPolicy
#endregion
$SecureBase64AuthInfo=[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $Cred.UserName,$Cred.Password)))
$Base64AuthInfo=[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $Cred.UserName,$Pwd)))
Prism Central:
$Header=@{Accept="application/json";Authorization="Basic $SecureBase64AuthInfo"}
$URI="https://<name or IP of central>:9440/PrismGateway/services/rest/v2.0/"
$Command="cluster"
$Central=Invoke-WebRequest -Method Get -Uri ($URI+$Command) -Credential $Cred -ContentType "application/json" -Headers $Header | Select-Object -ExpandProperty Content | ConvertFrom-Json
Prism Element:
$Header=@{Accept="application/json";Authorization="Basic $Base64AuthInfo"}
$URI="https://<name or IP of element>:9440/api/nutanix/v3/clusters/list"
$Body='{"kind":"cluster"}'
$Element=Invoke-WebRequest -Method Post -Uri $URI -Credential $Cred -ContentType "application/json" -Headers $Header -Body $Body -UseBasicParsing Select-Object -ExpandProperty Content | ConvertFrom-Json
Question Specific Answer:
If you use my code, I think you're looking for $Central.usage_stats
.
Upvotes: 0
Reputation: 21
There's a few options, one of them would be using:
Alternatively there's nutanix.dev with a whole bunch of examples you can use to get this kickstarted
disclaimer: I'm a Nutanix employee and author of the script in the first link.
Upvotes: 2