new-drsrule Unable to cast object of type ‘VMware.Vim.ClusterVmHostRuleInfo’ to type ‘VMware.Vim.ClusterAntiAffinityRuleSpec’.

I was trying to create a new drs vm-vm anti affinity rule and got this red error :

PowerCLI C:\> New-DrsRule -Cluster xyz -Name AA-vm1,vm2 -KeepTogether:$false -VM vm1,vm2
New-DrsRule : 5/14/2012 9:30:23 AM New-DrsRule Unable to cast object of type 'VMware.Vim.ClusterVmHostRuleInf
o' to type 'VMware.Vim.ClusterAntiAffinityRuleSpec'.
At line:1 char:12
+ New-DrsRule <<<< -Cluster xyz -Name AA-vm1,vm2 -KeepTogether:$false -VM vm1,vm2
+ CategoryInfo : NotSpecified: (:) [New-DrsRule], ViError
+ FullyQualifiedErrorId : Client20_ClientSideTaskImpl_ThreadProc_UnhandledException,VMware.VimAutomation.ViCore.Cm

Still , i do not know if there is a way to fix this , or is this just a bug and will be fixed in new release of powercli.
This error is only “informing” us, and the rule is still created on this cluster, so i would say that this is only a minor issue. But if you are not happy that it outputs those nasty red errors, you can do other function that ads a vm-vm rule on a cluster , i will write function later, but if want to write it yourself this should be more than enough in order to write it:

$spec2 = New-Object VMware.Vim.ClusterConfigSpecEx
$spec2.rulesSpec = New-Object VMware.Vim.ClusterRuleSpec[] (2)
$spec2.rulesSpec[0] = New-Object VMware.Vim.ClusterRuleSpec
$spec2.rulesSpec[0].operation = "add"
$spec2.rulesSpec[0].info = New-Object VMware.Vim.ClusterAffinityRuleSpec            
$spec2.rulesSpec[0].info.enabled = $true
$spec2.rulesSpec[0] = "AA-vm1-vm2"
$spec2.rulesSpec[0].info.userCreated = $true
$spec2.rulesSpec[0].info.vm = (get-vm vm1,vm2|get-view) |% {$_.moref}  
(Get-View -Id (get-cluster xyz).id).ReconfigureComputeResource_Task($spec2, $true)

# object for AA rule is VMware.Vim.ClusterAntiAffinityRuleSpec
# you can put as many vms as you want in info.vm section...

Today is diablo3 world premiere 😉 so um… i will not write this function today 😉
Why this error is showing up ? that’s because i have used a VM-TO-HOST rule on cluster. Once you define a rule like that, new-drsrule will output this error while creating a VM-VM rule on that cluster. I have observed this on powercli 5.0.1. Same for remove-drsRule, when you will specify a vm-host rule, it will also FAIL, not just by screaming with error, but the deleting will not proceed. I will also write a function for this , but like i said not today 😉
I will post a pack of drs functions shortly with add/remove and so on. This topic was mentioned on vmware communities, you can open it using this link and check how to reproduce this error step by step.
VMware has confirmed this bug, and wrote that it is fixed in new release. Nice!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s