File Coverage

blib/lib/Rex/Virtualization/CBSD/bpci_list.pm
Criterion Covered Total %
statement 15 30 50.0
branch 0 4 0.0
condition n/a
subroutine 5 6 83.3
pod 0 1 0.0
total 20 41 48.7


line stmt bran cond sub pod time code
1             #
2             # (c) Zane C. Bowers-Hadley
3             #
4              
5             package Rex::Virtualization::CBSD::bpci_list;
6              
7 1     1   75238 use strict;
  1         14  
  1         33  
8 1     1   6 use warnings;
  1         11  
  1         72  
9              
10             our $VERSION = '0.0.1'; # VERSION
11              
12 1     1   467 use Rex::Logger;
  1         12136  
  1         71  
13 1     1   624 use Rex::Helper::Run;
  1         82479  
  1         74  
14 1     1   10 use Term::ANSIColor qw(colorstrip);
  1         2  
  1         2159  
15              
16             sub execute {
17 0     0 0   my ( $class, $vm ) = @_;
18              
19 0 0         if (!defined($vm)) {
20 0           die 'No VM specified';
21             }
22              
23 0           Rex::Logger::debug("Getting list of PCI devices for '".$vm."' in CBSD");
24              
25 0           my @pci;
26              
27             # header=0 is needed to avoid including code to exclude it
28             # if display= is changed, the parsing order needs updated
29 0           my $found=i_run ('cbsd bpcibus jname='.$vm.' mode=list header=0 display=pcislot_name,pcislot_bus,pcislot_pcislot,pcislot_function,pcislot_desc' , fail_ok => 1);
30 0 0         if ( $? != 0 ) {
31 0           die("Error running 'cbsd bpcibus jname=".$vm." mode=list header=0 display=pcislot_name,pcislot_bus,pcislot_pcislot,pcislot_function,pcislot_desc'");
32             }
33              
34             # remove it here so the data can be safely used else where
35 0           $found=colorstrip($found);
36              
37 0           my @found_lines=split(/\n/, $found);
38              
39 0           foreach my $line (@found_lines) {
40 0           my %device;
41             # needs to be updated if display= is ever changed
42 0           ( $device{'name'}, $device{'bus'}, $device{'slot'}, $device{'function'}, $device{'desc'} ) = split(/[\ \t]+/, $line);
43 0           push( @pci, \%device );
44             }
45              
46 0           return \@pci;
47             }
48              
49             1;