Thursday, July 27, 2017

Infrastructure as Code

Consuming vRA Catalog Item using REST API

I'm preparing a demo to show how developer can consume infrastructure layer by using API. I have the cloud management platform using VMware vRealize Automation up and working, blueprints already created, catalog set for user and ready to consume. Now the question is how to consume the Catalog Item using API. Thankfully a colleague point me to a blog from Ryan Kelly here:
The article is awesome, it shows step-by-step on how to do it so you will understand the flow, which will be useful for further exploration. And at the end of the article, it wrapped all the steps into one script that user can call to request the catalog item. After that, it only requires to run the script to do the request.

Well, if it is only to say the above, I will not write this article. The reason why I write this is to add a little information. First, in the original article, developer access vRA from a Linux machine. Since I'm using Macbook Pro, so I wonder whether any modification required. Initially, following the manual steps it works. One thing to note is when you use OSX Terminal to perform the steps, you might need to change the directory where you will save the JSON file accordingly. For instance, in my case I saved the file to my Documents folder.

curl --insecure -H "Accept: $ACCEPT" -H "Authorization: $AUTH" https://vra-01a.corp.local/catalog-service/api/consumer/entitledCatalogItems/f16585f9-5a43-4c43-b12b-386b3ba2b3bc/requests/template | python -m json.tool > /Users/slesmana/documents/CentOS6.json
After that everything works fine and I can get my request submitted.

Next problem occured when writing the script. Happened to be the syntax for one of the command is not available for OSX that I use. To be specific it is grep -P which is not working (option -P is no longer available on my OSX). Do some googling and testing, I manage to make it work.

The original command:

export TOKEN=`echo $DATA | grep -o -P '(?<="id":")[\w\d=]*(?=")'`
My modified command:

export TOKEN=`echo $DATA | sed -e "s/.*id\":\"\(.*\)\",\"tenant.*/\1/"`
After I change this line, the script now works.


No comments:

Post a Comment