Summary/Use Cases:
This workflow can be used as part of a self healing solution to ensure SDRS runs whenever you get a datastore alarm. (see Self Healing Datacenter). This ensures SDRS immediately runs and can balance the storage in the cluster.
Inputs:
- Datastore Name: Type = String
Outputs: None
The Workflow:
How It Works:
- Takes the Datastore string passed to it and then searches vCenter for a Datastore Object matching the stringtext. This is stored as type VC:Datastore.
- Looks through all of the SDRS PODs declared in your general attributes to see if any of them contain the Datastore object found in step 1.
- If there is a match, it stores this as the variable “podToRunSDRSOn”, and stops searching.
- Run’s refresh recommendations on the pod “podToRunSDRSOn”.
The Code:
Only 1 scriptable task has been used above, and i’m considering making it an action item if I don’t expand on the workflow further.
//Search vCenter for a Datastore matching the name
var dataStoreObject = System.getModule
("com.vmware.library.vc.datastore").getAllDatastoresMatchingRegexp(dataStoreName);
dataStore = dataStoreObject[0];
System.log("Datastore Object Found is " + dataStore);
//Now we have the datastore in question, we need to find out which SDRS POD the Datastore
is a member of.
//Checking the array of pods
for (var i in podsArray)
{
System.log("Checking POD: " + i + "in podsArray. The current POD is" + podsArray
[i]);
//Grab the child entities of the pod and put them in the arrayCheckDatastore
checkDatastore = podsArray[i].childEntity;
//Now check each datastore against the original one we found to verify the
objects are the same
for (var t in checkDatastore)
{
System.log ("Datastore at object " + t + "is : " +
checkDatastore[t]);
if (checkDatastore[t] == dataStore)
{
System.log("Datastore Match. The pod we need to
run SDRS on is " + podsArray[i]);
podToRunSDRSOn = podsArray[i];
break;
}
else
{
System.log("There was no match...we could not
find an SDRS POD");
}
}
}
System.log("CHECKING COMPLETE: Pod to run SDRS on is : " + podToRunSDRSOn);
//RUN SDRS
if (podToRunSDRSOn != null)
{
var m = podToRunSDRSOn.vimHost.storageResourceManager;
task = m.refreshStorageDrsRecommendation(podToRunSDRSOn);
}