File Coverage

blib/lib/Rex/Virtualization/CBSD/list.pm
Criterion Covered Total %
statement 15 28 53.5
branch 0 2 0.0
condition n/a
subroutine 5 6 83.3
pod 0 1 0.0
total 20 37 54.0


line stmt bran cond sub pod time code
1             #
2             # (c) Zane C. Bowers-Hadley
3             #
4              
5             package Rex::Virtualization::CBSD::list;
6              
7 1     1   72603 use strict;
  1         12  
  1         31  
8 1     1   5 use warnings;
  1         2  
  1         52  
9              
10             our $VERSION = '0.0.1'; # VERSION
11              
12 1     1   451 use Rex::Logger;
  1         10819  
  1         38  
13 1     1   421 use Rex::Helper::Run;
  1         80243  
  1         77  
14 1     1   9 use Term::ANSIColor qw(colorstrip);
  1         3  
  1         1164  
15              
16             sub execute {
17 0     0 0   my ($class) = @_;
18              
19 0           Rex::Logger::debug(
20             "Getting CBSD VM list via cbsd bls display=nodename,jname,jid,vm_ram,vm_curmem,vm_cpus,pcpu,vm_os_type,ip4_addr,status,vnc,path header=0"
21             );
22              
23 0           my %VMs;
24              
25             # header=0 is needed to avoid including code to exclude it
26             # if display= is changed, the parsing order needs updated
27 0           my $found = i_run(
28             'cbsd bls display=nodename,jname,jid,vm_ram,vm_curmem,vm_cpus,pcpu,vm_os_type,ip4_addr,status,vnc,path header=0',
29             fail_ok => 1
30             );
31 0 0         if ( $? != 0 ) {
32 0           die(
33             "Error running 'cbsd bls display=nodename,jname,jid,vm_ram,vm_curmem,vm_cpus,pcpu,vm_os_type,ip4_addr,status,vnc,path header=0'"
34             );
35             }
36              
37             # cbsd bls is colorized with no off mode for the color
38             # remove it here so the data can be safely used else where
39 0           $found = colorstrip($found);
40              
41 0           my @found_lines = split( /\n/, $found );
42              
43 0           foreach my $line (@found_lines) {
44 0           my %VM;
45              
46             # needs to be updated if display= is ever changed
47             (
48             $VM{'node'}, $VM{'name'}, $VM{'pid'}, $VM{'ram'}, $VM{'curmem'}, $VM{'cpus'},
49 0           $VM{'pcpu'}, $VM{'os'}, $VM{'ip4'}, $VM{'status'}, $VM{'vnc'}, $VM{'path'}
50             ) = split( /[\ \t]+/, $line );
51 0           $VMs{ $VM{'name'} } = \%VM;
52             }
53              
54 0           return %VMs;
55             }
56              
57             1;