Lately I’ve been running into random failures in my deployment workflow when it comes to finding what datastores are attached to what hosts. My workflow selects a host to use, then loops through all datastores, looking to see what hosts are connected and builds a list of available datastores I can pick from.
The relevant section of code is where my problem is:
var allDatastores = System.getModule("com.vmware.library.vc.datastore").getAllDatastores();
var vmStorage = new Array();
var storageName;
if (allDatastores)
{
for (i = 0; i < allDatastores.length; i++)
{
for (j=0; j < allDatastores[i].host.length; j++)
Everything works fine but every now and then, I get the following error: TypeError: Cannot read property "length" from undefined
I believe the error is coming from the host.length call (I’ve adding a little more logging to try and confirm the next time it happens). I added a try/catch block to loop through the same section of the code in the event of a failure but after 10 attempts (with 15 seconds between), it still fails. Another call to the workflow right after works just fine.
Anyone know what might be the cause of if there’s a better way to get a list of datastores and/or datastore clusters attached to a given host? I've seen other random failures (usually with running stuff within the guest OS via vmware tools) and retrying seems to work but in this case, not so much.
Thanks