File Coverage

blib/lib/Rex/Virtualization/CBSD/pause.pm
Criterion Covered Total %
statement 15 30 50.0
branch 0 10 0.0
condition 0 6 0.0
subroutine 5 6 83.3
pod 0 1 0.0
total 20 53 37.7


line stmt bran cond sub pod time code
1             #
2             # (c) Zane C. Bowers-Hadley
3             #
4              
5             package Rex::Virtualization::CBSD::pause;
6              
7 1     1   69519 use strict;
  1         13  
  1         31  
8 1     1   6 use warnings;
  1         2  
  1         64  
9              
10             our $VERSION = '0.0.1'; # VERSION
11              
12 1     1   447 use Rex::Logger;
  1         10792  
  1         40  
13 1     1   426 use Rex::Helper::Run;
  1         78834  
  1         76  
14 1     1   8 use Term::ANSIColor qw(colorstrip);
  1         3  
  1         1146  
15              
16             sub execute {
17 0     0 0   my ( $class, $name, $mode ) = @_;
18              
19             # make sure we have a jname to pass
20 0 0         if ( !defined($name) ) {
21 0           die('No VM name defined');
22             }
23              
24             # set the mode to auto if none is set
25 0 0         if ( !defined($mode) ) {
26 0           $mode = 'auto';
27             }
28              
29             # make sure mode is something valid
30 0 0 0       if ( ( $mode eq 'auto' )
      0        
31             || ( $mode eq 'on' )
32             || ( $mode eq 'off' ) )
33             {
34 0           die "Mode specified is something other than 'auto', 'on', or 'off'.";
35             }
36              
37 0           Rex::Logger::debug( "CBSD VM start via cbsd brebstart " . $name );
38              
39             # run it
40 0           my $returned = i_run( 'cbsd bpause ' . $name . ' mode=' . $mode, fail_ok => 1 );
41              
42             # the output is colorized
43 0           $returned = colorstrip($returned);
44              
45             # check for failures caused by it not existing
46 0 0         if ( $returned =~ /^No\ such/ ) {
47 0           die( '"' . $name . '" does not exist' );
48             }
49 0 0         if ( $? != 0 ) {
50 0           die( "Error running 'cbsd brestart " . $name . "'" );
51             }
52              
53 0           return 1;
54             }
55              
56             1;