Writing a workflow to detect which VMs are template in vCloud Director

Today I need to export a list of my VMs and determine which of them are template in vCloud director. I tried to export this list on vRealize Operation Manager (vROP) but i found that it is not possible to do it at least with the default configuration.

  1. First I need to get all the VMs and put it to an array named “vms”

To get all VMs an put it into an array you can used a default action named “getallvms”


To save the result to the array I go to the Visual Binding and connect the action result to “vms”

Now I need a custom decision to build a loop for each of my VMs and assign the parameter “vms”, “vm” and “i”.

In the scripting section I write this code:

return (i < vms.length)

I create a script to select a vm from my created array (“vms”)and run my script on the machine, I also need to assign all the parameter to this script.

The code will be like below:

vm = vms[i]

Now I have to create a new parameter in General tab for my vCloud director host.

Like below I create check template script to run all my script on the selected vm, as you see I assigned the vm parameter in addition to the vcdhost.

This script will find the vCloud director ID from the name of virtual machine on vSphere environment and search it within the vCloud director vApp templates, if it finds the related vApp template it logs its an template otherwise it is not a vApp template

And the script will be like this:

var VCDID = "urn:vcloud:vm:" + vm.name.match((/.*\s\((\S{8}-\S{4}-\S{4}-\S{4}-\S{12})\)/))[1]
var vApptemplate;
VCVM = vcdhost.getEntityById(VclFinderType.VAPP_TEMPLATE, VCDID)
if ( VCVM != null ) {
vApptemplate = true }
else {vApptemplate = false}

System.log("the " + vm.name + "is a vapptemplate?:" + vApptemplate)

And for the last step just put increase number component in workflow to increase “i” parameter value.



Leave a Reply

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

45 − = 38