Hi ccnasaurabh1.
We had the same issue you are spesiying here, and we have solved it in a simlar matter,
Using the event broker to trigger to turn of DRS for a VM, after deployment.
vRA is rather dump when it comes to placement of VMs during deployment (Hint: Metro clusters) and also we are using guest operations during provisioning and if DRS moves a VM during provisioning this will fail. So we turn off the DRS during deployment, and set it to default after deployment.
Also, setting DRS to manual is not correct. The VM might still change ESX host during reboot(it will however not move it while running). See the code below and take notice of:
drsVmConfigSpec.info.enabled = false;
Setting it to false, means DRS is disabled, NOT manual.
(You also need the Custom properties as explained allready in this thread:
VirtualMachine.Admin.ForceHost
VirtualMachine.Admin.HostSelectionPolicy: EXACT_MATCH
)
If you want to make your solution a litte bit more "secure". I can metion that we use Tags in vCenter/vm/StoragePods/ESX etc. And rules in the vCenter to enforce them. So when a VM is deployed in vRA the Tags will be assigned to the VM. The VM will then always run on the host/cluster/datastore we want. (EG: a user deploys to a Metro Cluster and Storage+Cluster will always be on the same site.)
Anyway, we use 2 events in Eventbroker like this:
1. Eventbroker event Machine provisioning/Event/CloneWorkflow.CloneMachine.EVENT.OnCloneMachineComplete
(Should be blockable!)
This must turn off DRS.
2. Eventbroker event Macine provisioning/Post/VMPSMasterWorkflow32.BuildingMachine
Set DRS to "default"
The actual code is like this: (you need to add the logic around finding the VM)
function VerifyDRSEnabled(ClusterName)
{
var T = ClusterName.configurationEx;
var x = T.drsConfig;
if (x.enabled == true && x.enableVmBehaviorOverrides == true)
{
return true;
}
else
{
System.log (ClusterName.Name+" does not have DRS enabled (or allow overide per vm.");
return false;
}
}
function SetVMToManual(VM)
{
var drsVmConfigSpec = new VcClusterDrsVmConfigSpec();
drsVmConfigSpec.operation = VcArrayUpdateOperation.add;
drsVmConfigSpec.info = new VcClusterDrsVmConfigInfo();
drsVmConfigSpec.info.key = VM;
drsVmConfigSpec.info.enabled = false;
drsVmConfigSpec.info.behavior = VcDrsBehavior.manual
var VcClusterDrsVmConfigSpecArray = new Array() ;
VcClusterDrsVmConfigSpecArray.push(drsVmConfigSpec);
var clusterConfigSpec = new VcClusterConfigSpecEx();
clusterConfigSpec.drsVmConfigSpec = VcClusterDrsVmConfigSpecArray
System.log("Setting DRS setting for vm : " + VM.name + " on cluster " + Cluster.name+" to manual.");
var task = Cluster.reconfigureComputeResource_Task(clusterConfigSpec, true);
return task;
}
function SetVMToDefault(VM)
{
var myVM = new VcManagedObjectReference();
myVM.type = "VirtualMachine";
myVM.value = VM.id;
var drsVmConfigSpec = new VcClusterDrsVmConfigSpec();
drsVmConfigSpec.operation = VcArrayUpdateOperation.remove;
drsVmConfigSpec.removeKey = myVM;
var ClusterDrsVmConfigSpecArray = new Array();
ClusterDrsVmConfigSpecArray.push(drsVmConfigSpec)
var clusterConfigSpec = new VcClusterConfigSpecEx();
clusterConfigSpec.drsVmConfigSpec = ClusterDrsVmConfigSpecArray
System.log("Restoring defualt DRS setting for vm : " + VM.name + " on cluster " + Cluster.name);
var task = Cluster.reconfigureComputeResource_Task(clusterConfigSpec, true);
return task;
}
var VM =GetVMByUUID();
if (VM != null)
{
// Get Cluster of VM.
var Cluster = VM.runtime.host.parent;
if (VerifyDRSEnabled(Cluster) == true)
{
if (State == true)
{
var Task = SetVMToManual(VM);
}
else
{
var Task = SetVMToDefault(VM);
}
}
}
Hope this can help you out.