VMware Cloud Community
evizc
Contributor
Contributor

getAllDatastores();

Hello,

Is there a way to only select and use those datastores in a specific folder? I am creating a workflow that creates several VMs in a specific folder but different datastores. I use var datastores = VcPlugin.getAllDatastores(); and select it to create my VMs, The problem is I am trying to select a specific Folder of data stores and that plugin gets me all datastores everywhere.

Example:

DataStoreA

DataStoreB

DatastoreFolder

     ->DataStore1

     ->DataStore2

     ->DataStore3


I only need DatastoreFolder and its contents. Any idea what can I do?

Reply
0 Kudos
1 Reply
qc4vmware
Virtuoso
Virtuoso

You can do something like this.  I just modified the action that selects all vm's for a folder and sub folders.  Insert this into an action with a datastoreFolder for an input and an array as an output.

if(!datastoreFolder){

    throw "UndefinedParameter: datastoreFolder mandatory input is not defined.";

}

var allDatastores = new Array();

getAllDatastoresInFolder(datastoreFolder);

return allDatastores;

function getAllDatastoresInFolder(folder) {

    var children = folder.childEntity;

    for (var i in children) {

        if (children[i] instanceof VcFolder) {

            getAllDatastoresInFolder(children[i]);

        }

        if (children[i] instanceof VcDatastore) {

            allDatastores.push(children[i]);

        }

    }

}

Reply
0 Kudos