7 Replies Latest reply on May 8, 2015 6:05 PM by EvilDennisR

    How to remove a DRS rule?

    xnjiang Lurker

      Hi,

       

         I tried to use the following code to remove a DRS rule but it did not work.

       

            my $ruleinfo = ClusterRuleInfo->new(name => "testrule");
            my $rules_spec = ClusterRuleSpec->new(info => $ruleinfo,
                                                  operation => ArrayUpdateOperation->new('remove'));
            my @my_rules_spec = ($rules_spec);
            my $spec = ClusterConfigSpecEx->new(rulesSpec => \@my_rules_spec);
            eval {
               $cluster_view->ReconfigureComputeResource_Task(spec => $spec,
                                                              modify => 'false');

       

         Anyone knows what is wrong? Also, there is a "removeKey" property in ClusterRuleSpec, what is it for?

       

         Thanks.

       

      - Sean

        • 1. Re: How to remove a DRS rule?
          stumpr Master

          You should be able to delete by using the key value in the ClusterRuleInfo object.

           

          my $rules_spec = ClusterRuleSpec->new(removeKey => $ruleKey,

                                                     operation => ArrayUpdateOperation->new('remove'));
                my @my_rules_spec = ($rules_spec);
                my $spec = ClusterConfigSpecEx->new(rulesSpec => \@my_rules_spec);
                eval {
                   $cluster_view->ReconfigureComputeResource_Task(spec => $spec,
                                                                  modify => 'true');

           

           

          • 2. Re: How to remove a DRS rule?
            tomboven Lurker

            Hi all,

             

            Was someone able to remove a DRS rule using the perl API ? I tried the above combination but I'm unable to get it working. I'm currently stuck trying with different combinations on the piece of code below:

             

            sub removeRule {
                    my ( $cluster, $existingRule ) = @_;
            
                    my $ruleInfo = ClusterRuleInfo->new(
                                    key => $existingRule->{'key'},
                                    name => $existingRule->{'name'},
                            );
            
                    my $ruleSpec = ClusterRuleSpec->new(
                                    info => $ruleInfo,
                                    removeKey => $existingRule->{'key'},
                                    operation => ArrayUpdateOperation->new('remove'),
                            );
            
                    my @ruleSpecs = ($ruleSpec);
            
                    my $clusterConfigSpec = ClusterConfigSpecEx->new(
                                    rulesSpec => \@ruleSpecs,
                            );
            
                    my $task = $cluster->ReconfigureComputeResource_Task(
                                    spec => $clusterConfigSpec,
                                    modify => 1,
                            );
            }
            

             

            But this always returns "A specified parameter was not correct." error message in vCenter

            If someone could point me into the right direction.

             

            Many thanks,

            Tom

            • 3. Re: How to remove a DRS rule?
              svenXY Lurker

              Hi,

               

              @Tom - thanks for bringing this up again.

               

              We face the same problem here - no problems creating rules and adding VMs to rules.

               

              But we also completely fail removing hosts from rules or deleting rules from the cluster.

               

              So - if anyone out there has some insight into this and can provide some working example, we'd greatly appreciate it.

               

              Thanks,

              Sven

               

              PS: Is there a way to get some more meaningful error messages than 'A specified parameter was not correct'?

              • 4. Re: How to remove a DRS rule?
                Gungazoo Lurker

                I just tried to remove it as well and am having the same problem.  I'm using Ruby instead of perl but am getting the same error.

                 

                Has anyone found a way to make it work?

                 

                Thanks,

                 

                Peter

                • 5. Re: How to remove a DRS rule?
                  stumpr Master

                  I just looked into this, it's a bug.  I've seen the same type of bug with AnyType properties with Host Profiles as well.

                   

                  Basically, the Perl SDK treats all AnyTypes (if it doesn't match a known SDK object type) as string.  But the vSphere API cannot convert the string to a number internally so it errors out. 

                   

                  BAD-

                  <spec><rulesSpec><operation>remove</operation><removeKey xsi:type="xsd:string">2</removeKey><info xsi:type="ClusterAffinityRuleSpec"><key>2</key><enabled>1</enabled><name>Test</name><userCreated>1</userCreated><vm type="VirtualMachine">vm-462</vm>

                  <vm type="VirtualMachine">vm-398</vm>

                  </info></rulesSpec></spec>

                   

                  GOOD-

                  <spec><rulesSpec><operation>remove</operation><removeKey xsi:type="xsd:int">2</removeKey><info xsi:type="ClusterAffinityRuleSpec"><key>2</key><enabled>1</enabled><name>Test</name><userCreated>1</userCreated><vm type="VirtualMachine">vm-462</vm>

                  <vm type="VirtualMachine">vm-398</vm>

                  </info></rulesSpec></spec>

                   

                  I had two work arounds in the past:

                   

                  1) Generate your own SOAP message body and header.  You can get all the session information from your current VIM session, be sure to set removeKey as 'xsd:int'.

                   

                  2) Modify the Perl SDK VICommon.pm to include a check for numbers and send it in as xsd:int.  However, it may still choke on doubles, floats, etc.  The other option might be to add your own type override for these odd cases.

                   

                  In either case, a bug should be filed.  I'll try to open one today as well, but it's always good to associate it with a customer for more traction and to expedite it for tracking especially if in a production environment.

                  • 6. Re: How to remove a DRS rule?
                    stumpr Master

                    This is obviously dated, but I ran into this issue again.  This time I looked through VICommon.pm in the VI Perl SDK and noticed a base XSD type PrimType.  It's actually documented in the VI Perl SDK programming guide, however, it is not completely clear on how to use it these types of issues (with AnyType serialization problems in the VI Perl SDK).

                     

                     

                    It's actually an easy fix, though it might be hard to isolate the cause.  However, if you see an AnyType property in a data object or API method and are getting InvalidArgument faults, this is likely the cause of the problem.

                     

                     

                    I wrote up a quick description and a sample script that fixes the DRS rule removal problem here.

                    • 7. Re: How to remove a DRS rule?
                      EvilDennisR Lurker

                      This works-- You just need to change one line:

                       

                      removeKey => $existingRule->{'key'},


                      to

                       

                      removeKey => new PrimType($existingRule->{'key'}, 'int'),