Multi-Machine Blueprint – Collect VM from deploy

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: