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);