JimKnopf99
Commander
Commander

REST API

Hi,

i have a question about the REST API. I would like to add a VM into Maintenace mode during backup time. I create the following script.

$vrealize = "vrealize"

$username = "maintenance";

$password = ConvertTo-SecureString –String "password" –AsPlainText -Force

$credential = New-Object –TypeName "System.Management.Automation.PSCredential" –ArgumentList $username, $password

$data = Invoke-RestMethod -Method Get -uri "https://$vrealize/suite-api/api/resources/" -Credential $credential

#Put in Maintenance Mode

Invoke-RestMethod -Method Put -uri "https://$vrealize/suite-api/api/resources/"VMname"/maintained" -Credential $credential

#Remove from Maintenance Mode

Invoke-RestMethod -Method delete -uri "https://$vrealize/suite-api/api/resources/"VMname"/maintained" -Credential $credential

The Script is working. The question is, if i have multiple adapters, like the End Point Agent Adapter, i also have multiple entries of my vm´s when browsing the inventory explorer.

One for vCenter Adapter and multiple entries for EP Ops Adapter. One Agent Entry, one Windows or Linux entry and one MSSQL entry if it is installed on the VM.

With the script above, it is only possible to add the vm that is located under the vcenter adapter into maintenance.

How is it possible to find the id for the other adapters to add the vm for all installed adapters into maintenance?

Thanks

Frank

If you find this information useful, please award points for "correct" or "helpful".
0 Kudos
1 Reply
dtaliafe
Hot Shot
Hot Shot

There are a couple of ways you can do this.

You can get all the objects with the VM name:

https://{{vrops}}/suite-api/api/resources?name=vmname

Each of the results will have a value named "identifier".  This is the ID of the object that you can use to put it in maintenance.

For example:

https://{{vrops}}/suite-api/api/resources/d94015b4-4513-486d-8370-59bfe9601937/maintained

Alternatively, you can be more specific when querying for resources.  For example you can specify the type or "resourcKind" as it's referred to in the API.

This will get only the one for Windows:

https://{{vrops}}/suite-api/api/resources?resourceKind=Windows&name=vmname

Check out the "getResources" method in the API doc for all the properties you can query on.

0 Kudos