lib/Rex/Virtualization/LibVirt/blklist.pm

filter: Statementstmt 36.3% 16 / 44 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 31.8% 21 / 66 CC 11 SCAR 45.1
CC
11
Cov
28%
execute
132.0
BEGIN
1.0
BEGIN
1.0
CRAP 91.1
« lib/Rex/Virtualization/LibVirt/create.pm ↑ Summary lib/Rex/PkgConf/Debian.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Virtualization::LibVirt::blklist;
6  
7 1 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '1.16.1'; # VERSION
11  
12 1 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 0 ▶sub execute {
Subroutine execute: not called CC=11 SCAR=48.8
Pod undocumented
18 0 shift;
19 0 my $vmname = shift;
20 0 my %options = @_;
21 0 my $virt_settings = Rex::Config->get("virtualization");
22 chomp( my $uri =
23 0 ▶ ref($virt_settings) ? $virt_settings->{connect} : i_run "virsh uri" );
Branch: 1 branch
BranchTrueFalseTotal
ref $virt_settings ? : 0 0 0
24  
25 0 ▶ unless ($vmname) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($vmname) 0 0 0
26 0 die("You have to define the vm name!");
27 }
28  
29 0 Rex::Logger::debug("Getting block list of domain: $vmname");
30  
31 0 my @blklist = i_run "virsh -c $uri domblklist '$vmname' --details",
32 fail_ok => 1;
33  
34 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
35 0 die("Error running virsh domblklist '$vmname'");
36 }
37  
38 0 my %ret = ();
39 0 my ( $k, $v );
40  
41 0 shift @blklist;
42 0 shift @blklist;
43 0 for my $line (@blklist) {
44 0 my ( $type, $device, $target, $source ) = split( /\s+/, $line );
45 0 $ret{$target} = {
46 type => $type,
47 device => $device,
48 source => $source
49 };
50 }
51  
52 0 ▶ if (%options) {
Branch: 1 branch
BranchTrueFalseTotal
if (%options) 0 0 0
53 0 ▶ if ( $options{details} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"details"}) 0 0 0
54 0 ▶ my $unit = $options{unit} || 1;
Condition0%0/2
$options{'unit'} || 1
l!l
00
MC/DC0%0/1
$options{'unit'} || 1
$options{'unit'}
Truth table0%0/2
A
A= $options{'unit'}
Aresult
11
00
55 0 for my $target ( keys %ret ) {
56 0 my @infos =
57 i_run "virsh -c $uri domblkinfo '$vmname' '$target' 2>/dev/null",
58 fail_ok => 1;
59 0 ▶ if ( $? == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? == 0) 0 0 0
60 0 for my $line (@infos) {
61 0 my ( $k, $v ) = split( /:\s+/, $line );
62 0 $ret{$target}->{$k} = $v / $unit;
63 }
64 }
65 }
66 }
67 }
68  
69 0 return \%ret;
70 }
71  
72 1 1;
« lib/Rex/Virtualization/LibVirt/create.pm ↑ Summary lib/Rex/PkgConf/Debian.pm »