I'm very new to the vCO (or maybe I should call it vRO now) and therefor also very new to javascripting and digging through the API, so I apologize if this is a bit of a noob question.
I'm running below script to find the datastore cluster of a host cluster with most available space.
However, I also want to check for text in the name of the datastore. For this I use indexOf.
If indexOf finds any matches it should add the DSC (or pod) to an array.
But it seems that this operation turns my array into a string.
Because this is a new environment I only have one DSC connected to the hosts cluster, but I still think it should be able to be an array with only one value?
// Find Cluster and related variables
var hostarray = System.getModule("com.vmware.library.vc.cluster").getAllHostSystemsOfCluster(inCluster);
host = hostarray[0];
pool = inCluster.ResourcePool;
var tier = "High";
// Find Datastores in Cluster
var datastores = host.datastore;
// Find Datastore Clusters in Cluster
var storagePods = new Array();
var storagePodNames = new Array();
for (d in datastores){
if (datastores[d].parent.vimType == "StoragePod"){
if (storagePodNames.indexOf(datastores[d].parent.name) <= -1){
storagePodNames.push(datastores[d].parent.name);
storagePods.push(datastores[d].parent);
}
}
}
System.log("storagePods:" + storagePods[0].Summary.freeSpace);
// Find Datastore Clusters matching the tier
var podTierArray = new Array();
for each(var pod in storagePods){
if(pod.name.indexOf(tier) >= 0){
podTierArray += pod;
}
}
// podTierArray becomes a string instead of array after above operation :((((
System.log("podTierArray:" + podTierArray[0]);
System.log("podTierArray:" + podTierArray);
Here is the output of above script:
[2015-02-27 12:24:27.307] [I] storagePods: 4497773428736
[2015-02-27 12:24:27.308] [I] podTierArray: D
[2015-02-27 12:24:27.310] [I] podTierArray: DynamicWrapper (Instance) : [VcDatastore]-[class com.vmware.vmo.plugin.vi4.model.VimDatastore] -- VALUE : Datastore<datastore-386>'Datastore01-High'
I'm guessing "D" is the first character of the string (which should be an array) which is also proven by the third row of the output where I print the entire string.
Because this now is a string I can't use it as an object anymore either, for example "podTierArray.Summary.freeSpace" will give me an error that it is an undefined property.
Also, as you can see earlier when I use the variable "storagePods" this is an array before I run the podTierArray operation.
Why would it suddenly become a string instead of an array of objects?