| Line 85... |
Line 85... |
| 85 |
# lists hardware capabilities of all nodes (virsh nodeinfo)
|
85 |
# lists hardware capabilities of all nodes (virsh nodeinfo)
|
| 86 |
sub list {
|
86 |
sub list {
|
| 87 |
my @header;
|
87 |
my @header;
|
| 88 |
my @data;
|
88 |
my @data;
|
| 89 |
my $return;
|
89 |
my $return;
|
| 90 |
&main::loadNodeDB();
|
90 |
&main::readDB();
|
| 91 |
foreach my $node ( sort keys %$main::nodeDB ) {
|
91 |
foreach my $node ( sort keys %{$main::statusDB->{'node'}} ) {
|
| 92 |
unless ( @header ) {
|
92 |
unless ( @header ) {
|
| 93 |
# just grab the keys for headers
|
93 |
# just grab the keys for headers
|
| 94 |
@header = sort keys %{ $main::nodeDB->{$node} };
|
94 |
@header = sort keys %{ $main::statusDB->{'node'}->{$node} };
|
| 95 |
# put Node at the beginning
|
95 |
# put Node at the beginning
|
| 96 |
unshift ( @header, 'Node' );
|
96 |
unshift ( @header, 'Node' );
|
| 97 |
}
|
97 |
}
|
| 98 |
my @line;
|
98 |
my @line;
|
| 99 |
push @line, $node;
|
99 |
push @line, $node;
|
| 100 |
foreach my $column (sort keys %{ $main::nodeDB->{$node} }) {
|
100 |
foreach my $column (sort keys %{ $main::statusDB->{'node'}->{$node} }) {
|
| 101 |
push @line, $main::nodeDB->{$node}->{$column};
|
101 |
push @line, $main::statusDB->{'node'}->{$node}->{$column};
|
| 102 |
}
|
102 |
}
|
| 103 |
push (@data, \@line );
|
103 |
push (@data, \@line );
|
| 104 |
}
|
104 |
}
|
| 105 |
return &main::report( \@header, \@data );
|
105 |
return &main::report( \@header, \@data );
|
| 106 |
}
|
106 |
}
|
| Line 108... |
Line 108... |
| 108 |
# Get information about a node. Really only needs to be done when a node is
|
108 |
# Get information about a node. Really only needs to be done when a node is
|
| 109 |
# first defined, or if there is a hardware upgrade
|
109 |
# first defined, or if there is a hardware upgrade
|
| 110 |
# reads information off of the stack (@_), but will add to that if --target
|
110 |
# reads information off of the stack (@_), but will add to that if --target
|
| 111 |
# was defined
|
111 |
# was defined
|
| 112 |
sub update {
|
112 |
sub update {
|
| 113 |
&main::loadNodeDB();
|
113 |
&main::readDB( 1 ); # open and lock so we can write to it later
|
| 114 |
my $return;
|
114 |
my $return;
|
| 115 |
my @targets;
|
115 |
my @targets;
|
| 116 |
if ( $main::targetNode ) {
|
116 |
if ( $main::targetNode ) {
|
| 117 |
push @_, $main::targetNode;
|
117 |
push @_, $main::targetNode;
|
| 118 |
}
|
118 |
}
|
| 119 |
@_ = keys %$main::nodeDB unless @_;
|
119 |
@_ = keys %{$main::statusDB->{'node'}} unless @_;
|
| 120 |
while ( my $nodename = shift ) {
|
120 |
while ( my $nodename = shift ) {
|
| 121 |
print "Updating $nodename\n" if $main::DEBUG;
|
121 |
print "Updating $nodename\n" if $main::DEBUG;
|
| 122 |
$return = `ssh $nodename 'virsh nodeinfo'`;
|
122 |
$return = `ssh $nodename 'virsh nodeinfo'`;
|
| 123 |
print "Output of ssh $nodename 'virsh nodeinfo' is\n" . $return if $main::DEBUG;
|
123 |
print "Output of ssh $nodename 'virsh nodeinfo' is\n" . $return if $main::DEBUG;
|
| 124 |
my @nodeinfo = split( "\n", $return );
|
124 |
my @nodeinfo = split( "\n", $return );
|
| Line 126... |
Line 126... |
| 126 |
my ($key, $value) = split( /:\s+/, $nodeinfo[$i] );
|
126 |
my ($key, $value) = split( /:\s+/, $nodeinfo[$i] );
|
| 127 |
if ( $value =~ m/^(\d+)\s+[a-z]+$/i ) {
|
127 |
if ( $value =~ m/^(\d+)\s+[a-z]+$/i ) {
|
| 128 |
$value = $1;
|
128 |
$value = $1;
|
| 129 |
}
|
129 |
}
|
| 130 |
$key = $conversion{$key} if exists( $conversion{$key} );
|
130 |
$key = $conversion{$key} if exists( $conversion{$key} );
|
| 131 |
$main::nodeDB->{$nodename}->{$key} = $value;
|
131 |
$main::statusDB->{'node'}->{$nodename}->{$key} = $value;
|
| 132 |
} # for
|
132 |
} # for
|
| 133 |
} # while
|
133 |
} # while
|
| 134 |
print "main::nodeDB state after update\n" . Dumper( $main::nodeDB ) if $main::DEBUG;
|
134 |
print "main::statusDB->{'node'} state after update\n" . Dumper( $main::statusDB->{'node'} ) if $main::DEBUG;
|
| 135 |
&main::writeDB( $main::nodeDBName, $main::nodeDB );
|
135 |
&main::writeDB();
|
| 136 |
return "Node has been updated\n";
|
136 |
return "Node has been updated\n";
|
| 137 |
}
|
137 |
}
|
| 138 |
|
138 |
|
| 139 |
|
139 |
|
| 140 |
# check one or more nodes and determine which domains are running on them.
|
140 |
# 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
|
141 |
# 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
|
142 |
# this is the function that should be run every few minutes on one of the servers
|
| 143 |
sub scan {
|
143 |
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 |
}
|
| 144 |
&main::loadNodeDB();
|
148 |
`touch $main::lastScanFileName`;
|
| 145 |
&main::loadNodePopulations();
|
149 |
&main::readDB(1);
|
| 146 |
print Dumper( $main::nodePopulations ) if $main::DEBUG > 2;
|
150 |
print Dumper( $main::statusDB->{'nodePopulation'} ) if $main::DEBUG > 2;
|
| 147 |
my @targets;
|
151 |
my @targets;
|
| 148 |
if ( $main::targetNode ) {
|
152 |
if ( $main::targetNode ) {
|
| 149 |
push @targets, $main::targetNode;
|
153 |
push @targets, $main::targetNode;
|
| 150 |
} else {
|
154 |
} else {
|
| 151 |
@targets = keys %$main::nodeDB;
|
155 |
@targets = keys %{$main::statusDB->{'node'}};
|
| 152 |
}
|
156 |
}
|
| 153 |
print "Scanning " . join( "\n", @targets ) . "\n" if $main::DEBUG;
|
157 |
print "Scanning " . join( "\n", @targets ) . "\n" if $main::DEBUG;
|
| 154 |
foreach my $node (@targets) {
|
158 |
foreach my $node (@targets) {
|
| 155 |
$main::nodePopulations->{$node}->{'running'} = &getDomainsOnNode( $node );
|
159 |
$main::statusDB->{'nodePopulation'}->{$node}->{'running'} = &getDomainsOnNode( $node );
|
| 156 |
$main::nodePopulations->{$node}->{'lastchecked'} = time;
|
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 |
}
|
| 157 |
print Dumper( $main::nodePopulations->{$node} ) if $main::DEBUG > 2;
|
165 |
print Dumper( $main::statusDB->{'nodePopulation'}->{$node} ) if $main::DEBUG > 2;
|
| 158 |
}
|
166 |
}
|
| 159 |
&main::writeDB( $main::nodePopulationDBName,$main::nodePopulations );
|
167 |
&main::writeDB();
|
| 160 |
return "Node(s) updated\n";
|
168 |
return "Node(s) updated\n";
|
| 161 |
}
|
169 |
}
|
| 162 |
|
170 |
|
| 163 |
|
171 |
|
| 164 |
# add a new node. This is the same as doing an update on a node that doesn't exist.
|
172 |
# add a new node. This is the same as doing an update on a node that doesn't exist.
|
| 165 |
sub add {
|
173 |
sub add {
|
| 166 |
# &main::loadNodeDB();
|
174 |
# &main::readDB();
|
| 167 |
# print "Adding $main::targetNode as new node\n" if $main::DEBUG;
|
175 |
# print "Adding $main::targetNode as new node\n" if $main::DEBUG;
|
| 168 |
# $main::nodeDB->{$main::targetNode} = '';
|
176 |
# $main::statusDB->{'node'}->{$main::targetNode} = '';
|
| 169 |
# print "Calling update for new node\n" if $main::DEBUG;
|
177 |
# print "Calling update for new node\n" if $main::DEBUG;
|
| 170 |
&update();
|
178 |
&update( @_ );
|
| 171 |
}
|
179 |
}
|
| 172 |
|
180 |
|