VMware Cloud Community
FTBZ
Contributor
Contributor

Add virtual machines to DRS group based on datastore name

Hello,

Completely new to vRealize Orchestrator, I'm looking for help do to a "simple" workflow. 

We're using a vMSC with two datacenters and I want to automate the DRS membership attribution. I want to schedule an daily task that checks datastore name, extracts virtual machine and, based on the datastore name, puts the VM to the correct DRS group.

Our datastore have a name that indicates the datacenter name that can be used to identify the DRS group.
I've found a video on YouTube that doing nearly what I need, but I'm not able to reproduce the workflow.

Someone has already done something similar?

Thanks.

Reply
0 Kudos
1 Reply
ChrisMueller85
Enthusiast
Enthusiast

Hallo, welcome in the Orchestrator community.

We are having the same requirement in our environment. Our setting is based on the DS Cluster but thats not important for the fololwing script part. The script also checks if a group allready exists or not. So you could define the group name freely and the script will hande the it.

VM = ??  // VM to add

VMGroupName = ?? // Name of the Group

cluster = VM.runtime.host.parent;

var VMs = new Array();

var addOrEdit = "add";

// Searching for a DRS VMGroup group by name

for (i in cluster.configurationEx.group) {

     if (cluster.configurationEx.group[i].name == VMGroupName) {

          if (cluster.configurationEx.group[i] instanceof VcClusterVmGroup) {

               System.log ("A group with the same name " + VMGroupName +  " found: " +  cluster.configurationEx.group[i]);

               addOrEdit = "edit";

               if (cluster.configurationEx.group[i].vm != null)

               {

                    // Take all VMs allready in the group

                    VMs = cluster.configurationEx.group[i].vm;

               }

          }

     }

}

VMs.push(VM);

var clusterConfigSpec = new VcClusterConfigSpecEx();

clusterConfigSpec.groupSpec = [new VcClusterGroupSpec()];

clusterConfigSpec.groupSpec[0].operation = VcArrayUpdateOperation[addOrEdit];

clusterConfigSpec.groupSpec[0].info = new VcClusterVmGroup();

clusterConfigSpec.groupSpec[0].info.name = VMGroupName;

clusterConfigSpec.groupSpec[0].info.vm = VMs;

if (addOrEdit == "add") {

     System.log("Create DRS VMGroup Group for Cluster: " + cluster.name);

} else {

     System.log("Update DRS VMGroup Group for Cluster: " + cluster.name);

}

task = cluster.reconfigureComputeResource_Task(clusterConfigSpec, true);