I'm trying to find a way to output the smallest vm inside a datastore input. When you use vm.summary.storage.committed you can be looking at several vmdks that span multiple datastores.
I have this but I get an undefined return on the output for line#24.
The output on line#15 doesn't just show me a single devices, looks like it's the entire list of devices for the first VM of datastoreVmList
function sortDisk (a, b) { return (a.deviceInfo.summary - b.deviceInfo.summary); } System.log("First vm is " + datastoreVmList[0]); System.log("Datastore is " + datastore); var allDevices = new Array(); for (var i in datastoreVmList) { var devices = datastoreVmList[i].config.hardware.device allDevices.push(devices) } System.log("First device on array of devices is " + allDevices[0]); var datastoreDisks = new Array(); for (var i in allDevices) { if (allDevices[i] instanceof VcVirtualDisk == datastore) { datastoreDisks.push(allDevices[i]) } } System.log("First disk device is " + datastoreDisks[0]); datastoreDisks.sort(sortDisk); datastoreDisks.reverse; smallestVm = datastoreDisks[0].parent; System.log("First disk device datastore is " + datastoreDisks[0].backing.datastore); System.log("Smallest VM is " + smallestVm);
What would be the best way to do this?
Thanks!