Many time I’ve spent to search how to collect data from multi-machine blueprint. I’ve take a look on many forum on many blogs but withot success so I’ve decided that do this in my own way.
So at the beginning. This case will be created for multi machine blueprint which at the Requested phase change the name for VM as I describe in previous article and at the End do collect data.
First element is create the REST host in vRO. Login to vRealize Orchestrator and go to the HTTP-REST Configuration.
Start workflow and provide specific properties for your vRealize Automation appliance
When host is added sucesfully we have to create to REST Operations.
First operation is for Token which will be used for authentication
Second one will be for content request based on ID
The last element from REST operation is Generate Workflow from REST Operation
We need to run this double time one for token and one for content providing specific REST operation.
Automatically created workflow looks like this
Requesting Token is POST operation so we need to provide the body of operation in content parameter
and the script looks like this for POST we only need to add body and header with Accept – application/json in customization part
//prepare request
//Do not edit
var inParamtersValues = [];
var request = restOperation.createRequest(inParamtersValues, content);
//set the request content type
request.contentType = "application\/json";
System.log("Request: " + request);
System.log("Request URL: " + request.fullUrl);
//Customize the request here
//request.setHeader("headerName", "headerValue");
request.setHeader("Accept", "application/json");
//execute request
//Do not edit
var response = request.execute();
//prepare output parameters
System.log("Response: " + response);
statusCode = response.statusCode;
statusCodeAttribute = statusCode;
System.log("Status code: " + statusCode);
contentLength = response.contentLength;
headers = response.getAllHeaders();
contentAsString = response.contentAsString;
System.log("Content as string: " + contentAsString);
I create another workflow which use previous one but automatically post DATA without user interface
In first Scriptable Task I’m providing credentials and POST Body
var username = "name"
var password = "pass"
var tenant = "vsphere.local"
var postText = "{\"username\":\"" + username + "\",\"password\":\"" + password + "\",\"tenant\":\"" + tenant + "\"}";
Element in the middle is our workflow and second scriptable task is collecting output as JSON and put Token for the output
var jsonResponse = JSON.parse(contentAsString);
var token = jsonResponse.id
System.log("Token is: " + token);
The binding looks like that
So now we have required token for authentication
In second workflow we need to change/add few line as well like in first but also we need to add our token and header for authorization via this token
//prepare request
//Do not edit
var inParamtersValues = [id];
var request = restOperation.createRequest(inParamtersValues, null);
//set the request content type
request.contentType = "application\/json";
System.log("Request: " + request);
System.log("Request URL: " + request.fullUrl);
//Customize the request here
//request.setHeader("headerName", "headerValue");
var authorizationToken = "Bearer " + token
request.setHeader("Accept", "application/json");
request.setHeader("Authorization", authorizationToken);
//execute request
//Do not edit
var response = request.execute();
//prepare output parameters
System.log("Response: " + response);
statusCode = response.statusCode;
statusCodeAttribute = statusCode;
System.log("Status code: " + statusCode);
contentLength = response.contentLength;
headers = response.getAllHeaders();
contentAsString = response.contentAsString;
System.log("Content as string: " + contentAsString);
Now we have all required element so build main workflow.
- First part is requesting Token
- Second is collecting Payload
- Third getting content
- Fourth work on results
First and Third part was described upper so in second Part we need to collect Content ID from payload
var machine = payload.get("machine");
var catalogRequestId = payload.get("catalogRequestId");
System.log("cataog request ID: "+catalogRequestId);
Fourt element collect data as JSON and search our VM in result
var jsonResponse = JSON.parse(contentAsString);
var resources = jsonResponse.content;
for each (res in resources)
{
var name = res.name;
if (name.match("vm"))
{
System.log(name);
}
}
That looks binding for all element
You must remember to put as input parameter only Payload and if you require more, than use them as input attribute.
Now we only need to create Event Subscription in vRealize Automation
Go to Administration–> Events –> Subscriptions
We want to run our workflow after deployment so we cannot use standar Mchine provisioning and we will use Catalog item request completed which provide us CatalogRequestId
As a condition I’m only provide Blueprint name
and in workflow choose our newly created workflow.
When our Blueprint finish with success status we will see in logs names of our VM created in build process
Hello,
First of all, thanks for taking the time to publish this solution, excellent work!
Now, I’m trying to follow the guide you published but I have a doubt in this part, I would really appreciate it if you can solve it for me:
I create the workflow to get the authentication token. After that part you say “In second workflow we need to change / add few lines as well as in first but we need to add our token and header for authorization via this token”
What second flow do you mean specifically? (Until then we have 3 workflows created, Request-Token-https, RequestTokenvRa and Get-Content-By-ID)
Thanks for your help
hello, thanks a lot, I’hm talking about this part
//Customize the request here
//request.setHeader(“headerName”, “headerValue”);
var authorizationToken = “Bearer ” + token
request.setHeader(“Accept”, “application/json”);
request.setHeader(“Authorization”, authorizationToken);
But i add the lines in wich workflow?
Second ono, content request based on ID
I simply want to say I’m newbie to blogs and actually savored this web page. More than likely I’m likely to bookmark your website . You certainly have good articles. Thanks for revealing your web site.
Pretty section of content. I just stumbled upon your blog and in accession capital to assert that I acquire actually enjoyed account your blog posts. Any way I’ll be subscribing to your feeds and even I achievement you access consistently rapidly.|
This is good info and exactly what i needed. but i have a question on the Main workflow.
there is a “Payload_For_Content” workflow, but i dont see where that is created.
Is this just a workflow with a single scriptable task? with In attribute of Payload and out parameter for catalogRequestID?