VMware Cloud Community
BillStreet00
Enthusiast
Enthusiast

Create a dynamic list of vCenter 6.5 Folders for vRA 7.2

I need to have a drop down on my vRA blueprints that will list the folders in vCenter allowing the user to specify which one they want to build their VM in.  I can manually input the folder list as a Property Definition however our operations group creates quite a number of folders.  What I would like to do is call a vRO workflow that will dynamically build this list for me so its not updated almost daily.

I found this code from an earlier post by Ilian Iliev

  1. // Search index object for the first registered vCenter 
  2. var index = VcPlugin.allSdkConnections[0].searchIndex; 
  3.  
  4. // Inventory path of the folder to search for (note: starts with datacenter name; replace datacenter123 with your datacenter name) 
  5. var invPath = "/datacenter123/vm/site1/servers/critical/"
  6.  
  7. var folder = index.findByInventoryPath(invPath); 
  8. System.log("folder: " + folder); 

I did change the DC name to /mydatacenter/mycluster/ under which I have several top level folders and subfolders.  When I run this workflow I get the following error message in vRO. I have tried this by declaring invPath as an attribute and hardcoding the datacenter and added folder as an output.  I seem to have no luck either way.

[2017-07-20 09:15:44.132] [E] Error in (Workflow:getFolderList / Scriptable task (item1)#6) TypeError: Cannot call method "findByInventoryPath" of null

[2017-07-20 09:15:44.140] [E] Workflow execution stack:

***

item: 'getFolderList/item1', state: 'failed', business state: 'null', exception: 'TypeError: Cannot call method "findByInventoryPath" of null (Workflow:getFolderList / Scriptable task (item1)#6)'

workflow: 'getFolderList' (16cedf47-3abc-4e1b-ba60-e390b995e1bc)

|  'attribute': name=invPath type=string value=/p10dcvcenterha.amwins.local/P10/

|  'output': name=folder type=string value=null

|  'no inputs'

*** End of execution stack.

Any assistance would be great. 

Thanks

0 Kudos
1 Reply
BillStreet00
Enthusiast
Enthusiast

Some success.  I combined two different bits of code for my vRO Action and came up with this:

var sdk = Server.findForType("VC:SdkConnection",sdkConnection);

var nFolder = sdk.getAllVmFolders();

var oFolder = [];

for(i=0; i<nFolder.length; i++){

     if(nFolder[i].name != "_Templates_"){

          oFolder.push(nFolder[i].name);

          }

     }

oFolder.sort();

System.log(oFolder);

return oFolder;

It works well and does return a dynamic list of folders in my blueprint. I get a flat list of folders that appears in my blueprint.  The problem with the flat list of folders is that rather than building a folder in a nested folder as requested it builds a new folder at the root.

However I have two data centers and nested folders in each.  I would like to be able to pull the folder list from a specific data center and pass the folder path back to my blueprint. For example, I would like to pull the folder list from data center 1 and denote embedded folder names by including the parent folder like this.

Parent Folder

Parent Folder\Son Folder

Parent Folder\Daughter Folder.

Any thoughts would be great.

Thanks

0 Kudos