VMware {code} Community
RainerP
Contributor
Contributor
Jump to solution

Solved : Howto disable a DRS Rule

Hi,

I have searched and searched but could not find a solution.

How can I disable an existing DRS Rule with perl ?

Here is where I am starting but not getting any further 😞

my $cluster="MYCluster";

## Login to the VMware Infrastructure Web Service

Vim::login(service_url => $service_url, user_name => $username, password => $password);

my $cluster_view = Vim::find_entity_view(view_type => 'ClusterComputeResource', filter => {name => $cluster});

my $rules = $cluster_view->configurationEx->rule;

foreach(sort {$a->name cmp $b->name} @$rules) {

        my $rule = $_;

        #rule enabled = 1 , disabled = 0

        $rule->enabled=>0 ;

        my $rule_status = $rule->enabled;

        my $rule_name = $rule->name;

        print "$rule_name Status: $rule_status \n" ;

        }

Regards,

Rainer

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
stumpr
Virtuoso
Virtuoso
Jump to solution

Type on my part - in the ClusterConfigSpecEx, the property is named rulesSpec, not ruleSpec.

#!/usr/bin/perl

use strict;

use warnings;

use VMware::VIRuntime;

my %opts = (

  cluster => {

  type => ":s",

  required => 1,

  },

);

Opts::add_options(%opts);

Opts::parse();

Opts::validate();

Util::connect();

my $cluster_view = Vim::find_entity_view(

  view_type => 'ClusterComputeResource',

  filter => {name => Opts::get_option('cluster')}

);

my $rules = $cluster_view->{'configurationEx'}{'rule'};

my @rule_specs = ( );

foreach my $rule (sort {$a->name cmp $b->name} @$rules) {

        my $is_enabled = $rule->enabled;

        my $rule_name = $rule->name;

        print "$rule_name $is_enabled \n" ;

       

        my $rule_change = new ClusterRuleSpec (

            operation => ArrayUpdateOperation->new('edit'),

            info => $rule,

        );

       

        # Enable or disable the rule

        $rule_change->{'info'}{'enabled'} = 0;

               

        push @rule_specs, $rule_change;

}

my $cluster_spec = new ClusterConfigSpecEx (

  rulesSpec => \@rule_specs,

);

# Should get and check task status, we'll be lazy and use the non-Task version

$cluster_view->ReconfigureComputeResource (

  spec => $cluster_spec,

  modify => 'true'

);

Reuben Stump | http://www.virtuin.com | @ReubenStump

View solution in original post

0 Kudos
7 Replies
stumpr
Virtuoso
Virtuoso
Jump to solution

By any chance is this the problem you are seeing?

How to remove a DRS rule?

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
RainerP
Contributor
Contributor
Jump to solution

Hi,

no sorry. I'm not trying to remove a rule, I just need to disable the rule for a while.

Thx and a happy new year.......

Rainer

0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

I see.

You need to call ReconfigureComputeResource_Task() on your cluster object.  Assuming $rule is the rule you found in your code snippet.

$rule_change = new ClusterRuleSpec (

     operation => ArrayUpdateOperation->new('edit'),

     info => $rule,

);

# Enable or disable the rule

$rule_change->{'info'}{'enabled'} = 0;

$cluster_spec = new ClusterConfigSpecEx (

     ruleSpec => [ $rule_change, ]

);

# Update the cluster configuration with the rule change(s)

$cluster_view->ReconfigureComputeResource_Task (

     spec => $cluster_spec,

     modify => 'true'

);

I didn't try this code, just typed it out here.  Sorry for any typos or errors.  But that's the general logic.

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
RainerP
Contributor
Contributor
Jump to solution

Hi Reuben,

sorry, does not work, Error :

Argument ruleSpec is not valid at /usr/lib/perl5/5.10.0/VMware/VICommon.pm line 2492

    ComplexType::arg_validation('ClusterConfigSpecEx', 'ruleSpec', 'ARRAY(0xe76e38)') called at /usr/lib/perl5/5.10.0/VMware/VICommon.pm line 2464

    ComplexType::new('ClusterConfigSpecEx', 'ruleSpec', 'ARRAY(0xe76e38)') called at

my $cluster="USV-Cluster";

## Login to the VMware Infrastructure Web Service

Vim::login(service_url => $service_url, user_name => $username, password => $password);

my $cluster_view = Vim::find_entity_view(view_type => 'ClusterComputeResource', filter => {name => $cluster});

my $rules = $cluster_view->configurationEx->rule;

foreach(sort {$a->name cmp $b->name} @$rules) {

        my $rule = $_;

        my $is_enabled = $rule->enabled;

        my $rule_name = $rule->name;

        print "$rule_name $is_enabled \n" ;

        $rule_change = new ClusterRuleSpec (

                operation => ArrayUpdateOperation->new('edit'),

                info => $rule,

                );

        # Enable or disable the rule

        $rule_change->{'info'}{'enabled'} = '0';

        $cluster_spec = new ClusterConfigSpecEx (

                ruleSpec => [ $rule_change, ]

                );

        # Update the cluster configuration with the rule change(s)

        $cluster_view->ReconfigureComputeResource_Task (

                spec => $cluster_spec,

                modify => 'true'

                );

}

Regards,

Rainer

0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

Type on my part - in the ClusterConfigSpecEx, the property is named rulesSpec, not ruleSpec.

#!/usr/bin/perl

use strict;

use warnings;

use VMware::VIRuntime;

my %opts = (

  cluster => {

  type => ":s",

  required => 1,

  },

);

Opts::add_options(%opts);

Opts::parse();

Opts::validate();

Util::connect();

my $cluster_view = Vim::find_entity_view(

  view_type => 'ClusterComputeResource',

  filter => {name => Opts::get_option('cluster')}

);

my $rules = $cluster_view->{'configurationEx'}{'rule'};

my @rule_specs = ( );

foreach my $rule (sort {$a->name cmp $b->name} @$rules) {

        my $is_enabled = $rule->enabled;

        my $rule_name = $rule->name;

        print "$rule_name $is_enabled \n" ;

       

        my $rule_change = new ClusterRuleSpec (

            operation => ArrayUpdateOperation->new('edit'),

            info => $rule,

        );

       

        # Enable or disable the rule

        $rule_change->{'info'}{'enabled'} = 0;

               

        push @rule_specs, $rule_change;

}

my $cluster_spec = new ClusterConfigSpecEx (

  rulesSpec => \@rule_specs,

);

# Should get and check task status, we'll be lazy and use the non-Task version

$cluster_view->ReconfigureComputeResource (

  spec => $cluster_spec,

  modify => 'true'

);

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
RainerP
Contributor
Contributor
Jump to solution

Hi Reuben,

you made my day  Smiley Happy

Everyhting is working like a charm.

Thank you very much

Too bad u are so far away from here, otherwise I would buy u a beer Smiley Wink

Regards,

Rainer

0 Kudos
stumpr
Virtuoso
Virtuoso
Jump to solution

No problem, easy fix!

I could use that beer, but always glad to help regardless Smiley Wink

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos