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