5 Replies Latest reply on May 15, 2012 3:41 AM by Grzesiekk

    Unable to cast object of type 'VMware.Vim.ClusterVmHostRuleInf o' to type 'VMware.Vim.ClusterAntiAffinityRuleSpec'

    Grzesiekk Expert
      Hello,

        i  was suprised by this error. Have anyone seen this as well ? I was doing some affinity rules for  cluster. In the beggining when there were no vmgroups,hostgroups,no vm to host rules, this command was running just fine, no errors were generated. After vm-vm antiaffinity rules, i made some vm groups, host groups, and created AA rules for this cluster as well via api.  Everything worked well, no errors during creation. But after some days, i wanted to add 1 more rule vm-vm AA. And i received this error , any idea why would this come up ? This error shows up, but the rule is created anyways.

      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
         dlets.Commands.NewDrsRule

       

      Thanks,

      Greg

       

      btw.

      Why would he want to cast "VMware.Vim.ClusterVmHostRuleInfo" ?

      "A ClusterVmHostRuleInfo object identifies virtual machines  and host groups that determine virtual machine placement. The virtual  machines and hosts referenced by a VM-Host rule must be in the same cluster."

      But this is a VM-VM antiaffinity rule, not a vm-host rule.  I still have no clue why the error pops out but i used onyx to see if i will have the same issue when doing this with api:

       

      $spec = New-Object VMware.Vim.ClusterConfigSpecEx
      $spec.rulesSpec = New-Object VMware.Vim.ClusterRuleSpec[] (2)
      $spec.rulesSpec[0] = New-Object VMware.Vim.ClusterRuleSpec
      $spec.rulesSpec[0].operation = "add"
      $spec.rulesSpec[0].info = New-Object VMware.Vim.ClusterAffinityRuleSpec
      $spec.rulesSpec[0].info.enabled = $true
      $spec.rulesSpec[0].info.name = "AA-vm1-vm2"
      $spec.rulesSpec[0].info.userCreated = $true
      $spec.rulesSpec[0].info.vm = New-Object VMware.Vim.ManagedObjectReference[] (2)
      $spec.rulesSpec[0].info.vm[0] = New-Object VMware.Vim.ManagedObjectReference
      $spec.rulesSpec[0].info.vm[0].type = "VirtualMachine"
      $spec.rulesSpec[0].info.vm[0].value = "vm-xxxxxxx"
      $spec.rulesSpec[0].info.vm[1] = New-Object VMware.Vim.ManagedObjectReference
      $spec.rulesSpec[0].info.vm[1].type = "VirtualMachine"
      $spec.rulesSpec[0].info.vm[1].value = "vm-yyyyyyy"

       

      $_this = Get-View -Id 'ClusterComputeResource-domain-c345645464'
      $_this.ReconfigureComputeResource_Task($spec, $true)

       

      This is working without any errors