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   13 use v5.12.5;
  1         4  
8 1     1   5 use warnings;
  1         2  
  1         40  
9              
10             our $VERSION = '1.14.2.2'; # TRIAL VERSION
11              
12 1     1   6 use Rex::Logger;
  1         2  
  1         5  
13              
14 1     1   20 use Data::Dumper;
  1         2  
  1         39  
15 1     1   27 use Rex::Virtualization::LibVirt::dumpxml;
  1         2  
  1         8  
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;