Skip to content
vWorld
Menu
  • Main Page
  • About
  • Study Guide
    • VCAP-CMA Deploy 2018
Menu

Multi-Machine Blueprint – Collect VM from deploy

Posted on January 21, 2019January 21, 2019 by admin

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

Share with:


7 thoughts on “Multi-Machine Blueprint – Collect VM from deploy”

  1. Julian B. says:
    March 8, 2019 at 6:33 am

    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

    Reply
    1. admin says:
      March 8, 2019 at 9:49 am

      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);

      Reply
      1. Julian B. says:
        March 8, 2019 at 2:29 pm

        But i add the lines in wich workflow?

        Reply
        1. admin says:
          March 8, 2019 at 3:08 pm

          Second ono, content request based on ID

          Reply
  2. visit site says:
    January 31, 2020 at 1:34 am

    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.

    Reply
  3. windows 10 activator zip says:
    January 20, 2021 at 12:26 pm

    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.|

    Reply
  4. AlienMadness says:
    January 20, 2021 at 9:57 pm

    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?

    Reply

Leave a Reply Cancel reply

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

Recent Posts

  • From Commit to Cluster: Mastering GitOps with Argo CD on VMware Cloud Foundation
  • The Full Power of VCF Automation in Action: How I Connect the Dots and Build a Multi-Tier App with Kubernetes Objects.
  • From Code to Kubernetes Cluster with Chiselled Ubuntu Images on VMware
  • From Zero to Database-as-a-Service: A Deep Dive into VMware Data Services Manager 9.0 and VCF Automation
  • Complete Guide: Configuring SSO in VMware Cloud Foundation with Active Directory and VCF Automation Integration

Archives

Follow Me!

Follow Me on TwitterFollow Me on LinkedIn

GIT

  • GITHub – vWorld GITHub – vWorld 0
© 2026 vWorld | Powered by Superbs Personal Blog theme