Subversion Repositories havirt

Rev

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

Rev 4 Rev 5
Line 39... Line 39...
39
 
39
 
40
use Exporter;
40
use Exporter;
41
 
41
 
42
our @ISA = qw( Exporter );
42
our @ISA = qw( Exporter );
43
our @EXPORT = qw( 
43
our @EXPORT = qw( 
44
                  &node &list &update &scan
44
                  &node &list &update &scan &add
45
                );
45
                );
46
 
46
 
47
# Converts from output of node info to a key we want to use
47
# Converts from output of node info to a key we want to use
48
my %conversion = ( 
48
my %conversion = ( 
49
  'CPU frequency' => 'clock',
49
  'CPU frequency' => 'clock',
Line 54... Line 54...
54
  'Memory size' => 'memory',
54
  'Memory size' => 'memory',
55
  'NUMA cell(s)' => 'numa_cells',
55
  'NUMA cell(s)' => 'numa_cells',
56
  'Thread(s) per core' => 'threads_per_core'
56
  'Thread(s) per core' => 'threads_per_core'
57
);
57
);
58
 
58
 
59
 
-
 
-
 
59
# read the node database into memory, if it was not already loaded
60
sub loadNodeDB {
60
sub loadNodeDB {
61
   print "In loadNodeDB, reading $main::nodeDBName\n" if $main::DEBUG > 1;
61
   print "In loadNodeDB, reading $main::nodeDBName\n" if $main::DEBUG > 1;
62
   return if $main::nodeDB;
62
   return if $main::nodeDB;
63
   $main::nodeDB = &main::readDB( $main::nodeDBName );
63
   $main::nodeDB = &main::readDB( $main::nodeDBName );
64
   print "Success\n" if $main::DEBUG > 1;
64
   print "Success\n" if $main::DEBUG > 1;
65
}
65
}
66
 
66
 
-
 
67
# scans a node to determine which domains are running on it
67
sub getDomainsOnNode {
68
sub getDomainsOnNode {
68
   my $node = shift;
69
   my $node = shift;
69
   my @nodeList = grep { /^\s*\d/ } `ssh $node 'virsh list'`;
70
   my @nodeList = grep { /^\s*\d/ } `ssh $node 'virsh list'`;
70
   for ( my $i = 0; $i < @nodeList; $i++ ) {
71
   for ( my $i = 0; $i < @nodeList; $i++ ) {
71
      if ( $nodeList[$i] =~ m/\s*\d+\s*([^ ]+)/ ) {
72
      if ( $nodeList[$i] =~ m/\s*\d+\s*([^ ]+)/ ) {
Line 74... Line 75...
74
   }
75
   }
75
   my %hash = map{ $_ => time } @nodeList;
76
   my %hash = map{ $_ => time } @nodeList;
76
   return \%hash;
77
   return \%hash;
77
}
78
}
78
 
79
 
79
 
-
 
-
 
80
# lists hardware capabilities of all nodes (virsh nodeinfo)
80
sub list {
81
sub list {
81
   my @header;
82
   my @header;
82
   my @data;
83
   my @data;
83
   my $return;
84
   my $return;
84
   &loadNodeDB();
85
   &loadNodeDB();
Line 97... Line 98...
97
      push (@data, \@line );
98
      push (@data, \@line );
98
   }
99
   }
99
   $return = &main::report( \@header, \@data );
100
   $return = &main::report( \@header, \@data );
100
}
101
}
101
 
102
 
102
 
-
 
-
 
103
# Get information about a node. Really only needs to be done when a node is
-
 
104
# first defined, or if there is a hardware upgrade
103
sub update {
105
sub update {
104
   &loadNodeDB();
106
   &loadNodeDB();
105
   my $return;
107
   my $return;
106
   my @targets;
108
   my @targets;
107
   if ( $main::targetNode ) {
109
   if ( $main::targetNode ) {
108
      push @targets, $main::targetNode;
110
      push @targets, $main::targetNode;
109
   } else {
111
   } else {
110
      @targets = keys %$main::nodeDB;
112
      @targets = keys %$main::nodeDB;
111
   }
113
   }
112
   while ( my $nodename = shift ) {
114
   while ( my $nodename = shift @targets ) {
113
      print "Updating $nodename\n" if $main::DEBUG;
115
      print "Updating $nodename\n" if $main::DEBUG;
114
      $return = `ssh $nodename 'virsh nodeinfo'`;
116
      $return = `ssh $nodename 'virsh nodeinfo'`;
115
      print "Output of ssh $nodename 'virsh nodeinfo' is\n" . $return if $main::DEBUG;
117
      print "Output of ssh $nodename 'virsh nodeinfo' is\n" . $return if $main::DEBUG;
116
      my @nodeinfo = split( "\n", $return );
118
      my @nodeinfo = split( "\n", $return );
117
      for ( my $i = 0; $i < @nodeinfo; $i++ ) {
119
      for ( my $i = 0; $i < @nodeinfo; $i++ ) {
Line 126... Line 128...
126
   print "main::nodeDB state after update\n" . Dumper( $main::nodeDB ) if $main::DEBUG;
128
   print "main::nodeDB state after update\n" . Dumper( $main::nodeDB ) if $main::DEBUG;
127
   &main::writeDB( $main::nodeDBName, $main::nodeDB );
129
   &main::writeDB( $main::nodeDBName, $main::nodeDB );
128
   return "Node has been updated\n";
130
   return "Node has been updated\n";
129
}      
131
}      
130
 
132
 
-
 
133
 
-
 
134
# check one or more nodes and determine which domains are running on them.
-
 
135
# defaults to everything in the node database, but the -t can have it run on only one
-
 
136
# this is the function that should be run every few minutes on one of the servers
131
sub scan {
137
sub scan {
132
   &loadNodeDB();
138
   &loadNodeDB();
133
   &main::loadNodePopulations();
139
   &main::loadNodePopulations();
134
   print Dumper( $main::nodePopulations ) if $main::DEBUG > 2;
140
   print Dumper( $main::nodePopulations ) if $main::DEBUG > 2;
135
   my @targets;
141
   my @targets;
Line 144... Line 150...
144
      $main::nodePopulations->{$node}->{'lastchecked'} = time;
150
      $main::nodePopulations->{$node}->{'lastchecked'} = time;
145
      print Dumper( $main::nodePopulations->{$node} ) if $main::DEBUG > 2;
151
      print Dumper( $main::nodePopulations->{$node} ) if $main::DEBUG > 2;
146
   }
152
   }
147
   &main::writeDB( $main::nodePopulationDBName,$main::nodePopulations );
153
   &main::writeDB( $main::nodePopulationDBName,$main::nodePopulations );
148
   return "Node(s) updated\n";
154
   return "Node(s) updated\n";
149
}   
155
}
150
 
156
 
151
sub node {
-
 
152
   my $action = lc shift;
-
 
153
 
157
 
154
   print "In node, action is $action\n" if $main::DEBUG;
158
# add a new node. This is the same as doing an update on a node that doesn't exist.
155
   my $return = '';
159
sub add {
156
   &loadNodeDB();
160
#   &loadNodeDB();
157
   if ( $action eq 'update' ) { # read information for nodes and update database
161
#   print "Adding $main::targetNode as new node\n" if $main::DEBUG;
158
      return &update( @_ );
162
#   $main::nodeDB->{$main::targetNode} = '';
159
   } elsif ( $action eq 'list' ) { # dump database to screen
163
#   print "Calling update for new node\n" if $main::DEBUG;
160
      return &list();
-
 
161
   } elsif ( $action eq 'scan' ) {
-
 
162
      return &scan();
-
 
163
   } # if..elsif
-
 
164
   return $return;
164
   &update();
165
}
165
}
166
 
166
 
167
 
-