• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

RexOps / Rex / 12855852081

19 Jan 2025 05:52PM UTC coverage: 50.631% (-0.03%) from 50.659%
12855852081

push

github

ferki
WIP: fix quoting on Windows

2 of 2 new or added lines in 1 file covered. (100.0%)

9 existing lines in 2 files now uncovered.

9950 of 19652 relevant lines covered (50.63%)

99.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.0
/lib/Rex/Hardware.pm
1
#
2
# (c) Jan Gehring <jan.gehring@gmail.com>
3
#
4

5
=head1 NAME
6

7
Rex::Hardware - Base Class for hardware / information gathering
8

9
=head1 DESCRIPTION
10

11
This module is the base class for hardware/information gathering.
12

13
=head1 SYNOPSIS
14

15
 use Rex::Hardware;
16

17
 my %host_info = Rex::Hardware->get(qw/ Host /);
18
 my %all_info  = Rex::Hardware->get(qw/ All /);
19

20
=head1 CLASS METHODS
21

22
=cut
23

24
package Rex::Hardware;
25

26
use v5.12.5;
79✔
27
use warnings;
79✔
28

29
our $VERSION = '9999.99.99_99'; # VERSION
30

31
use Rex::Logger;
79✔
32

33
require Rex::Args;
34

35
=head2 get(@modules)
36

37
Returns a hash with the wanted information.
38

39
 task "get-info", "server1", sub {
40
   %hw_info = Rex::Hardware->get(qw/ Host Network /);
41
 };
42

43
Or if you want to get all information
44

45
 task "get-all-info", "server1", sub {
46
   %hw_info = Rex::Hardware->get(qw/ All /);
47
 };
48

49
Available modules:
50

51
=over 4
52

53
=item Host
54

55
=item Kernel
56

57
=item Memory
58

59
=item Network
60

61
=item Swap
62

63
=item VirtInfo
64

65
=back
66

67
=cut
68

69
my %HW_PROVIDER;
70

71
sub register_hardware_provider {
72
  my ( $class, $service_name, $service_class ) = @_;
2✔
73
  $HW_PROVIDER{"\L$service_name"} = $service_class;
2✔
74
  return 1;
2✔
75
}
76

77
sub get {
78
  my ( $class, @modules ) = @_;
37✔
79

80
  my %hardware_information;
37✔
81

82
  if ( "all" eq "\L$modules[0]" ) {
37✔
83

84
    @modules = qw(Host Kernel Memory Network Swap VirtInfo);
11✔
85
    push( @modules, keys(%HW_PROVIDER) );
11✔
86

87
  }
88

89
  for my $mod_string (@modules) {
37✔
90

91
    Rex::Commands::profiler()->start("hardware: $mod_string");
82✔
92

93
    my $mod = "Rex::Hardware::$mod_string";
81✔
94
    if ( exists $HW_PROVIDER{$mod_string} ) {
81✔
UNCOV
95
      $mod = $HW_PROVIDER{$mod_string};
×
96
    }
97

98
    Rex::Logger::debug("Loading $mod");
80✔
99
    eval "use $mod";
80✔
100

101
    if ($@) {
84✔
102
      Rex::Logger::info("$mod not found.");
4✔
103
      Rex::Logger::debug("$@");
4✔
UNCOV
104
      next;
×
105
    }
106

107
    $hardware_information{$mod_string} = $mod->get();
80✔
108

109
    Rex::Commands::profiler()->end("hardware: $mod_string");
84✔
110

111
  }
112

113
  return %hardware_information;
39✔
114
}
115

116
1;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc