Subversion Repositories havirt

Rev

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

Rev 12 Rev 15
Line 67... Line 67...
67
   push @return, "\tUpdates list of domains on one or more existing nodes, default is all nodes";
67
   push @return, "\tUpdates list of domains on one or more existing nodes, default is all nodes";
68
   return join( "\n", @return ) . "\n";
68
   return join( "\n", @return ) . "\n";
69
}
69
}
70
 
70
 
71
 
71
 
72
# scans a node to determine which domains are running on it
-
 
73
sub getDomainsOnNode {
-
 
74
   my $node = shift;
-
 
75
   my @nodeList = grep { /^\s*\d/ } `ssh $node 'virsh list'`;
-
 
76
   for ( my $i = 0; $i < @nodeList; $i++ ) {
-
 
77
      if ( $nodeList[$i] =~ m/\s*\d+\s*([^ ]+)/ ) {
-
 
78
         $nodeList[$i] = $1;
-
 
79
      }
-
 
80
   }
-
 
81
   my %hash = map{ $_ => time } @nodeList;
-
 
82
   return \%hash;
-
 
83
}
-
 
84
 
-
 
85
# lists hardware capabilities of all nodes (virsh nodeinfo)
72
# lists hardware capabilities of all nodes (virsh nodeinfo)
86
sub list {
73
sub list {
87
   my @header;
74
   my @header;
88
   my @data;
75
   my @data;
89
   my $return;
76
   my $return;
Line 139... Line 126...
139
 
126
 
140
# check one or more nodes and determine which domains are running on them.
127
# check one or more nodes and determine which domains are running on them.
141
# defaults to everything in the node database, but the -t can have it run on only one
128
# defaults to everything in the node database, but the -t can have it run on only one
142
# this is the function that should be run every few minutes on one of the servers
129
# this is the function that should be run every few minutes on one of the servers
143
sub scan {
130
sub scan {
144
   if ( -f $main::lastScanFileName && ! $main::force ) {
-
 
145
      my $lastScan = time - ( stat( $main::lastScanFileName ) ) [9];
-
 
146
      return "Scan was run $lastScan seconds ago\n" unless $lastScan > $main::minScanTimes;
-
 
147
   }
-
 
148
   `touch $main::lastScanFileName`;
-
 
149
   &main::readDB(1);
131
   return &main::scan(@_);
150
   print Dumper( $main::statusDB->{'nodePopulation'} ) if $main::DEBUG > 2;
-
 
151
   my @targets;
-
 
152
   if ( $main::targetNode ) {
-
 
153
      push @targets, $main::targetNode;
-
 
154
   } else {
-
 
155
      @targets = keys %{$main::statusDB->{'node'}};
-
 
156
   }
-
 
157
   print "Scanning " . join( "\n", @targets ) . "\n" if $main::DEBUG;
-
 
158
   foreach my $node (@targets) {
-
 
159
      $main::statusDB->{'nodePopulation'}->{$node}->{'running'} = &getDomainsOnNode( $node );
-
 
160
      $main::statusDB->{'nodePopulation'}->{$node}->{'lastchecked'} = time;
-
 
161
      foreach my $domain ( keys %{$main::statusDB->{'nodePopulation'}->{$node}->{'running'}} ) {
-
 
162
         # make sure there is an entry for all of these domains
-
 
163
         $main::statusDB->{'virt'}->{$domain} = {} unless exists( $main::statusDB->{'virt'}->{$domain} );
-
 
164
      }
-
 
165
      print Dumper( $main::statusDB->{'nodePopulation'}->{$node} ) if $main::DEBUG > 2;
-
 
166
   }
-
 
167
   &main::writeDB();
-
 
168
   return "Node(s) updated\n";
-
 
169
}
132
}
170
 
133
 
171
 
134
 
172
# add a new node. This is the same as doing an update on a node that doesn't exist.
135
# add a new node. This is the same as doing an update on a node that doesn't exist.
173
sub add {
136
sub add {