line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::AIX::LVM; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
79595275
|
use FusionInventory::Agent::Tools; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
128
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
6
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3
|
use English qw(-no_match_vars); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub isEnabled { |
11
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
12
|
0
|
0
|
|
|
|
|
return 0 if $params{no_category}->{lvm}; |
13
|
0
|
|
|
|
|
|
return canRun('lspv'); |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub doInventory { |
17
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $inventory = $params{inventory}; |
20
|
0
|
|
|
|
|
|
my $logger = $params{logger}; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
foreach my $volume (_getPhysicalVolumes($logger)) { |
23
|
0
|
|
|
|
|
|
$inventory->addEntry(section => 'PHYSICAL_VOLUMES', entry => $volume); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
foreach my $group (_getVolumeGroups($logger)) { |
27
|
0
|
|
|
|
|
|
$inventory->addEntry(section => 'VOLUME_GROUPS', entry => $group); |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
foreach my $volume (_getLogicalVolumes($logger, $group->{VG_NAME})) { |
30
|
0
|
|
|
|
|
|
$inventory->addEntry(section => 'LOGICAL_VOLUMES', entry => $volume); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _getLogicalVolumes { |
36
|
0
|
|
|
0
|
|
|
my ($logger, $group) = @_; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $handle = getFileHandle( |
39
|
|
|
|
|
|
|
command => "lsvg -l $group", |
40
|
|
|
|
|
|
|
logger => $logger |
41
|
|
|
|
|
|
|
); |
42
|
0
|
0
|
|
|
|
|
return unless $handle; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# skip headers |
45
|
0
|
|
|
|
|
|
my $line; |
46
|
0
|
|
|
|
|
|
$line = <$handle>; |
47
|
0
|
|
|
|
|
|
$line = <$handle>; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# no logical volume if there is only one line of output |
50
|
0
|
0
|
|
|
|
|
return unless $line; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my @volumes; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
55
|
0
|
|
|
|
|
|
chomp $line; |
56
|
0
|
|
|
|
|
|
my ($name) = split(/\s+/, $line); |
57
|
0
|
|
|
|
|
|
push @volumes, _getLogicalVolume(logger => $logger, name => $name); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
close $handle; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return @volumes; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _getLogicalVolume { |
66
|
0
|
|
|
0
|
|
|
my (%params) = @_; |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
my $command = $params{name} ? "lslv $params{name}" : undef; |
69
|
0
|
|
|
|
|
|
my $handle = getFileHandle(command => $command, %params); |
70
|
0
|
0
|
|
|
|
|
return unless $handle; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my $volume = { |
73
|
|
|
|
|
|
|
LV_NAME => $params{name} |
74
|
|
|
|
|
|
|
}; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $size; |
77
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
78
|
0
|
0
|
|
|
|
|
if ($line =~ /PP SIZE:\s+(\d+)/) { |
79
|
0
|
|
|
|
|
|
$size = $1; |
80
|
|
|
|
|
|
|
} |
81
|
0
|
0
|
|
|
|
|
if ($line =~ /^LV IDENTIFIER:\s+(\S+)/) { |
82
|
0
|
|
|
|
|
|
$volume->{LV_UUID} = $1; |
83
|
|
|
|
|
|
|
} |
84
|
0
|
0
|
|
|
|
|
if ($line =~ /^LPs:\s+(\S+)/) { |
85
|
0
|
|
|
|
|
|
$volume->{SEG_COUNT} = $1; |
86
|
|
|
|
|
|
|
} |
87
|
0
|
0
|
|
|
|
|
if ($line =~ /^TYPE:\s+(\S+)/) { |
88
|
0
|
|
|
|
|
|
$volume->{ATTR} = "Type $1", |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
0
|
|
|
|
|
|
close $handle; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
$volume->{SIZE} = $volume->{SEG_COUNT} * $size; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return $volume; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub _getPhysicalVolumes { |
99
|
0
|
|
|
0
|
|
|
my ($logger) = @_; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $handle = getFileHandle( |
102
|
|
|
|
|
|
|
command => 'lspv', |
103
|
|
|
|
|
|
|
logger => $logger |
104
|
|
|
|
|
|
|
); |
105
|
0
|
0
|
|
|
|
|
return unless $handle; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
my @volumes; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
110
|
0
|
|
|
|
|
|
chomp $line; |
111
|
0
|
|
|
|
|
|
my ($name) = split(/\s+/, $line); |
112
|
0
|
|
|
|
|
|
push @volumes, _getPhysicalVolume(logger => $logger, name => $name); |
113
|
|
|
|
|
|
|
} |
114
|
0
|
|
|
|
|
|
close $handle; |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
return @volumes; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _getPhysicalVolume { |
120
|
0
|
|
|
0
|
|
|
my (%params) = @_; |
121
|
|
|
|
|
|
|
|
122
|
0
|
0
|
|
|
|
|
my $command = $params{name} ? "lspv $params{name}" : undef; |
123
|
0
|
|
|
|
|
|
my $handle = getFileHandle(command => $command, %params); |
124
|
0
|
0
|
|
|
|
|
return unless $handle; |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my $volume = { |
127
|
|
|
|
|
|
|
DEVICE => "/dev/$params{name}" |
128
|
|
|
|
|
|
|
}; |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
my ($free, $total); |
131
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
132
|
0
|
|
|
|
|
|
chomp $line; |
133
|
|
|
|
|
|
|
|
134
|
0
|
0
|
|
|
|
|
if ($line =~ /PHYSICAL VOLUME:\s+(\S+)/) { |
135
|
0
|
|
|
|
|
|
$volume->{FORMAT} = "AIX PV"; |
136
|
|
|
|
|
|
|
} |
137
|
0
|
0
|
|
|
|
|
if ($line =~ /FREE PPs:\s+(\d+)/) { |
138
|
0
|
|
|
|
|
|
$free = $1; |
139
|
|
|
|
|
|
|
} |
140
|
0
|
0
|
|
|
|
|
if ($line =~ /TOTAL PPs:\s+(\d+)/) { |
141
|
0
|
|
|
|
|
|
$total = $1; |
142
|
|
|
|
|
|
|
} |
143
|
0
|
0
|
|
|
|
|
if ($line =~ /VOLUME GROUP:\s+(\S+)/) { |
144
|
0
|
|
|
|
|
|
$volume->{ATTR} = "VG $1"; |
145
|
|
|
|
|
|
|
} |
146
|
0
|
0
|
|
|
|
|
if ($line =~ /PP SIZE:\s+(\d+)/) { |
147
|
0
|
|
|
|
|
|
$volume->{PE_SIZE} = $1; |
148
|
|
|
|
|
|
|
} |
149
|
0
|
0
|
|
|
|
|
if ($line =~ /PV IDENTIFIER:\s+(\S+)/) { |
150
|
0
|
|
|
|
|
|
$volume->{PV_UUID} = $1; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
0
|
|
|
|
|
|
close $handle; |
154
|
|
|
|
|
|
|
|
155
|
0
|
0
|
|
|
|
|
if (defined $volume->{PE_SIZE}) { |
156
|
0
|
0
|
|
|
|
|
$volume->{SIZE} = $total * $volume->{PE_SIZE} if defined $total; |
157
|
0
|
0
|
|
|
|
|
$volume->{FREE} = $free * $volume->{PE_SIZE} if defined $free; |
158
|
|
|
|
|
|
|
} |
159
|
0
|
0
|
|
|
|
|
$volume->{PV_PE_COUNT} = $total if defined $total; |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
return $volume; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub _getVolumeGroups { |
165
|
0
|
|
|
0
|
|
|
my ($logger) = @_; |
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
my $handle = getFileHandle( |
168
|
|
|
|
|
|
|
command => 'lsvg', |
169
|
|
|
|
|
|
|
logger => $logger |
170
|
|
|
|
|
|
|
); |
171
|
0
|
0
|
|
|
|
|
return unless $handle; |
172
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
my @groups; |
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
176
|
0
|
|
|
|
|
|
chomp $line; |
177
|
0
|
|
|
|
|
|
push @groups, _getVolumeGroup(logger => $logger, name => $line); |
178
|
|
|
|
|
|
|
} |
179
|
0
|
|
|
|
|
|
close $handle; |
180
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
|
return @groups; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub _getVolumeGroup { |
185
|
0
|
|
|
0
|
|
|
my (%params) = @_; |
186
|
|
|
|
|
|
|
|
187
|
0
|
0
|
|
|
|
|
my $command = $params{name} ? "lsvg $params{name}" : undef; |
188
|
0
|
|
|
|
|
|
my $handle = getFileHandle(command => $command, %params); |
189
|
0
|
0
|
|
|
|
|
return unless $handle; |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
my $group = { |
192
|
|
|
|
|
|
|
VG_NAME => $params{name} |
193
|
|
|
|
|
|
|
}; |
194
|
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
196
|
0
|
|
|
|
|
|
chomp $line; |
197
|
|
|
|
|
|
|
|
198
|
0
|
0
|
|
|
|
|
if ($line =~ /TOTAL PPs:\s+(\d+)/) { |
199
|
0
|
|
|
|
|
|
$group->{SIZE} = $1; |
200
|
|
|
|
|
|
|
} |
201
|
0
|
0
|
|
|
|
|
if ($line =~ /FREE PPs:\s+(\d+)/) { |
202
|
0
|
|
|
|
|
|
$group->{FREE} = $1; |
203
|
|
|
|
|
|
|
} |
204
|
0
|
0
|
|
|
|
|
if ($line =~ /VG IDENTIFIER:\s+(\S+)/) { |
205
|
0
|
|
|
|
|
|
$group->{VG_UUID} = $1; |
206
|
|
|
|
|
|
|
} |
207
|
0
|
0
|
|
|
|
|
if ($line =~ /PP SIZE:\s+(\d+)/) { |
208
|
0
|
|
|
|
|
|
$group->{VG_EXTENT_SIZE} = $1; |
209
|
|
|
|
|
|
|
} |
210
|
0
|
0
|
|
|
|
|
if ($line =~ /LVs:\s+(\d+)/) { |
211
|
0
|
|
|
|
|
|
$group->{LV_COUNT} = $1; |
212
|
|
|
|
|
|
|
} |
213
|
0
|
0
|
|
|
|
|
if ($line =~/ACTIVE PVs:\s+(\d+)/) { |
214
|
0
|
|
|
|
|
|
$group->{PV_COUNT} = $1; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
} |
218
|
0
|
|
|
|
|
|
close $handle; |
219
|
|
|
|
|
|
|
|
220
|
0
|
|
|
|
|
|
return $group; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
1; |