File Coverage

blib/lib/Rex/Virtualization/CBSD/bremove.pm
Criterion Covered Total %
statement 15 27 55.5
branch 0 6 0.0
condition n/a
subroutine 5 6 83.3
pod 0 1 0.0
total 20 40 50.0


line stmt bran cond sub pod time code
1             #
2             # (c) Zane C. Bowers-Hadley
3             #
4              
5             package Rex::Virtualization::CBSD::bremove;
6              
7 1     1   73052 use strict;
  1         15  
  1         37  
8 1     1   14 use warnings;
  1         4  
  1         61  
9              
10             our $VERSION = '0.0.1'; # VERSION
11              
12 1     1   516 use Rex::Logger;
  1         11224  
  1         39  
13 1     1   462 use Rex::Helper::Run;
  1         78789  
  1         71  
14 1     1   9 use Term::ANSIColor qw(colorstrip);
  1         2  
  1         2108  
15              
16             sub execute {
17 0     0 0   my ( $class, $name ) = @_;
18              
19 0 0         if ( !defined($name) ) {
20 0           die('No VM name defined');
21             }
22              
23 0           Rex::Logger::debug( "CBSD VM remove via cbsd bremove " . $name );
24              
25 0           my %VMs;
26              
27             # note
28 0           my $returned = i_run( 'cbsd bdestroy ' . $name, fail_ok => 1 );
29 0 0         if ( $? != 0 ) {
30 0           die( "Error running 'cbsd remove " . $name . "'" );
31             }
32              
33             # the output is colorized
34 0           $returned = colorstrip($returned);
35              
36             # as of CBSD 12.1.7, it won't exit non-zero for this, so check here
37 0 0         if ( $returned =~ /^No\ such/ ) {
38 0           die( '"' . $name . '" does not exist' );
39             }
40              
41 0           return 1;
42             }
43              
44             1;