File Coverage

lib/Rex/Virtualization/LibVirt/iflist.pm
Criterion Covered Total %
statement 14 30 46.6
branch 0 4 0.0
condition n/a
subroutine 5 6 83.3
pod 0 1 0.0
total 19 41 46.3


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4              
5             package Rex::Virtualization::LibVirt::iflist;
6              
7 1     1   14 use v5.12.5;
  1         3  
8 1     1   14 use warnings;
  1         12  
  1         48  
9              
10             our $VERSION = '1.14.3'; # VERSION
11              
12 1     1   8 use Rex::Logger;
  1         2  
  1         6  
13              
14 1     1   39 use Data::Dumper;
  1         3  
  1         58  
15 1     1   9 use Rex::Virtualization::LibVirt::dumpxml;
  1         7  
  1         7  
16              
17             sub execute {
18 0     0 0   shift;
19 0           my $vmname = shift;
20 0           my %options = @_;
21              
22 0 0         unless ($vmname) {
23 0           die("You have to define the vm name!");
24             }
25              
26 0           my $ref = Rex::Virtualization::LibVirt::dumpxml->execute($vmname);
27              
28 0           my $interfaces = $ref->{devices}->{interface};
29 0 0         if ( ref $interfaces ne "ARRAY" ) {
30 0           $interfaces = [$interfaces];
31             }
32              
33 0           my %ret = ();
34 0           my $iface_num = 0;
35 0           for my $iface ( @{$interfaces} ) {
  0            
36             $ret{"vnet$iface_num"} = {
37             type => $iface->{model}->{type},
38             source => $iface->{source}->{network},
39             model => $iface->{model}->{type},
40             mac => $iface->{mac}->{address},
41 0           };
42              
43 0           $iface_num++;
44             }
45              
46 0           return \%ret;
47              
48             }
49              
50             1;