chelnak
7/20/2016 - 1:05 PM

Example for determining DRS group based off storage. Pass cluster, vm_group and vms to the Library workflow Add virtual machines to DRS gro

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;

}