File Coverage

blib/lib/Rex/Virtualization/CBSD/info.pm
Criterion Covered Total %
statement 15 31 48.3
branch 0 6 0.0
condition n/a
subroutine 5 6 83.3
pod 0 1 0.0
total 20 44 45.4


line stmt bran cond sub pod time code
1             #
2             # (c) Zane C. Bowers-Hadley
3             #
4              
5             package Rex::Virtualization::CBSD::info;
6              
7 1     1   75326 use strict;
  1         15  
  1         34  
8 1     1   6 use warnings;
  1         2  
  1         59  
9              
10             our $VERSION = '0.0.1'; # VERSION
11              
12 1     1   545 use Rex::Logger;
  1         11531  
  1         74  
13 1     1   700 use Rex::Helper::Run;
  1         85718  
  1         79  
14 1     1   12 use Term::ANSIColor qw(colorstrip);
  1         3  
  1         1281  
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 info via cbsd bget jname=" . $name );
24              
25             #
26 0           my $returned = i_run( 'cbsd bget jname=' . $name, fail_ok => 1 );
27              
28             # the output is colorized, if there is an error
29 0           $returned = colorstrip($returned);
30 0 0         if ( $returned =~ /^No\ such/ ) {
31 0           die( '"' . $name . '" does not exist' );
32             }
33              
34             # check for this second as no VM will also exit non-zero
35 0 0         if ( $? != 0 ) {
36 0           die( "Error running 'cbsd bget jname=" . $name . "'" );
37             }
38              
39 0           my %info;
40 0           my @lines = split( /\n/, $returned );
41 0           foreach my $line (@lines) {
42 0           my ( $vname, $vval ) = split( /\:\ /, $line );
43 0           $info{$vname} = $vval;
44             }
45              
46 0           return \%info;
47             }
48              
49             1;