File Coverage

blib/lib/Rex/Virtualization/CBSD/remove.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::remove;
6              
7 1     1   70072 use strict;
  1         13  
  1         32  
8 1     1   13 use warnings;
  1         4  
  1         91  
9              
10             our $VERSION = '0.0.1'; # VERSION
11              
12 1     1   459 use Rex::Logger;
  1         10846  
  1         43  
13 1     1   457 use Rex::Helper::Run;
  1         79148  
  1         75  
14 1     1   9 use Term::ANSIColor qw(colorstrip);
  1         2  
  1         2307  
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;