How to get the IP address of a VM in vRealize Automation 7 REST API

In my last post I showed you how to script a REST API request in vRealize Automation 7. Now let’s close the loop and get the details of that request. In this guide I will show you how to retrieve the IP address of a provisioned item. You can then use this as a building block for more advanced REST calls or integrations.

Pre-Reqs:

  • A working vRA 7 Blueprint provisioned and viewable in the items view in the vRA portal.
  • A linux system with a command line that you can run curl from to connect to the vRealize Appliance API
  • An account with access to vRA 7 that can list details of a provisioned item.

On your Linux system with Curl we will need to set some environment variables to save us time. Let’s export the vRA appliance host name.

export VRA=vra-01a.corp.local

Create variable for the HTTP Accept header, which tells the server what format you want the response to be in.

export ACCEPT="application/json"

Here we will authenticate by requesting a bearer token via a POST against /identity/api/tokens API, and we will store the bearer token in a variable so we can use it on future API invocations. This example passes cloudadmins credentials (vsphere.local tenant) with inline JSON, but you could also create variables or store this JSON in a file and use the file instead.

curl --insecure -H "Accept: application/json" -H 'Content-Type: application/json' --data '{"username":"tony@corp.local","password":"VMware1!","tenant":"vsphere.local"}' https://$VRA/identity/api/tokens

Now let’s grab the bearer token from the response above. Highlight all the text between the quotes as shown and copy it to the clip board

Now we will export the token to a variable like below

export AUTH="Bearer MTQ0OTYwMjc2MDI4NToyODlmZWM2MjZlNzNkMDAwZmRmYjp0ZW5hbnQ6dnNwaGVyZS5sb2NhbHVzZXJuYW1lOnRvbnlAY29ycC5sb2NhbGV4cGlyYXRpb246MTQ0OTYzMTU2MDAwMDo4MzE3NThmNjhjZTNjNzg5MDNiMWM3ODdlODBmMDQ3NGYzNmYwMzBkYWFjNGM4Y2I3YTk5YmY1ODBmN2E4N2IyNzM4MTRhM2M3NmQzNzM3ZTUzMmZjZDI4OGEwZTI0OTA4NTZjMDg3YTQ2NzRjMjczZTIyOTQyZGJlOWQwNDU2NQ=="

Ok, now let’s list the provisioned resources. Enter the following to bring up the resources view

Notice I add a pipe on the end of the command. This makes the JSON output more readable.  | python -m json.tool

curl --insecure -H "Accept: $ACCEPT" -H "Authorization: $AUTH" https://$VRA/catalog-service/api/consumer/resources | python -m json.tool

Now let’s locate the Item ID of the CentOS6 VM to get the details for the CentOS6 blueprint we provisioned. Highlight the ID as shown and copy to the clipboard.

Now let’s get the IP address of the CentOS6 item by typing the following

Remember you will need to replace the items below in RED with the item ID from your environment.

curl --insecure -H "Accept: $ACCEPT" -H "Authorization: $AUTH" https://$VRA/catalog-service/api/consumer/resources/ec425370-e70b-4457-acfe-cf62d0bd26ad | python -m json.tool

Scroll through the output to locate the IP address

vRA7RestgetIP

You now have the information you need to integrate with your build system so that you can SSH to this VM and kick off installation scripts, Puppet, Chef or what ever you choose!

Happy Coding!! Enjoy!

Remember, sharing is caring ->Tweet about this on Twitter0Share on Facebook0Share on LinkedIn0Share on Google+0Email this to someone

One thought on “How to get the IP address of a VM in vRealize Automation 7 REST API

  1. Pingback: How to script a vRealize Automation 7 REST API request – VMtoCloud.com

Leave a Reply

Your email address will not be published. Required fields are marked *

*