Hi Team,
I'm facing an issue with VM-VM Anti-affinity, requirement is to keep the VMs in separate host, but I don't want this to be mandatory(only best effort). I have created the rule with mandatory=False as shown below. To test this I created two VMs on a same node and applied the rule, then I stopped both the VMs are tried to start them, then one of the node was not started with error
"This operation would violate a virtual machine affinity/anti-affinity rule". As I had chosen it as an optional rule, I was expecting both VMs to come up on same host. Am I missing something. Thanks in advance for any help in this regard.
As per the document
mandatory* | boolean | Flag to indicate whether compliance with this rule is mandatory or optional. The default value is false (optional).
|
try:
content = service_instance.RetrieveContent()
print("starting host anti-affinity process, for vms:" + ' '.join(vm_list)+" rule name:"+affinity_rule_name)
vm_objs = []
for one_vm in vm_list:
vm_obj = get_obj(content, [vim.VirtualMachine], one_vm)
if vm_obj is not None:
vm_objs.append(vm_obj)
if len(vm_objs) >0:
cluster = get_cluster_for_vm(content,vm_objs[0])
print("Found Cluster:"+cluster.name)
if cluster is not None:
rule = vim.cluster.AntiAffinityRuleSpec(vm=vm_objs, enabled=True, mandatory=False,
name=affinity_rule_name)
ruleSpec = vim.cluster.RuleSpec(info=rule, operation='add')
configSpec = vim.cluster.ConfigSpecEx(rulesSpec=[ruleSpec])
task = cluster.ReconfigureEx(configSpec, modify=True)
wait_for_tasks(service_instance, [task])
else:
print("Cluster could not be identified, skipping anti-affinity setting")
else:
print("VM Object list is empty, skipping anti-affinity setting")
except Exception as ex:
print("Error:"+ex.message)
To my knowledge, a VM anti-affinity rule is always hard. There is no best effort basis for this type of rule. It's either enabled (active) or disabled (inactive).
To my knowledge, a VM anti-affinity rule is always hard. There is no best effort basis for this type of rule. It's either enabled (active) or disabled (inactive).
I think you’re right for VM-VM rules: Create a VM-VM Affinity Rule