Subversion Repositories havirt

Rev

Rev 46 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 rodolico 1
#!/usr/bin/env perl
2
 
3
# Common library for havirt. Basically, just a place to put things which may be used by any
4 rodolico 4
# part of havirt. More for organizations purposes.
3 rodolico 5
 
4 rodolico 6
# Copyright 2024 Daily Data, Inc.
7
# 
8
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following 
9
# conditions are met:
10
#
11
#   Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
12
#   Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer 
13
#   in the documentation and/or other materials provided with the distribution.
14
#   Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived
15
#   from this software without specific prior written permission.
16
# 
17
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
18
# NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
19
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
22
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
 
24
 
3 rodolico 25
# v0.0.1 20240602 RWR
26
# Initial setup
26 rodolico 27
#
28
# v1.2.0 20240826 RWR
29
# Added some code to migrate domains if node placed in maintenance mode
30
# Added a lot of 'verbose' print lines, and modified for new flag structure
31
#
38 rodolico 32
# v1.2.1 20240828 RWR
33
# removed forceScan from migrateAll and relying on calling scripts to do that.
42 rodolico 34
#
35
# v1.2.2 20250511 RWR
36
# added source node as a parameter for migrate. If source node is passed in, will not run readDB
46 rodolico 37
#
38
# v1.2.3 20260101 RWR
39
# modified executeAndWait to return 0 on timeout, 1 on success
40
# bugfix in diffArray to handle case where arr1 is smaller than arr2
47 rodolico 41
#
42
# v1.2.4 20260102 RWR
43
# Created centralized execute() function for all command execution
44
# Refactored all backtick command executions to use execute() for easier debugging and maintenance
45
# All 7 command execution points in havirt.pm now use execute()
3 rodolico 46
 
47
package havirt;
48
 
49
use warnings;
50
use strict;  
51
 
25 rodolico 52
BEGIN {
53
   use FindBin;
54
   use File::Spec;
55
   # use libraries from the directory this script is in
56
   use Cwd 'abs_path';
57
   use File::Basename;
58
   use lib dirname( abs_path( __FILE__ ) );
59
}
60
 
3 rodolico 61
use Data::Dumper qw(Dumper); # Import the Dumper() subroutine
47 rodolico 62
use YAML::Tiny;
3 rodolico 63
 
4 rodolico 64
# define the version number
65
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
66
use version;
47 rodolico 67
our $VERSION = version->declare("1.2.4");
4 rodolico 68
 
69
 
3 rodolico 70
use Exporter;
71
 
72
our @ISA = qw( Exporter );
73
our @EXPORT = qw( 
25 rodolico 74
                  &readDB
75
                  &writeDB
76
                  &report
77
                  &scan
78
                  &makeCommand
47 rodolico 79
                  &execute
25 rodolico 80
                  &forceScan
15 rodolico 81
                  &executeAndWait
18 rodolico 82
                  &findDomain
83
                  &diffArray
25 rodolico 84
                  &makeConfig
85
                  &readConfig
86
                  &getAvailableResources
87
                  &resource
88
                  &validateResources
89
                  &migrate
3 rodolico 90
                );
91
 
12 rodolico 92
# read a DB file (just a YAML)
93
# if $lock is set, will create a "lock" file so other processes will
94
# not try to write to it. Using custom code as flock is automagically
95
# release when the file is read
3 rodolico 96
 
97
sub readDB {
12 rodolico 98
   my $lock = shift;
25 rodolico 99
   my $lockFileName = "$main::config->{'status db filename'}.lock";
12 rodolico 100
   my $lockTime = 5; # maximum time to wait for lock to clear
101
   # wait for lock to clear if it exists, if we are wanting a lock
102
   # and we have tried it for $locktime iterations
103
   while ( $lock && -f $lockFileName && $lockTime-- ) {
104
      sleep 1; # wait one second, then try again
105
   }
106
   if ( $lock ) {
25 rodolico 107
      die "Something has $main::config->{'status db filename'} locked, aborting\n" if -f $lockFileName;
47 rodolico 108
      &execute("touch $lockFileName");
12 rodolico 109
   }
3 rodolico 110
   my $yaml = YAML::Tiny->new( {} );
25 rodolico 111
   if ( -f $main::config->{'status db filename'} ) {
112
      $yaml = YAML::Tiny->read( $main::config->{'status db filename'} );
3 rodolico 113
   }
12 rodolico 114
   $main::statusDB = $yaml->[0];
3 rodolico 115
}
116
 
26 rodolico 117
# Write the statusDB file out, overwriting the current one
118
# remove the lock file, if it exists
3 rodolico 119
sub writeDB {
12 rodolico 120
   my $yaml = YAML::Tiny->new( $main::statusDB );
25 rodolico 121
   $yaml->write( $main::config->{'status db filename'} );
122
   unlink "$main::config->{'status db filename'}.lock" if -f "$main::config->{'status db filename'}.lock"; # release any lock we might have on it
3 rodolico 123
}
124
 
26 rodolico 125
# create a report and send to STDOUT.
4 rodolico 126
sub report {
25 rodolico 127
   if ( $main::config->{'flags'}->{'format'} eq 'tsv' ) {
4 rodolico 128
      return &report_tsv( @_ );
129
   } else {
130
      return &report_screen( @_ );
131
   }
132
}
133
 
26 rodolico 134
# report as a tab separated values, no encapulation
3 rodolico 135
sub report_tsv {
136
   my ( $header, $data ) = @_;
137
   my @output;
138
   push @output, join( "\t", @$header );
139
   for( my $line = 0; $line < @$data; $line++ ) {
140
      push @output, join( "\t", @{$data->[$line]} );
141
   } # for
142
   return join( "\n", @output ) . "\n";
143
}
144
 
26 rodolico 145
# report suitable for screen, with fixed width columns
3 rodolico 146
sub report_screen {
147
   my ( $header, $data ) = @_;
148
   my @output;
149
   my @widths;
150
   my $column;
151
   my $row;
152
   # First, initialize by using the length of the headers
153
   for ( $column = 0; $column < @$header; $column++ ) {
154
      @widths[$column] = length( $header->[$column] );
155
   }
156
   # now, go through all data in each row, for each column, and increment the width if it is larger
157
   for ( $row = 0; $row < @$data; $row++ ) {
158
      for ( $column = 0; $column < @$header; $column++ ) {
159
         $widths[$column] = length( $data->[$row][$column] ) 
160
            if length( $data->[$row][$column] ) > $widths[$column];
161
      } # for column
162
   } # for row
163
   # actually do the print now
164
   my @format;
165
   for ( $column = 0; $column < @widths; $column++ ) {
166
      push ( @format, '%' . $widths[$column] . 's' );
167
   }
168
   my $format = join( ' ', @format ) . "\n";
169
   my $output = sprintf( $format, @$header );
170
   for ( $row = 0; $row < @$data; $row++ ) {
171
      $output .= sprintf( $format, @{$data->[$row]} );
172
   } # for row
173
   return $output;
174
}
10 rodolico 175
 
15 rodolico 176
# scans a node to determine which domains are running on it
26 rodolico 177
# updates each domain to reflect when it was last seen
47 rodolico 178
# if testing flag is set, reads from testing directory file: $node_scan.testing
15 rodolico 179
sub getDomainsOnNode {
180
   my $node = shift;
47 rodolico 181
   my @nodeList;
182
 
183
   if ( $main::config->{'flags'}->{'testing'} ) {
184
      # Testing mode: read from file instead of executing command
185
      my $testFile = $main::config->{'script dir'} . "/tests/${node}_scan.testing";
186
      print "havirt.pm:getDomainsOnNode, reading from test file: $testFile\n" if $main::config->{'flags'}->{'debug'} > 2;
187
      if ( -f $testFile ) {
188
         open my $fh, '<', $testFile or die "Could not open test file $testFile: $!\n";
189
         @nodeList = grep { /^\s*\d/ } <$fh>;
190
         close $fh;
191
      } else {
192
         print "Warning: Test file $testFile not found, returning empty list\n" if $main::config->{'flags'}->{'verbose'};
193
      }
194
   } else {
195
      # Normal mode: execute virsh command
196
      my $command = &main::makeCommand( $node, 'virsh list' );
197
      print "havirt.pm:getDomainsOnNode, command is $command\n" if $main::config->{'flags'}->{'debug'} > 2;
198
      @nodeList = grep { /^\s*\d/ } &main::execute($command);
199
   }
200
 
15 rodolico 201
   for ( my $i = 0; $i < @nodeList; $i++ ) {
202
      if ( $nodeList[$i] =~ m/\s*\d+\s*([^ ]+)/ ) {
203
         $nodeList[$i] = $1;
204
      }
205
   }
206
   my %hash = map{ $_ => time } @nodeList;
207
   return \%hash;
208
}
209
 
18 rodolico 210
# find node a domain is on
211
# first parameter is the domain name
212
# rest of @_ is list of nodes to search
213
# if no nodes passed in, will search all known nodes
214
# returns first node found with the domain, or an empty string if not found
215
# possibly not being used??
216
sub findDomain {
217
   my $domainName = shift;
218
   my @node = @_;
219
   my $foundNode = '';
220
   &readDB();
221
   unless ( @node ) {
222
      @node = keys %{$main::statusDB->{'node'} };
25 rodolico 223
      print "findDomain, nodes = " . join( "\t", @node ) . "\n" if $main::config->{'flags'}->{'debug'} > 1;
18 rodolico 224
   }
26 rodolico 225
   if ( $main::config->{'flags'}->{'paranoid'} ) { # we will scan all nodes just to make sure
226
      foreach my $thisNode ( @node ) {
227
         my $command = &main::makeCommand( $thisNode, 'virsh list' );
47 rodolico 228
         my $output = &main::execute($command);
26 rodolico 229
         print "findDomain, $thisNode list =\n" . $output . "\n" if $main::config->{'flags'}->{'debug'} > 1;;
230
         return $thisNode if ( $output =~ m/$domainName/ );
231
      }
232
   } else { # not paranoid mode, so just look through the status file
233
      foreach my $thisNode ( @node ) {
234
         if ( $main::statusDB->{'nodePopulation'}->{$thisNode}->{'running'}->{$domainName} ) {
235
            return $thisNode;
236
         }
237
      }
18 rodolico 238
   }
239
   return '';
240
}
15 rodolico 241
 
242
# check one or more nodes and determine which domains are running on them.
243
# defaults to everything in the node database, but the -t can have it run on only one
244
# this is the function that should be run every few minutes on one of the servers
245
sub scan {
25 rodolico 246
   my @targets = @_;
26 rodolico 247
   if ( -f $main::config->{'last scan filename'} && ! $main::config->{'flags'}->{'force'} ) {
25 rodolico 248
      my $lastScan = time - ( stat( $main::config->{'last scan filename'} ) ) [9];
26 rodolico 249
      return "Scan was run $lastScan seconds ago\n" unless $lastScan > $main::config->{'min scan time'};
15 rodolico 250
   }
47 rodolico 251
   &main::execute("touch $main::config->{'last scan filename'}");
15 rodolico 252
   &main::readDB(1);
25 rodolico 253
   print Dumper( $main::statusDB->{'nodePopulation'} ) if $main::config->{'flags'}->{'debug'} > 2;
254
   if ( $main::config->{'flags'}->{'target'} ) {
255
      push @targets, $main::config->{'flags'}->{'target'};
15 rodolico 256
   }
25 rodolico 257
   @targets = keys %{$main::statusDB->{'node'}} unless @targets;
258
   print "Scanning " . join( "\n", @targets ) . "\n" if $main::config->{'flags'}->{'debug'};
15 rodolico 259
   foreach my $node (@targets) {
26 rodolico 260
      print "Scanning $node\n" if $main::config->{'flags'}->{'verbose'};
15 rodolico 261
      $main::statusDB->{'nodePopulation'}->{$node}->{'running'} = &getDomainsOnNode( $node );
262
      $main::statusDB->{'nodePopulation'}->{$node}->{'lastchecked'} = time;
29 rodolico 263
      print "Found " . (keys %{$main::statusDB->{'nodePopulation'}->{$node}->{'running'}}) . " domains on node $node\n" if $main::config->{'flags'}->{'verbose'};
15 rodolico 264
      foreach my $domain ( keys %{$main::statusDB->{'nodePopulation'}->{$node}->{'running'}} ) {
265
         # make sure there is an entry for all of these domains
266
         $main::statusDB->{'virt'}->{$domain} = {} unless exists( $main::statusDB->{'virt'}->{$domain} );
267
      }
25 rodolico 268
      print Dumper( $main::statusDB->{'nodePopulation'}->{$node} ) if $main::config->{'flags'}->{'debug'} > 2;
15 rodolico 269
   }
270
   &main::writeDB();
271
   return "Node(s) updated\n";
272
}
273
 
18 rodolico 274
# makes the command that will be run on a node
275
# Created as a sub so we can change format easily
25 rodolico 276
# if node is the node we're on, we don't need to do a remote call
277
# if node is null, we'll assume we do the command here
278
# otherwise, we'll do an ssh to the node and run the command there
15 rodolico 279
sub makeCommand {
280
   my ( $node, $command ) = @_;
47 rodolico 281
   my $me = &execute('hostname');
25 rodolico 282
   chomp $me;
283
   if ( ! $node || $node eq $me ) {
284
      return $command;
285
   } else {
286
      return "ssh $node '$command'";
287
   }
15 rodolico 288
}
289
 
47 rodolico 290
# executes a shell command and returns the output
291
# centralizes all command execution for easier debugging and modification
292
# usage: execute($command) or @output = execute($command)
293
sub execute {
294
   my $command = shift;
295
   print "havirt.pm:execute running: [$command]\n" if $main::config->{'flags'}->{'debug'} > 2;
296
   return `$command`;
297
}
298
 
38 rodolico 299
# force a node scan, of all domains, even if time has not expired
300
# and/or target is set. do this by setting force to 1 and target to null
301
# then calling scan,
302
# after run, reset it to old value
15 rodolico 303
sub forceScan {
38 rodolico 304
   my $force = $main::config->{'flags'}->{'force'};
305
   my $target = $main::config->{'flags'}->{'target'};
306
   $main::config->{'flags'}->{'force'} = 1;
307
   $main::config->{'flags'}->{'target'} = '';
15 rodolico 308
   &main::scan();
38 rodolico 309
   $main::config->{'flags'}->{'force'} = $force;
310
   $main::config->{'flags'}->{'target'} = $target;
15 rodolico 311
}
312
 
313
 
314
# executes command $command, then repeatedly runs virsh list
315
# on $scanNode, grep'ing for $scanDomain
26 rodolico 316
# $condition is 1, to wait for domain to start
317
# or 0 (false) to wait for it to shut down
15 rodolico 318
sub executeAndWait {
47 rodolico 319
   my ( $command, $scanNode, $scanDomain, $condition, $timeOut, $pollEvery ) = @_;
320
   $pollEvery = 15 unless defined $pollEvery; # number of seconds to wait before checking again
321
   $timeOut = 60 unless defined $timeOut; # maximum number of tries
322
   $timeOut = int( $timeOut / $pollEvery ) unless $timeOut > $pollEvery;
323
   print "Running [$command], then waiting $pollEvery seconds to check if complete\n" if $main::config->{'flags'}->{'debug'};
324
   &main::execute($command);
15 rodolico 325
   my $waitCommand = &makeCommand( $scanNode, "virsh list | grep $scanDomain" );
326
   my $output = '';
327
   do {
47 rodolico 328
      return 0 unless ( $timeOut-- ); # we've waited too long, so probably not working
15 rodolico 329
      print '. ';
47 rodolico 330
      sleep $pollEvery;
331
      $output = &main::execute($waitCommand);
25 rodolico 332
      print "[$waitCommand] returned [$output]\n" if $main::config->{'flags'}->{'debug'} > 1;
15 rodolico 333
   } until ( $condition ? $output : !$output );
334
   return 1; # made it successful
335
} 
336
 
18 rodolico 337
# find the differences between two arrays (passed by reference)
338
# first sorts the array, then walks through them one by one
339
# @$arr1 MUST be larger than @$arr2
26 rodolico 340
# used by domain.pm:list to find non-running domains for output
47 rodolico 341
# returns elements in arr1 that are not in arr2
18 rodolico 342
sub diffArray {
343
   my ( $arr1, $arr2 ) = @_;
344
   my @result;
345
 
346
   @$arr1 = sort @$arr1;
347
   @$arr2 = sort @$arr2;
348
   my $i=0;
349
   my $j=0;
350
 
47 rodolico 351
   while ( $i < @$arr1 ) {
352
      if ( $j < @$arr2 && $arr1->[$i] eq $arr2->[$j] ) {
353
         # Match found, skip both
18 rodolico 354
         $i++;
355
         $j++;
47 rodolico 356
      } elsif ( $j >= @$arr2 || $arr1->[$i] lt $arr2->[$j] ) {
357
         # arr1[i] not in arr2, or arr2 exhausted
18 rodolico 358
         push @result, $arr1->[$i];
359
         $i++;
360
      } else {
47 rodolico 361
         # arr1[i] > arr2[j], advance j to keep looking for match
18 rodolico 362
         $j++;
363
      }
364
   }
365
   return \@result;
366
}
25 rodolico 367
 
368
 
369
# create a config file if one does not exist
370
sub makeConfig {
371
   my ( $config, $filename ) = @_;
372
   $config->{'script dir'} = $FindBin::RealBin;
373
   $config->{'script name'} = $FindBin::Script;
374
   $config->{'db dir'} = $config->{'script dir'} . '/var';
375
   $config->{'conf dir'} = $config->{'script dir'} . '/conf';
376
   $config->{'status db filename'} = $config->{'db dir'} . '/status.yaml';
377
   $config->{'last scan filename'} = $config->{'script dir'} . '/var/lastscan';
26 rodolico 378
   $config->{'min scan time'} = 5 * 60; # five minutes
25 rodolico 379
   $config->{'node reserved memory'} = 8 * 1024 * 1024; # 8 gigabytes
380
   $config->{'node reserved vcpu' } = 0; # turn off reserved vcpu
26 rodolico 381
   $config->{'paranoid'} = 1; # rescan all nodes on any action which will modify it
382
   $config->{'flags'}->{'debug'} = 0;
383
   $config->{'flags'}->{'dryrun'} = 1;
384
   $config->{'flags'}->{'force'} = 0;
25 rodolico 385
   $config->{'flags'}->{'format'} = 'screen';
26 rodolico 386
   #$config->{'flags'}->{'help'} = 0; # used, but don't put in config file
25 rodolico 387
   $config->{'flags'}->{'quiet'} = 0;
388
   $config->{'flags'}->{'target'} = '';
26 rodolico 389
   $config->{'flags'}->{'verbose'} = 1;
390
   #$config->{'flags'}->{'version'} = 0; # used, but don't put in config file
25 rodolico 391
   my $yaml = YAML::Tiny->new( $config );
392
   $yaml->write( $filename );
393
}
394
 
395
# read the config file and return it
396
sub readConfig {
397
   my $filename = shift;
398
   my $yaml = YAML::Tiny->new( {} );
399
   if ( -f $filename ) {
400
      $yaml = YAML::Tiny->read( $filename );
401
   }
402
   return $yaml->[0];
403
}
404
 
26 rodolico 405
# find available resource on a node, total RAM and threads
25 rodolico 406
sub resource {
407
   my $node = shift;
408
   die "Can not find node $node in havirt.pm:resource\n"
409
      unless $main::statusDB->{'node'}->{$node};
410
   my $return = {
411
      'memory' => 0,
412
      'cpu_count' => 0
413
      };
414
   foreach my $key ( keys %$return ) {
415
      $return->{$key} = $main::statusDB->{'node'}->{$node}->{$key}
416
         if defined $main::statusDB->{'node'}->{$node}->{$key};
417
   } # foreach
418
   return $return;
419
}
420
 
26 rodolico 421
# determine resources used on a node, total RAM and VCPU
25 rodolico 422
sub getAvailableResources {
423
   my $node = shift;
424
   &readDB();
26 rodolico 425
   die "Can not find node $node in havirt.pm:resource\n" unless $main::statusDB->{'node'}->{$node};
25 rodolico 426
   my $totalResources = &resource( $node );
427
   print Dumper( $totalResources ) if $main::config->{'flags'}->{'debug'};
428
   foreach my $domain ( keys %{ $main::statusDB->{'nodePopulation'}->{$node}->{'running'} } ) {
429
      $totalResources->{'memory'} -= $main::statusDB->{'virt'}->{$domain}->{'memory'};
430
      $totalResources->{'cpu_count'} -= $main::statusDB->{'virt'}->{$domain}->{'vcpu'};
431
   }
432
   return $totalResources;
433
}
434
 
435
# validate that node has enough resources for the domains which occupy the
436
# remainder of the stack
437
# returns 0 on success, or one or more error messages in a string on failure
438
sub validateResources {
439
   my $node = shift;
440
   &readDB();
441
   my @return;
442
   my $nodeResources = &getAvailableResources( $node );
443
   print "In havirt.pm:validateResources, checking if enough room on $node for\n" . join( "\n", @_ ) . "\n"
26 rodolico 444
      if $main::config->{'flags'}->{'debug'};
445
   print "Checking resources on $node\n" if $main::config->{'flags'}->{'verbose'};
25 rodolico 446
   # subtract the reserved memory from the node
447
   $nodeResources->{'memory'} -= $main::config->{'node reserved memory'};
448
   $nodeResources->{'cpu_count'} -= $main::config->{'node reserved vcpu'} if $main::config->{'node reserved vcpu'};
449
   while ( my $domain = shift ) {
450
      $nodeResources->{'memory'} -= $main::statusDB->{'virt'}->{$domain}->{'memory'};
451
      $nodeResources->{'cpu_count'} -= $main::statusDB->{'virt'}->{$domain}->{'vcpu'};
452
   }
453
   print "In havirt.pm:validateResources, $node will have $nodeResources->{memory} memory and $nodeResources->{cpu_count} vcpu's after task\n"
454
      if ( $main::config->{'flags'}->{'debug'} > 1 );
455
 
456
   push @return, "This action would result in memory of $nodeResources->{memory}" if $nodeResources->{'memory'} <= 0;
457
   push @return, "This action would result in virtual cpu count of $nodeResources->{cpu_count}" if $nodeResources->{'cpu_count'} <= 0 && $main::config->{'flags'}->{'node reserved vcpu'};
458
   return @return ? join( "\n", @return ) . "\n" : 0;
459
}
460
 
461
# migrate domain from current node it is on to $target
462
sub migrate {
42 rodolico 463
   my ( $virt, $target, $node ) = @_;
25 rodolico 464
   my $return;
42 rodolico 465
   $node  = &main::findDomain( $virt ) unless $node;
25 rodolico 466
   print Dumper( $main::statusDB->{'nodePopulation'} ) if $main::config->{'flags'}->{'debug'} > 2;
467
   die "I can not find $virt on any node\n" unless $node;
468
   die "Domain $virt in maintenance mode, can not migrate it\n" if $main::statusDB->{'virt'}->{$virt}->{'maintenance'};
469
   die "Node $target in maintenance mode, can not migrate anything to it\n" if $main::statusDB->{'node'}->{$target}->{'maintenance'};
470
   die "$virt already on $target\n" if $target eq $node;
471
   my $command = &main::makeCommand( $node, "virsh migrate --live --persistent --verbose  $virt qemu+ssh://$target/system" );
26 rodolico 472
   if ( $main::config->{'flags'}->{'dryrun'} ) { # they want us to actually do it
473
      $return = $command;
474
   } else {
38 rodolico 475
      print "Migrating $virt to $node\n" if $main::config->{'flags'}->{'verbose'};
47 rodolico 476
      $return = ( &main::executeAndWait( $command, $node, $virt, 0, 60, 15 ) ? 'Success' : 'Time Out waiting for shutdown');
38 rodolico 477
      #&main::forceScan(); Removed since we're doing it at a higher level
25 rodolico 478
   }
479
   return "$return\n";
480
}
481