File Coverage

lib/Rex/Hardware/Network.pm
Criterion Covered Total %
statement 41 48 85.4
branch 5 10 50.0
condition n/a
subroutine 11 14 78.5
pod 0 4 0.0
total 57 76 75.0


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4              
5             package Rex::Hardware::Network;
6              
7 37     37   503 use v5.12.5;
  37         164  
8 37     36   230 use warnings;
  36         90  
  36         1478  
9              
10             our $VERSION = '1.14.3'; # VERSION
11              
12 36     36   368 use Data::Dumper;
  36         83  
  36         1952  
13              
14 36     36   224 use Rex::Commands::Gather;
  36         93  
  36         460  
15 36     36   1181 use Rex::Logger;
  36         102  
  36         192  
16              
17             require Rex::Hardware;
18              
19             sub get {
20              
21 9     9 0 104 my $cache = Rex::get_cache();
22 9         104 my $cache_key_name = $cache->gen_key_name("hardware.network");
23              
24 9 50       111 if ( $cache->valid($cache_key_name) ) {
25 0         0 return $cache->get($cache_key_name);
26             }
27              
28 9         98 my $hw_class = _get_class();
29 9 50       69 unless ($hw_class) {
30 0         0 return {};
31             }
32              
33 9         170 my $data = {
34              
35             networkdevices => $hw_class->get_network_devices(),
36             networkconfiguration => $hw_class->get_network_configuration(),
37              
38             };
39              
40 9         172 $cache->set( $cache_key_name, $data );
41              
42 9         281 return $data;
43              
44             }
45              
46             sub route {
47 0     0 0 0 return _get_class()->route();
48             }
49              
50             sub default_gateway {
51 0     0 0 0 return _get_class()->default_gateway(@_);
52             }
53              
54             sub netstat {
55 0     0 0 0 return _get_class()->netstat();
56             }
57              
58             sub _get_class {
59 9     9   89 my $os_type = Rex::Commands::Gather::get_operating_system();
60              
61 9 50       148 $os_type = "Linux" if Rex::Commands::Gather::is_linux();
62 9 50       115 $os_type = "Solaris" if Rex::Commands::Gather::is_solaris();
63              
64 9         132 my $hw_class = "Rex::Hardware::Network::$os_type";
65 9     2   1069 eval "use $hw_class;";
  2     2   60  
  2     2   18  
  2     2   35  
  2         35  
  2         20  
  2         51  
  2         37  
  2         25  
  2         64  
  2         39  
  2         24  
  2         66  
66              
67 9 50       200 if ($@) {
68 0         0 Rex::Logger::debug("No network information on $os_type");
69 0         0 return;
70             }
71              
72 9         154 return $hw_class;
73             }
74              
75             1;