| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# (c) Zane C. Bowers-Hadley |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Virtualization::CBSD::bcheckpoint_create; |
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
68050
|
use strict; |
|
|
1
|
|
|
|
|
11
|
|
|
|
1
|
|
|
|
|
30
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
39
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.0.1'; # VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
446
|
use Rex::Logger; |
|
|
1
|
|
|
|
|
10592
|
|
|
|
1
|
|
|
|
|
38
|
|
|
13
|
1
|
|
|
1
|
|
418
|
use Rex::Helper::Run; |
|
|
1
|
|
|
|
|
76957
|
|
|
|
1
|
|
|
|
|
75
|
|
|
14
|
1
|
|
|
1
|
|
9
|
use Term::ANSIColor qw(colorstrip); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
2086
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub execute { |
|
17
|
0
|
|
|
0
|
0
|
|
my ( $class, %opts ) = @_; |
|
18
|
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
|
if ( !defined( $opts{vm} ) ) { |
|
20
|
0
|
|
|
|
|
|
die 'The required variable "vm" is not set'; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# set the defaults |
|
24
|
0
|
0
|
|
|
|
|
if ( !defined( $opts{suspend} ) ) { |
|
25
|
0
|
|
|
|
|
|
$opts{suspend} = 0; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
0
|
0
|
|
|
|
|
if ( !defined( $opts{name} ) ) { |
|
28
|
0
|
|
|
|
|
|
$opts{name} = 'checkpoint'; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# make sure all the keys are sane |
|
32
|
0
|
0
|
0
|
|
|
|
if ( ( $opts{vm} =~ /[\t\ \=\\\/\'\"\n\;\&]/ ) |
|
33
|
|
|
|
|
|
|
|| ( $opts{name} =~ /[\t\ \=\\\/\'\"\n\;\&]/ ) ) |
|
34
|
|
|
|
|
|
|
{ |
|
35
|
|
|
|
|
|
|
die 'The value either for "vm", "' |
|
36
|
|
|
|
|
|
|
. $opts{vm} |
|
37
|
|
|
|
|
|
|
. '" or "name", "' |
|
38
|
|
|
|
|
|
|
. $opts{name} |
|
39
|
0
|
|
|
|
|
|
. '", matched /[\t\ \=\/\\\'\"\n\;\&]/, meaning it is not a valid value'; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
0
|
0
|
|
|
|
|
if ( $opts{suspend} =~ /^[01]$/ ) { |
|
42
|
|
|
|
|
|
|
die 'The value for "suspend", "' |
|
43
|
|
|
|
|
|
|
. $opts{suspend} |
|
44
|
0
|
|
|
|
|
|
. '", matched /[\t\'\"\n\;\&]/, meaning it is not a valid value'; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# put together the command |
|
48
|
|
|
|
|
|
|
my $command |
|
49
|
0
|
|
|
|
|
|
= 'cbsd bcheckpoint mode=create jname=' . $opts{vm} . " name='" . $opts{name} . "' suspend=" . $opts{suspend}; |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
Rex::Logger::debug( "Checking a CBSD VM via... " . $command ); |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $returned = i_run( $command, fail_ok => 1 ); |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# the output is colorized, if there is an error |
|
56
|
0
|
|
|
|
|
|
$returned = colorstrip($returned); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# check for this second as no VM will also exit non-zero |
|
59
|
0
|
0
|
|
|
|
|
if ( $? != 0 ) { |
|
60
|
0
|
|
|
|
|
|
die( "Error running '" . $command . "'" ); |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return 1; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |