With vRA 7, the functionality of the default IaaS blueprints are dramatically improved. One of the new cool features is the usage of dropdown lists populated by a vRealize Orchestrator action. This is something we have only seen before in ASD/XaaS blueprints.
This blog article describes how to use this new cool feature.
In my example I am going to create a drop-down list which query’s a specific vCenter folder for existing vSphere templates and returns them in the drop-down list on the request form.
- Create your IaaS Blueprint and drag one vsphere virtual machine on the design canvas.
- Select the vsphere virtual machine now and you will see the General tab of it’s configuration.
- Click on the Build Information tab and specify your vsphere template as below example. I have chosen for template name TMPL-CENTOS-VRAS because selecting a template is required in this type of blueprint. Even when it is not my intention to use this template at all.
- Click on the Properties tab and next click on the Custom Properties sub tab. Add a new custom property with the name cloneFrom and make sure you have enabled the check box Show in Request. Otherwise you will not see this custom property on the request form.
- You are now done with the IaaS blueprint so click Finish.
- Next make your blueprint available as a catalog item in your service catalog. (publish your blueprint, assign a service for this new catalog item and make sure it is part of your end users entitlement.)
- When you request your catalog item now, it will look like the below screenshot.
- Now it’s time to create your vRO action. So lets open your vRO client, navigate to the action section, select a folder (for where to store your action in), click on create a new action, give it a name (in my example the name is displayTemplatesFromFolderId) and click Ok.
- Go to the Scripting tab of your new vRO action. 1. Set your Return type to Array/string 2. Create two attributes. Name one attribute sdkConnection and name the other attribute vcFolderId 3. Make sure the new attributes are of the type string 4. Provide the following JavaScript code:
123456789101112131415161718192021222324252627282930313233343536373839404142// find sdkConnection of the type VC:SdkConnection. Provide fqdn of vCenter servervar sdk = Server.findForType("VC:SdkConnection",sdkConnection);// Search for vcfolder with the id of vcFolderIdvar vcfolder = sdk.getAllVmFolders(null,"xpath:id='"+vcFolderId+"'");// vcfolder contains an array of folders. The first element of this array will be stored in theVmFolder as a VcVmFolder objectvar theVmFolder = vcfolder[0];// Stores the vm namevar vmsInFolder = theVmFolder.vm;// Array to store the vms with the status template from a vcfoldervar templatesInFolder = [];// Temporary variable to find out if one of the vms in the vcfolder has the status of a templatevar vmsAvailable = 0;// Checks if the vcfolder is emptyif (theVmFolder.vm == 0 && vmsAvailable == 0){System.log("NO VMs in Folder at all");templatesInFolder.push("NO TEMPLATES");} else {// Loops through all vms in the vcfolder and stores only vms with the status template in an array of stringsif (vmsInFolder[0].config.template != null){for (i = 0; i < vmsInFolder.length; i++) {if (vmsInFolder[i].config.template == true) {System.log("VM : "+vmsInFolder[i].name+" Is a template");templatesInFolder.push(vmsInFolder[i].name);}else {System.log("VM : "+vmsInFolder[i].name+" Is not a template");vmsAvailable = 1;}}}// Check if none of the available vms in the vcfolder have the status templateif (templatesInFolder[0] == null && vmsAvailable == 1){System.log("No Templates in Folder");templatesInFolder.push("NO TEMPLATES");}}// Resturns and Array of strings with includes all vms in the vcfolder with the status templatereturn templatesInFolder;
5. Click Save and close - Make a note of your values for sdkConnection (fqdn of your vCenter Server) and vcFolderId (the vCenter folder group-id). In my example, I can find this information in the vRO Inventory section.My value for sdkConnection = pb0vcsa01.flexlab.local My value for vcFolderId = group-v279
- Now lets create a new vRA Property Definition
- Follow the detailed steps below 1. Name your Property Definition cloneFrom (This is exactly the name as you used for your custom property configured on the IaaS blueprint) 2. For Label type Select Template 3. For Data type select String 4. For Required select Yes 5. For Display advice select Dropdown
- Instead of selecting Predefined values in the Value section, select External values.
- A new window will open where you have to select your newly created vRO action. When selected click Ok.
- Next populate the values for the Input parameters which have been captured in step 6 and finally click Ok.
- When you now request your catalog item it will look like the below screenshot.
- Enjoy using vRA 7 !
This is great and very helpful! I was following along with your JavaScript code but I’m having trouble figuring out where you found the ‘vm’ property of ‘theVmFolder’ on line 8 which is of the object type ‘vcFolder’.
‘vm’ isn’t one of the listed properties of the ‘vcFolder’ scripting class, so I’m just curious.
Thanks!
Hi Chris,
Good to hear that my post was great and very helpful. I have asked around internally and one of my colleagues came with the following answer..
VcFolder is the base type for all folders. It corresponds directly to Folder in vCenter API and the entity type is available in childType property. vRO provides subclasses to it – you can search for VcVmFolder which has property vm. Other subclasses are VcNetworkFolder, VcHostFolder, VcDatastoreFolder and VcDatacenterFolder. None of them exists in vCenter API as such.
I think this answers your question 😉
Regards,
Dennis
Thank you so much! This is exactly what I am looking for. I am extremely new to JavaScript, though, and when I implement the action as written above I get this error in vRA: Unable to refresh request form from the server
Unable to start action ‘com.webroot.util/displayTemplatesFromFolderId’. Reason ‘Action ‘displayTemplatesFromFolderId’ in module ‘com.webroot.util’ failed : TypeError: Cannot call method “getAllVmFolders” of null (unnamed script#4)’. Do you know where I could have gone wrong?
Thanks again,
Ann
Hi Ann,
It looks like something gets wrong with your vRO action eg. the input variabele is not populated.
Can you try to create a new empty vRO workflow and put the action displayTemplatesFromFolderId in it. Try if you can run it from there and see what the values are of the variabele templateInFolder.. it must be something like Array[template1,template2]
Also, did you add a vCenter host in vRO (This is your sdkConnection) ? By running the workflow “Add a vCenter Server instance” from the vCenter plugin.
Regards,
Dennis
I have the same issue and the action completes successfully when put into a workflow and I supply the same value in the workflow as I do in the property definition. Yes the return values are Array/String.
Thanks for your article!
Though, when I clicked External Values to put in the action script, I couldn’t see the one created in Orchestrator.
Did you set the return type of the action to Array of string ?
Hi Dennis,
I did not set the return type as array of string. I set it as string. Does the return type matter?
I’ll give it a try asap.
Hi Thang,
Yes, the return type matters.. Good Luck
Regards,
Dennis
Woohoo!
I did it! Yes, it was the return type that caused the problem 😀
Thanks in advance.
Thang
I feеl this is among the so much vital information for me.
And i am glad studying your article. But ѕhoᥙld obseгvation on sоme general issues,
The wеbsite taste is ideal, the articles
is in reality nice : D. Good job, cheers
It’s a pity yoᥙ don’t have a donate button! I’d witһout а dοubt donate
to this excellent bⅼog! I guess for now i’ll settle foг book-marking and
adɗing your RSS feed to my Google account.
I look forward to new updates and will talk about this Ьlog with my Facebook group.
Chat sօon!
Thanks for this article! I am also having issues with actions created in orchestrator not showing up in vra. As you suggested above, i did confirm my return value says ‘array/string’, but my custom action is not showing up.
My goal is to use this workflow to just return a list of all vm folders as we want users to select the folder to place the deployed vm in. I changed your script to simply return vcfolder rather than the template. I think this will work… if i can figure out how to select my action in vRA.
Thanks again for a great resource
Hi Matt,
Sorry for the delay, but I am just back from my summer holidays.
Did you manage to solve the issue? If not does the vro action works as expected in vro?
Regards,
Dennis
Yⲟu ought to ƅe a part of a contest for one of the finest websites on the internet.
I’m going to highly recommend this site!
Hi Dennis,
Thank you for this very useful article.
I am trying to accomplish exactly this, but unfortunately it does no work for me.
My issue is that after I create the vRO action I cannot access it from vRA.
What I mean is that in the list that opens in vRA in order to choose the action, my whole container and all the actions I have created are not there.
Do you have any ideas?
Hi Dimitrios,
Sorry for the late reply. Did you manage to solve the issue ?
If not can you send me a screenshot of what you are seeing and could you also send me the action ?
This shouldn’t be to hard to solve.
Regards,
Dennis
Hi Dennis,
I understood your concept of populating the clonefrom property. does this update the default value __clonefrom or you have to do it in the vCO using below line ?
System.getModule(“com.vmware.library.vcac”).addUpdatePropertyFromVirtualMachineEntity(host,virtualMachineEntity,”__clonefrom”,clonefrom
Can you please clarify
Hi Vignesh,
With my example I am generating a drop-down list with available templates in a specific vSphere folder by the usage of a vRO action (external value).
The value you are selecting will set the value for the cloneFrom custom property. Does this make sense to you? If you are trying to set one of the values from the drop-down list as the default value, afaik that’s not possible with a vRO action only.
Cheers,
Dennis
Hello,
If I have two vCenter and in each vcenter have different templates. How to make work this custom properties with two vCenter and different folder-id ?
Hello Mikael,
I was on holidays so sorry for the late response.
Did you already found a solution for your use-case?
The key in here is the sdk connection wich is a one-to-one mapping to your vCenter server.
Let me know if you need more assistance.
Regards,
Dennis
Hello Dennis, great article. Can you please share how one would show all the templates on a single vCenter? I’m looking at multiple Datacenter and Folder objects. Thanks!
Hi Dennis,
Your blog posts are really helpful.
Could you please help me get a vRA-SNOW integration vRO package which uses REST API instead of plugin where SNOW is the front end for machine provisioning requests?
For ex: https://virtualviking.net/2015/06/15/using-servicenow-as-a-front-end-for-vrealize-automation/
I need this vRO package for my project requirement. I tried to using the Postman POST /vco/api/workflows/{workflowid}/executions to request the machine, however ended up with
HTTP 400 Bad Request error “The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing)”
Request you to get me the package or some insights to write the workflow.