Subversion Repositories havirt

Rev

Rev 42 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 42 Rev 47
Line 31... Line 31...
31
# v1.2.1 20240828 RWR
31
# v1.2.1 20240828 RWR
32
# force rescan after domain migrate (pulled out of havirt.pm:scan)
32
# force rescan after domain migrate (pulled out of havirt.pm:scan)
33
#
33
#
34
# v1.2.2 20250511 RWR
34
# v1.2.2 20250511 RWR
35
# Do not force rescan on migrate if dryrun or testing are set
35
# Do not force rescan on migrate if dryrun or testing are set
-
 
36
#
-
 
37
# v1.2.3 20260102 RWR
-
 
38
# Refactored all command executions to use centralized execute() function
-
 
39
# Updated getVirtConfig, start, and new functions to use execute()
36
 
40
 
37
 
41
 
38
package domain;
42
package domain;
39
 
43
 
40
use warnings;
44
use warnings;
41
use strict;  
45
use strict;  
42
 
46
 
43
# define the version number
47
# define the version number
44
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
48
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
45
use version;
49
use version;
46
our $VERSION = version->declare("1.2.2");
50
our $VERSION = version->declare("1.2.3");
47
 
51
 
48
 
52
 
49
use Data::Dumper;
53
use Data::Dumper;
50
 
54
 
51
use Exporter;
55
use Exporter;
Line 206... Line 210...
206
         print "getVirtConfig Looking on $node for $virt\n" if $main::config->{'flags'}->{'debug'} > 1;;
210
         print "getVirtConfig Looking on $node for $virt\n" if $main::config->{'flags'}->{'debug'} > 1;;
207
         if ( exists( $main::statusDB->{'nodePopulation'}->{$node}->{'running'}->{$virt} ) ) { # we found it
211
         if ( exists( $main::statusDB->{'nodePopulation'}->{$node}->{'running'}->{$virt} ) ) { # we found it
208
            print "Getting copy of XML file for $virt from $node\n" if $main::config->{'flags'}->{'verbose'};
212
            print "Getting copy of XML file for $virt from $node\n" if $main::config->{'flags'}->{'verbose'};
209
            print "Found $virt on node $node\n" if $main::config->{'flags'}->{'debug'};;
213
            print "Found $virt on node $node\n" if $main::config->{'flags'}->{'debug'};;
210
            my $command = &main::makeCommand($node, "virsh dumpxml $virt");
214
            my $command = &main::makeCommand($node, "virsh dumpxml $virt");
211
            $return = `$command`;
215
            $return = &main::execute($command);
212
            print "Writing config for $virt from $node into $filename\n" if $main::config->{'flags'}->{'debug'};
216
            print "Writing config for $virt from $node into $filename\n" if $main::config->{'flags'}->{'debug'};
213
            open XML,">$filename" or die "Could not write to $filename: $!\n";
217
            open XML,">$filename" or die "Could not write to $filename: $!\n";
214
            print XML $return;
218
            print XML $return;
215
            close XML;
219
            close XML;
216
         } # if
220
         } # if
Line 222... Line 226...
222
 
226
 
223
# start a domain
227
# start a domain
224
sub start {
228
sub start {
225
   my ( $virt, $node ) = @_;
229
   my ( $virt, $node ) = @_;
226
   my $return;
230
   my $return;
227
   $node = `hostname` unless $node;
231
   $node = &main::execute('hostname') unless $node;
228
   chomp $node;
232
   chomp $node;
229
   return "Domain $virt in maintenance mode, can not start\n" if $main::statusDB->{'virt'}->{$virt}->{'maintenance'};
233
   return "Domain $virt in maintenance mode, can not start\n" if $main::statusDB->{'virt'}->{$virt}->{'maintenance'};
230
   return "Node $node in maintenance mode, can not start\n" if $main::statusDB->{'node'}->{$node}->{'maintenance'};
234
   return "Node $node in maintenance mode, can not start\n" if $main::statusDB->{'node'}->{$node}->{'maintenance'};
231
   if ( my $foundNode = &main::findDomain( $virt ) ) {
235
   if ( my $foundNode = &main::findDomain( $virt ) ) {
232
      die "$virt already running on $foundNode, not starting\n";
236
      die "$virt already running on $foundNode, not starting\n";
Line 240... Line 244...
240
   my $command = &main::makeCommand( $node, "virsh create $filename" );
244
   my $command = &main::makeCommand( $node, "virsh create $filename" );
241
   print "Starting $virt on $node\n" if $main::config->{'flags'}->{'verbose'};
245
   print "Starting $virt on $node\n" if $main::config->{'flags'}->{'verbose'};
242
   if ( $main::config->{'flags'}->{'dryrun'} ) { # we'll actually do it
246
   if ( $main::config->{'flags'}->{'dryrun'} ) { # we'll actually do it
243
      $return =  $command;;
247
      $return =  $command;;
244
   } else {
248
   } else {
245
      $return = ( &main::executeAndWait( $command, $node, $virt, 1 ) ? 'Success' : 'Can not start');
249
      $return = ( &main::executeAndWait( $command, $node, $virt, 1, 60, 15 ) ? 'Success' : 'Can not start');
246
      &main::forceScan();
250
      &main::forceScan();
247
   }
251
   }
248
   return "$return\n";
252
   return "$return\n";
249
}
253
}
250
 
254
 
Line 259... Line 263...
259
   my $command = &main::makeCommand( $node, "virsh shutdown $virt" );
263
   my $command = &main::makeCommand( $node, "virsh shutdown $virt" );
260
   print "Attempting to shut down $virt currently on $node\n" if $main::config->{'flags'}->{'verbose'};
264
   print "Attempting to shut down $virt currently on $node\n" if $main::config->{'flags'}->{'verbose'};
261
   if ( $main::config->{'flags'}->{'dryrun'} ) { # they want us to actually do it
265
   if ( $main::config->{'flags'}->{'dryrun'} ) { # they want us to actually do it
262
      $return = $command;
266
      $return = $command;
263
   } else {
267
   } else {
264
      $return = ( &main::executeAndWait( $command, $node, $virt, 0 ) ? 'Success' : 'Time Out waiting for shutdown');
268
      $return = ( &main::executeAndWait( $command, $node, $virt, 0, 120, 15 ) ? 'Success' : 'Time Out waiting for shutdown');
265
      &main::forceScan();
269
      &main::forceScan();
266
   }
270
   }
267
   return "$return\n";
271
   return "$return\n";
268
}
272
}
269
 
273
 
Line 332... Line 336...
332
      $current{'vnc'}{$main::statusDB->{'virt'}->{$virt}->{'vnc'}} = 1;
336
      $current{'vnc'}{$main::statusDB->{'virt'}->{$virt}->{'vnc'}} = 1;
333
      #$current{'mac'}{'null'} = 1;
337
      #$current{'mac'}{'null'} = 1;
334
   }
338
   }
335
   $config{'vnc'} = &findVNCPort( \%{$current{'vnc'}} );
339
   $config{'vnc'} = &findVNCPort( \%{$current{'vnc'}} );
336
   $config{'mac'} = &makeMac();
340
   $config{'mac'} = &makeMac();
337
   $config{'uuid'} = `uuidgen`;
341
   $config{'uuid'} = &main::execute('uuidgen');
338
   chomp $config{'uuid'};
342
   chomp $config{'uuid'};
339
   if ( open TEMPLATE, "<$template" ) {
343
   if ( open TEMPLATE, "<$template" ) {
340
      $return = join( '', <TEMPLATE> );
344
      $return = join( '', <TEMPLATE> );
341
      close TEMPLATE;
345
      close TEMPLATE;
342
      foreach my $key ( keys %config ) {
346
      foreach my $key ( keys %config ) {