File Coverage

lib/Rex/Inventory/HP/ACU.pm
Criterion Covered Total %
statement 11 122 9.0
branch 0 56 0.0
condition 0 15 0.0
subroutine 4 9 44.4
pod 0 5 0.0
total 15 207 7.2


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4              
5             package Rex::Inventory::HP::ACU;
6              
7 1     1   15 use v5.12.5;
  1         4  
8 1     1   5 use warnings;
  1         2  
  1         41  
9              
10             our $VERSION = '1.14.2.3'; # TRIAL VERSION
11              
12 1     1   7 use Rex::Commands::Run;
  1         4  
  1         6  
13 1     1   8 use Rex::Helper::Run;
  1         2  
  1         1268  
14              
15             sub get {
16              
17 0 0   0 0   if ( can_run("hpacucli") ) {
18 0           my @lines = i_run "/usr/sbin/hpacucli controller all show config detail",
19             fail_ok => 1;
20 0           my $ret = parse_config(@lines);
21 0           return $ret;
22             }
23             else {
24 0           return 0;
25             }
26              
27             }
28              
29             #
30             # The bellow code is from Parse::HP::ACU
31             #
32             # Copyright 2010 Jeremy Cole.
33             #
34             # This program is free software; you can redistribute it and/or modify it
35             # under the terms of either: the GNU General Public License as published
36             # by the Free Software Foundation; or the Artistic License.
37             #
38             # See http://dev.perl.org/licenses/ for more information.
39             #
40             sub parse_config {
41 0     0 0   my (@lines) = @_;
42              
43 0           my $controller = {};
44 0           my $current_controller = 0;
45 0           my $current_array = undef;
46 0           my $current_logical_drive = undef;
47 0           my $current_mirror_group = undef;
48 0           my $current_physical_drive = undef;
49              
50 0           LINE: for my $line (@lines) {
51 0           chomp $line;
52              
53 0 0         next if ( $line =~ /^$/ );
54              
55 0 0         if ( $line !~ /^[ ]+/ ) {
56 0           $current_controller = $current_controller + 1;
57 0           $current_array = undef;
58 0           $current_logical_drive = undef;
59 0           $current_mirror_group = undef;
60 0           $current_physical_drive = undef;
61 0           $controller->{$current_controller} = {};
62 0           $controller->{$current_controller}->{'description'} = $line;
63 0           next;
64             }
65              
66 0 0         next if ( !defined($current_controller) );
67              
68 0           $line =~ s/^\s+//g;
69 0           $line =~ s/\s+$//g;
70 0           $line =~ s/[ ]+/ /g;
71              
72 0 0         if ( $line =~ /unassigned/ ) {
73 0           $current_array = "unassigned";
74 0           $current_logical_drive = undef;
75 0           $current_mirror_group = undef;
76 0           $current_physical_drive = undef;
77 0           $controller->{$current_controller}->{'unassigned'} = {};
78 0           $controller->{$current_controller}->{'unassigned'}->{'physical_drive'} =
79             {};
80 0           next;
81             }
82              
83 0 0         if ( $line =~ /Array: ([A-Z]+)/ ) {
84 0           $current_array = $1;
85 0           $current_logical_drive = undef;
86 0           $current_mirror_group = undef;
87 0           $current_physical_drive = undef;
88 0           $controller->{$current_controller}->{'array'}->{$current_array} = {};
89             $controller->{$current_controller}->{'array'}->{$current_array}
90 0           ->{'logical_drive'} = {};
91             $controller->{$current_controller}->{'array'}->{$current_array}
92 0           ->{'physical_drive'} = {};
93 0           next;
94             }
95              
96 0 0         if ( $line =~ /Logical Drive: ([0-9]+)/ ) {
97 0           $current_logical_drive = $1;
98 0           $current_physical_drive = undef;
99 0           $current_mirror_group = undef;
100             $controller->{$current_controller}->{'array'}->{$current_array}
101 0           ->{'logical_drive'}->{$current_logical_drive} = {};
102             $controller->{$current_controller}->{'array'}->{$current_array}
103 0           ->{'logical_drive'}->{$current_logical_drive}->{'mirror_group'} = {};
104 0           next;
105             }
106              
107 0 0 0       if ( $line =~ /physicaldrive ([0-9IC:]+)/ and $line !~ /port/ ) {
108 0           $current_logical_drive = undef;
109 0           $current_physical_drive = $1;
110 0           $current_mirror_group = undef;
111 0 0         if ( $current_array eq 'unassigned' ) {
112             $controller->{$current_controller}->{'unassigned'}->{'physical_drive'}
113 0           ->{$current_physical_drive} = {};
114             }
115             else {
116             $controller->{$current_controller}->{'array'}->{$current_array}
117 0           ->{'physical_drive'}->{$current_physical_drive} = {};
118             }
119 0           next;
120             }
121              
122 0 0         if ( $line =~ /Mirror Group ([0-9]+):/ ) {
123 0           $current_mirror_group = $1;
124             $controller->{$current_controller}->{'array'}->{$current_array}
125             ->{'logical_drive'}->{$current_logical_drive}->{'mirror_group'}
126 0           ->{$current_mirror_group} = [];
127 0           next;
128             }
129              
130 0 0 0       if ( defined($current_array)
      0        
131             and defined($current_logical_drive)
132             and defined($current_mirror_group) )
133             {
134 0 0         if ( $line =~ /physicaldrive ([0-9IC:]+) \(/ ) {
135             my $current_mirror_group_list =
136             $controller->{$current_controller}->{'array'}->{$current_array}
137             ->{'logical_drive'}->{$current_logical_drive}->{'mirror_group'}
138 0           ->{$current_mirror_group};
139              
140 0           foreach my $pd ( @{$current_mirror_group_list} ) {
  0            
141 0 0         next LINE if ( $pd eq $1 );
142             }
143 0           push @{$current_mirror_group_list}, $1;
  0            
144             }
145 0           next;
146             }
147              
148 0 0 0       if ( defined($current_array)
149             and defined($current_logical_drive) )
150             {
151 0 0         if ( my ( $k, $v ) = &K_V($line) ) {
152 0 0         next unless defined($k);
153             $controller->{$current_controller}->{'array'}->{$current_array}
154 0           ->{'logical_drive'}->{$current_logical_drive}->{$k} = $v;
155             }
156 0           next;
157             }
158              
159 0 0 0       if ( defined($current_array)
160             and defined($current_physical_drive) )
161             {
162 0 0         if ( my ( $k, $v ) = &K_V($line) ) {
163 0 0         next unless defined($k);
164 0 0         if ( $current_array eq 'unassigned' ) {
165             $controller->{$current_controller}->{'unassigned'}
166 0           ->{'physical_drive'}->{$current_physical_drive}->{$k} = $v;
167             }
168             else {
169             $controller->{$current_controller}->{'array'}->{$current_array}
170 0           ->{'physical_drive'}->{$current_physical_drive}->{$k} = $v;
171             }
172             }
173 0           next;
174             }
175              
176 0 0         if ( defined($current_array) ) {
177 0 0         if ( my ( $k, $v ) = &K_V($line) ) {
178 0 0         next unless defined($k);
179 0           $controller->{$current_controller}->{'array'}->{$current_array}->{$k} =
180             $v;
181             }
182 0           next;
183             }
184              
185 0 0         if ( my ( $k, $v ) = &K_V($line) ) {
186 0 0         next unless defined($k);
187 0           $controller->{$current_controller}->{$k} = $v;
188             }
189 0           next;
190             }
191              
192 0           return $controller;
193             }
194              
195             sub K {
196 0     0 0   my ($k) = @_;
197              
198 0           $k = lc $k;
199 0           $k =~ s/[ \/\-]/_/g;
200 0           $k =~ s/[\(\)]//g;
201              
202 0           return $k;
203             }
204              
205             sub V {
206 0     0 0   my ( $k, $v ) = @_;
207              
208 0 0         if ( $k eq 'accelerator_ratio' ) {
209 0 0         if ( $v =~ /([0-9]+)% Read \/ ([0-9]+)% Write/ ) {
210 0           return { 'read' => $1, 'write' => $2 };
211             }
212             }
213              
214 0           return $v;
215             }
216              
217             sub K_V {
218 0     0 0   my ($line) = @_;
219              
220 0 0         if ( $line =~ /(.+):\s+(.+)/ ) {
221 0           my $k = &K($1);
222 0           my $v = &V( $k, $2 );
223 0           return ( $k, $v );
224             }
225              
226 0           return ( undef, undef );
227             }
228              
229             1;