Skip to content

Instantly share code, notes, and snippets.

@chelnak
Last active July 20, 2016 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelnak/a5270522dd2da70685288388b135d7d6 to your computer and use it in GitHub Desktop.
Save chelnak/a5270522dd2da70685288388b135d7d6 to your computer and use it in GitHub Desktop.
Example for determining DRS group based off storage. Pass cluster, vm_group and vms to the Library workflow Add virtual machines to DRS group
//Get the first datastore in the array
var dataStores = vcVirtualMachine.datastore;
var dataStore = dataStores[0].name;
System.log("Found first datastore in array: " + dataStore);
//Get datastore prefix
var prefix = dataStore.split("-")[0];
System.log("Datastore prefix is: " + prefix);
//Logic here determines which DRS group the vm will be placed in
if (prefix == "X") {
vm_group = "DRSGroup-X";
}
if (prefix == "Y") {
vm_group = "DRSGroup-Y";
}
//Log things
System.log("Attribute vm_group set to: " + vm_group);
//Populate output parameter for custom property
drsGroupName = vm_group;
// Add vm object to vms array that will pass to the next workflow
System.log("Building new array with " + vcVirtualMachine.name);
var vms = [];
vms.push(vcVirtualMachine);
//Need to get cluster here to set attribute
var vcVirtualMachineRuntimeInfo = vcVirtualMachine.runtime;
var hostSystem = vcVirtualMachineRuntimeInfo.host;
var clusterComputeResource = hostSystem.parent;
if (clusterComputeResource.vimType == "ClusterComputeResource") {
System.log(clusterComputeResource.name);
cluster = clusterComputeResource;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment