lcaccamo
Contributor
Contributor

Cloning VM to cluster vm folder "Discovered Virtual Machine" via workflow scriptable task

I am building a workflow to deploy vms to remote sites. My workflow uses a scriptable task with the getAllVmFolders method. My issue is that my folders look like below. My clone workflow doesn't work since I can't just rely on the "getAllVmFolders()" as it doesn't allow me to filter based on the cluster it is part of.

Datacenter 1

     SITE 1 CLUSTER   

          HOST1

          HOST2

               Discoverd Virtual Machines

Datacenter 2

     SITE 2 CLUSTER   

          HOST1

          HOST2

               Discoverd Virtual Machines

etc

etc

**** Here's my folder "get" code with a section commented out since the .parent.name parameters aren't valid. ****

//*** WE SET A STATIC FOLDER

var folders = VcPlugin.getAllVmFolders();

var arraylength = folders.length;

var i=0;

while (i < arraylength){

if ("DISCOVERED VIRTUAL MACHINE"==folders[i].name.toUpperCase()){

    System.log("FOUND FOLDER: " + folders[i].name); //Folder is found in every cluster how to I designate only "SITE1"

//    System.log("Parent: " + folders[i].parent.name);

//    if (folders[i].parent.name.toUpperCase() == "DISCOVERED VIRTUAL MACHINE"){

//        sFolder=folders[i];

//        break;

//    }

}

Can anyone help?

4 Replies
lcaccamo
Contributor
Contributor

Bueller.... Bueller.... anyone... bueller?

If my questions makes no sense, please let me know. I'm new to vCO

0 Kudos
Burke-
VMware Employee
VMware Employee

Since you are performing a clone operation, you must have a VC:VirtualMachine object that you are using as the source/template - let's call it "vmTemplate".. if this is the case, then perhaps you could try something like this:

var folders = vmTemplate.sdkConnection.allVmFolders;

for each (folder in folders){
if ("DISCOVERED VIRTUAL MACHINE"==folder.name.toUpperCase()){
System.log("FOUND FOLDER: " + folder.name);
System.log("Parent: " + folder.parent.name);
break;
}
}

The code above should limit folder retrieval to the same vCenter that the template resides on Smiley Wink

p.s. - your original post is using a while loop with i initialized to 0 but then there is nothing to increment it....

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
lcaccamo
Contributor
Contributor

So this is not a suitable solution since there are no VMs at the site yet. I have two brand new hosts. The are part of a cluster at the site. We only have a single vCenter server running in our datacenter and a couple dozen remote sites. How would one use VCO to identify a folder at a site that has no vms at it already.

0 Kudos
tschoergez
Leadership
Leadership

Hi,

can you make a screenshot of your inventory in vCenter? Are you talking about the structure in the Hosts&Clusters view or the Virtual Machines & Templates view?

Also I don't understand the goal of your workflow so far. You have the original source vm/template defined, right? And the challenge is now to get the destination folder for the new VM?

Cheers,

Joerg

0 Kudos