Subversion Repositories havirt

Rev

Rev 19 | Rev 26 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 19 Rev 25
Line 104... Line 104...
104
sub update {
104
sub update {
105
   &main::readDB( 1 ); # open and lock so we can write to it later
105
   &main::readDB( 1 ); # open and lock so we can write to it later
106
   my $return;
106
   my $return;
107
   my @requiredFields = ( 'maintenance' );
107
   my @requiredFields = ( 'maintenance' );
108
   my @targets;
108
   my @targets;
109
   if ( $main::targetNode ) {
109
   if ( $main::config->{'flags'}->{'target'} ) {
110
      push @_, $main::targetNode;
110
      push @_, $main::config->{'flags'}->{'target'};
111
   }
111
   }
112
   @_ = keys %{$main::statusDB->{'node'}} unless @_;
112
   @_ = keys %{$main::statusDB->{'node'}} unless @_;
113
   while ( my $nodename = shift  ) {
113
   while ( my $nodename = shift  ) {
114
      print "Updating $nodename\n" if $main::DEBUG;
114
      print "Updating $nodename\n" if $main::config->{'flags'}->{'debug'};
115
      $return = `ssh $nodename 'virsh nodeinfo'`;
115
      my $command = &main::makeCommand($nodename, "virsh nodeinfo" );
-
 
116
      $return = `$command`;
116
      print "Output of ssh $nodename 'virsh nodeinfo' is\n" . $return if $main::DEBUG;
117
      print "Output of [$command] is\n" . $return if $main::config->{'flags'}->{'debug'};
117
      my @nodeinfo = split( "\n", $return );
118
      my @nodeinfo = split( "\n", $return );
118
      for ( my $i = 0; $i < @nodeinfo; $i++ ) {
119
      for ( my $i = 0; $i < @nodeinfo; $i++ ) {
119
         my ($key, $value) = split( /:\s+/, $nodeinfo[$i] );
120
         my ($key, $value) = split( /:\s+/, $nodeinfo[$i] );
120
         if ( $value =~ m/^(\d+)\s+[a-z]+$/i ) {
121
         if ( $value =~ m/^(\d+)\s+[a-z]+$/i ) {
121
            $value = $1;
122
            $value = $1;
Line 126... Line 127...
126
      foreach my $field ( @requiredFields ) {
127
      foreach my $field ( @requiredFields ) {
127
         $main::statusDB->{'node'}->{$nodename}->{$field} = '' 
128
         $main::statusDB->{'node'}->{$nodename}->{$field} = '' 
128
            unless defined ( $main::statusDB->{'node'}->{$nodename}->{$field} );
129
            unless defined ( $main::statusDB->{'node'}->{$nodename}->{$field} );
129
      } # foreach
130
      } # foreach
130
   } # while
131
   } # while
131
   print "main::statusDB->{'node'} state after update\n" . Dumper( $main::statusDB->{'node'} ) if $main::DEBUG;
132
   print "main::statusDB->{'node'} state after update\n" . Dumper( $main::statusDB->{'node'} ) if $main::config->{'flags'}->{'debug'};
132
   &main::writeDB();
133
   &main::writeDB();
133
   return "Node has been updated\n";
134
   return "Node has been updated\n";
134
}      
135
}      
135
 
136
 
136
 
137
 
Line 143... Line 144...
143
 
144
 
144
 
145
 
145
# add a new node. This is the same as doing an update on a node that doesn't exist.
146
# add a new node. This is the same as doing an update on a node that doesn't exist.
146
sub add {
147
sub add {
147
#   &main::readDB();
148
#   &main::readDB();
148
#   print "Adding $main::targetNode as new node\n" if $main::DEBUG;
149
#   print "Adding $main::config->{'flags'}->{'target'} as new node\n" if $main::config->{'flags'}->{'debug'};
149
#   $main::statusDB->{'node'}->{$main::targetNode} = '';
150
#   $main::statusDB->{'node'}->{$main::config->{'flags'}->{'target'}} = '';
150
#   print "Calling update for new node\n" if $main::DEBUG;
151
#   print "Calling update for new node\n" if $main::config->{'flags'}->{'debug'};
151
   &update( @_ );
152
   &update( @_ );
152
}
153
}
153
 
154
 
-
 
155
# put node in maintenance mode
-
 
156
# if there are running domains on it, migrate them off first
154
sub maintenance {
157
sub maintenance {
155
   my ( $node, $action ) = @_;
158
   my ( $node, $action ) = @_;
156
   &main::readDB(1);
159
   &main::readDB(1);
-
 
160
   my @return;
157
   if ( $action ) {
161
   if ( $action ) {
-
 
162
      if ( lc ( $action ) eq 'on' ) {
-
 
163
         if ( $main::statusDB->{'nodePopulation'}->{$node}->{'running'} ) {
-
 
164
            # we've requested maintenance mode, but there are domains running on the node
-
 
165
            push @return, &migrateAllDomains( $node, $main::config->{'flags'}->{'target'}, keys %{$main::statusDB->{'nodePopulation'}->{$node}->{'running'}} );
-
 
166
         }
-
 
167
         if ( $main::statusDB->{'nodePopulation'}->{$node}->{'running'} ) {
-
 
168
            push @return,  "Can not mark $node in maintenance mode with running domains";
-
 
169
         } else {
-
 
170
            $main::statusDB->{'node'}->{$node}->{'maintenance'} = 1;
-
 
171
         }
-
 
172
      } else {
158
      $main::statusDB->{'node'}->{$node}->{'maintenance'} = ( lc( $action ) eq 'on' ) ? 1 : 0;
173
         $main::statusDB->{'node'}->{$node}->{'maintenance'} = 1;
-
 
174
      }
159
   }
175
   }
160
   &main::writeDB();
176
   &main::writeDB();
161
   return "Maintenance set to " . ( $main::statusDB->{'node'}->{$node}->{'maintenance'} ? 'On' : 'Off' ) . "\n";
177
   return "Maintenance set to " . ( $main::statusDB->{'node'}->{$node}->{'maintenance'} ? 'On' : 'Off' ) . "\n" .
-
 
178
          ( @return ? join( "\n", @return ) . "\n" : '');
-
 
179
}
-
 
180
 
-
 
181
 
-
 
182
# migrate domains from node $from to node $to
-
 
183
# the rest of the stack is a list of domains to migrate
-
 
184
sub migrateAllDomains {
-
 
185
   my $from = shift;
-
 
186
   my $to = shift;
-
 
187
   print "In node.pm:migrateAllDomains, migrating\n" . join( "\n", @_ ) . "\nto $to\n"
-
 
188
      if ( $main::config->{'flags'}->{'debug'} );
-
 
189
   my @commands;
-
 
190
   if ( my $error = &main::validateResources( $to, @_ ) ) {
-
 
191
      return "We can not migrate all of the domains on $from to $to\n$error\n";
-
 
192
   }
-
 
193
   while ( my $domain = shift ) {
-
 
194
      push @commands, &main::migrate( $domain, $to );
-
 
195
   }
-
 
196
   chomp @commands;
-
 
197
   return join( "\n", @commands ) . "\n";
162
}
198
}
163
 
199
 
-
 
200
   
164
 
201