Hi Team,
I need an API which can give real time information about the VMs which are added in VMgroup/sub client for all vmgroups and VMware centers configured in CommCell console.
Let me know if this is possible.
Regards,Mohit
Hi Team,
I need an API which can give real time information about the VMs which are added in VMgroup/sub client for all vmgroups and VMware centers configured in CommCell console.
Let me know if this is possible.
Regards,Mohit
Best answer by christopherlecky
There is another way to do this;
You can refresh the datacenter from CommVault. The reason why I initially suggested you get the data from the Vmware is that by default commvault only sees the VMs that are defined within it’s sub clients, and even then the date is only as up to date as the last backup. You can do a datacenter refresh against your Vcenters, you will need the Vcenter instance information in order to do it.
I took the liberty of modifying Abdul’s code to add a function to do the DC refresh.
Once again zero testing, so it most likely fail on line 38, because I wrote the code from the instance properties, this also finds all virtual server instances, so you may want to filter for that.
$CV = CVCS.HOME.COM
Function Get-CVToken {
[CmdletBinding(
)]
Param (
[Parameter(Mandatory=$True)]
[string]$UserName,
[Parameter(
Mandatory = $True,
ParameterSetName = 'Secret'
)]
[Security.SecureString]$Password
)
#Write-Verbose $Password
$headers = @{}
$headers.Add("Content-Type","application/json")
$headers.Add("Accept","application/json")
$plainPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password))
#Write-Verbose $UserName
#Write-Verbose $plainPassword
$encPassword = [convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($plainPassword))
$body = @{username=$userName;password=$encPassword;}
$response = Invoke-RestMethod "http://$CV/webconsole/api/login" -Method Post -Headers $headers -Body $($body | ConvertTo-Json)
Write-Verbose $response.token
$Global:cvToken = $response.token
}
function RefreshVcenters {
param ()
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept","application/json")
$headers.Add("AuthToken", $Global:cvToken)
$headers.Add("PagingInfo","0,10000")
$vCenterinfo = Invoke-RestMethod "http://$CV/webconsole/api/instance/byName(appName='Virtual Server'))" -Method Get -Headers $headers #
$vCenterinfo.foreach{ #Perform Datacenter Refresh against vCenterID
$body = '<?xml version="1.0" encoding="UTF-8" standalone="no" ?><EVGui_RefreshTemplateInformationReq clientId="0" flags="0" instanceId="' + $_.instanceproperties.instance.instanceID + '"/>'
Invoke-RestMethod "http://$CV/webconsole/api/VM?status=0" -Method Get -Headers $headers -Body $body
}
}
function StageVMData {
param ()
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept","application/json")
$headers.Add("AuthToken", $Global:cvToken)
$headers.Add("PagingInfo","0,10000")
$body = ""
$response = Invoke-RestMethod "http://$CV/webconsole/api/VM?status=0" -Method Get -Headers $headers
$Global:CVVMData = $response
}
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.