File Coverage

blib/lib/Rex/Virtualization/CBSD/brestart.pm
Criterion Covered Total %
statement 15 26 57.6
branch 0 6 0.0
condition n/a
subroutine 5 6 83.3
pod 0 1 0.0
total 20 39 51.2


line stmt bran cond sub pod time code
1             #
2             # (c) Zane C. Bowers-Hadley
3             #
4              
5             package Rex::Virtualization::CBSD::brestart;
6              
7 1     1   70044 use strict;
  1         14  
  1         38  
8 1     1   8 use warnings;
  1         3  
  1         58  
9              
10             our $VERSION = '0.0.1'; # VERSION
11              
12 1     1   498 use Rex::Logger;
  1         10866  
  1         38  
13 1     1   413 use Rex::Helper::Run;
  1         80641  
  1         75  
14 1     1   9 use Term::ANSIColor qw(colorstrip);
  1         2  
  1         2059  
15              
16             sub execute {
17 0     0 0   my ( $class, $name, %opt ) = @_;
18              
19 0 0         if ( !defined($name) ) {
20 0           die('No VM name defined');
21             }
22              
23 0           Rex::Logger::debug( "CBSD VM start via cbsd brebstart " . $name );
24              
25 0           my $returned = i_run( 'cbsd brestart ' . $name, fail_ok => 1 );
26              
27             # the output is colorized
28 0           $returned = colorstrip($returned);
29              
30             # check for failures caused by it not existing
31 0 0         if ( $returned =~ /^No\ such/ ) {
32 0           die( '"' . $name . '" does not exist' );
33             }
34 0 0         if ( $? != 0 ) {
35 0           die( "Error running 'cbsd brestart " . $name . "'" );
36             }
37              
38 0           return 1;
39             }
40              
41             1;