| Line 29... |
Line 29... |
| 29 |
# Added a lot of 'verbose' print lines, and modified for new flag structure
|
29 |
# Added a lot of 'verbose' print lines, and modified for new flag structure
|
| 30 |
#
|
30 |
#
|
| 31 |
# v1.2.1 20240828 RWR
|
31 |
# v1.2.1 20240828 RWR
|
| 32 |
# Fixed node maintenance, adding scanning and fixing some bugs with
|
32 |
# Fixed node maintenance, adding scanning and fixing some bugs with
|
| 33 |
# the migration code
|
33 |
# the migration code
|
| - |
|
34 |
#
|
| - |
|
35 |
# v1.2.2 20260102 RWR
|
| - |
|
36 |
# Refactored command execution in update() function to use centralized execute()
|
| 34 |
|
37 |
|
| 35 |
package node;
|
38 |
package node;
|
| 36 |
|
39 |
|
| 37 |
use warnings;
|
40 |
use warnings;
|
| 38 |
use strict;
|
41 |
use strict;
|
| 39 |
|
42 |
|
| 40 |
# define the version number
|
43 |
# define the version number
|
| 41 |
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
|
44 |
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
|
| 42 |
use version;
|
45 |
use version;
|
| 43 |
our $VERSION = version->declare("1.2.1");
|
46 |
our $VERSION = version->declare("1.2.2");
|
| 44 |
|
47 |
|
| 45 |
|
48 |
|
| 46 |
use Data::Dumper;
|
49 |
use Data::Dumper;
|
| 47 |
|
50 |
|
| 48 |
use Exporter;
|
51 |
use Exporter;
|
| Line 67... |
Line 70... |
| 67 |
# show a help screen
|
70 |
# show a help screen
|
| 68 |
sub help {
|
71 |
sub help {
|
| 69 |
my @return;
|
72 |
my @return;
|
| 70 |
push @return, "node update [nodename|-t nodename]";
|
73 |
push @return, "node update [nodename|-t nodename]";
|
| 71 |
push @return, "\tUpdates capabilities on one or more nodes, default is all nodes";
|
74 |
push @return, "\tUpdates capabilities on one or more nodes, default is all nodes";
|
| - |
|
75 |
push @return, "node add nodename";
|
| - |
|
76 |
push @return, "\tAdds a new node to the cluster. nodename must be reachable via ssh without password";
|
| 72 |
push @return, "node list [--format|-f screen|tsv]";
|
77 |
push @return, "node list [--format screen|tsv]";
|
| 73 |
push @return, "\tLists all nodes with some statistics about them as screen or tsv (default screen)";
|
78 |
push @return, "\tLists all nodes with some statistics about them as screen or tsv (default screen)";
|
| 74 |
push @return, "node scan [nodename|-t nodename]";
|
79 |
push @return, "node scan [nodename|-t nodename]";
|
| 75 |
push @return, "\tUpdates list of domains on one or more existing nodes, default is all nodes";
|
80 |
push @return, "\tUpdates list of domains on one or more existing nodes, default is all nodes";
|
| 76 |
push @return, "node maintenance nodename [on|off --target=targetNode]";
|
81 |
push @return, "node maintenance nodename [on|off --target=targetNode]";
|
| 77 |
push @return, "\ton - set maintenance flag; no domains can be started/migrated to node";
|
82 |
push @return, "\ton - set maintenance flag; no domains can be started/migrated to node";
|
| 78 |
push @return, "\t target must be set with the --target flag";
|
83 |
push @return, "\t target must be set with the --target flag";
|
| 79 |
push @return, "\toff - Allows domains to be migrated/started on node";
|
84 |
push @return, "\toff - Allows domains to be migrated/started on node";
|
| 80 |
push @return, "\tnothing - displays current maintenance flag";
|
85 |
push @return, "\tnothing - displays current maintenance flag";
|
| 81 |
push @return, "\tNote: a node with any domains running can not have maintenance mode turned on";
|
- |
|
| 82 |
return join( "\n", @return ) . "\n";
|
86 |
return join( "\n", @return ) . "\n";
|
| 83 |
}
|
87 |
}
|
| 84 |
|
88 |
|
| 85 |
|
89 |
|
| 86 |
# lists hardware capabilities of all nodes (virsh nodeinfo)
|
90 |
# lists hardware capabilities of all nodes (virsh nodeinfo)
|
| Line 123... |
Line 127... |
| 123 |
print "Updating $nodename\n" if $main::config->{'flags'}->{'debug'} || $main::config->{'flags'}->{'verbose'};
|
127 |
print "Updating $nodename\n" if $main::config->{'flags'}->{'debug'} || $main::config->{'flags'}->{'verbose'};
|
| 124 |
my $command = &main::makeCommand($nodename, "virsh nodeinfo" );
|
128 |
my $command = &main::makeCommand($nodename, "virsh nodeinfo" );
|
| 125 |
if ( $main::config->{'flags'}->{'dryrun'} ) {
|
129 |
if ( $main::config->{'flags'}->{'dryrun'} ) {
|
| 126 |
push @return, $command;
|
130 |
push @return, $command;
|
| 127 |
} else {
|
131 |
} else {
|
| 128 |
my $return= `$command`;
|
132 |
my $return= &main::execute($command);
|
| 129 |
print "Output of [$command] is\n" . $return if $main::config->{'flags'}->{'debug'};
|
133 |
print "Output of [$command] is\n" . $return if $main::config->{'flags'}->{'debug'};
|
| 130 |
my @nodeinfo = split( "\n", $return );
|
134 |
my @nodeinfo = split( "\n", $return );
|
| 131 |
for ( my $i = 0; $i < @nodeinfo; $i++ ) {
|
135 |
for ( my $i = 0; $i < @nodeinfo; $i++ ) {
|
| 132 |
my ($key, $value) = split( /:\s+/, $nodeinfo[$i] );
|
136 |
my ($key, $value) = split( /:\s+/, $nodeinfo[$i] );
|
| 133 |
if ( $value =~ m/^(\d+)\s+[a-z]+$/i ) {
|
137 |
if ( $value =~ m/^(\d+)\s+[a-z]+$/i ) {
|
| Line 160... |
Line 164... |
| 160 |
sub add {
|
164 |
sub add {
|
| 161 |
&update( @_ );
|
165 |
&update( @_ );
|
| 162 |
}
|
166 |
}
|
| 163 |
|
167 |
|
| 164 |
# put node in maintenance mode
|
168 |
# put node in maintenance mode
|
| 165 |
# if there are running domains on it, migrate them off first
|
169 |
# no domains are allowed to be started or migrated to a node in maintenance mode
|
| 166 |
# If we migrate, we must then do a force scan, which locks
|
170 |
# if we are turning maintenance mode on, we must migrate all domains off
|
| 167 |
# the database. So, we must read the database shared first, then
|
- |
|
| 168 |
# only read exclusive when we are actually changing the maintenance
|
171 |
# maintenance does NOT remove existing domains, but prevents new ones from being added
|
| 169 |
# flag. The solution here is a kludge, but it at least works
|
- |
|
| 170 |
# we do the exclusive read only just before we change then write
|
172 |
# however, cluster::balance will try to migrate them off
|
| 171 |
sub maintenance {
|
173 |
sub maintenance {
|
| 172 |
my ( $node, $action ) = @_;
|
174 |
my ( $node, $action ) = @_;
|
| 173 |
&main::readDB();
|
175 |
&main::readDB();
|
| 174 |
my @return;
|
176 |
my @return;
|
| 175 |
if ( $action ) {
|
177 |
if ( $action ) {
|
| 176 |
print "Found action [$action] in node.pm:maintenance\n" if $main::config->{'flags'}->{'debug'} > 1;
|
178 |
print "Found action [$action] in node.pm:maintenance\n" if $main::config->{'flags'}->{'debug'};
|
| 177 |
&main::readDB(1);
|
179 |
&main::readDB(1);
|
| 178 |
$main::statusDB->{'node'}->{$node}->{'maintenance'} = lc $action eq 'on';
|
180 |
$main::statusDB->{'node'}->{$node}->{'maintenance'} = lc $action eq 'on';
|
| 179 |
&main::writeDB();
|
181 |
&main::writeDB();
|
| 180 |
}
|
182 |
}
|
| 181 |
&main::readDB();
|
183 |
&main::readDB();
|