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