line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Linux::LVM; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
36961851
|
use strict; |
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
117
|
|
4
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
99
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use English qw(-no_match_vars); |
|
1
|
|
|
|
|
51
|
|
|
1
|
|
|
|
|
26
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1511
|
use FusionInventory::Agent::Tools; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
829
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub isEnabled { |
11
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
12
|
0
|
0
|
|
|
|
|
return 0 if $params{no_category}->{lvm}; |
13
|
0
|
|
|
|
|
|
return canRun('lvs'); |
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 (_getLogicalVolumes(logger => $logger)) { |
23
|
0
|
|
|
|
|
|
$inventory->addEntry(section => 'LOGICAL_VOLUMES', entry => $volume); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
foreach my $volume (_getPhysicalVolumes(logger => $logger)) { |
27
|
0
|
|
|
|
|
|
$inventory->addEntry(section => 'PHYSICAL_VOLUMES', entry => $volume); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
foreach my $group (_getVolumeGroups(logger => $logger)) { |
31
|
0
|
|
|
|
|
|
$inventory->addEntry(section => 'VOLUME_GROUPS', entry => $group); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _getLogicalVolumes { |
36
|
0
|
|
|
0
|
|
|
my (%params) = ( |
37
|
|
|
|
|
|
|
command => 'lvs -a --noheading --nosuffix --units M -o lv_name,vg_uuid,lv_attr,lv_size,lv_uuid,seg_count', |
38
|
|
|
|
|
|
|
@_ |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $handle = getFileHandle(%params); |
42
|
0
|
0
|
|
|
|
|
return unless $handle; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my @volumes; |
45
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
46
|
0
|
|
|
|
|
|
my @infos = split(/\s+/, $line); |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
0
|
|
|
|
push @volumes, { |
49
|
|
|
|
|
|
|
LV_NAME => $infos[1], |
50
|
|
|
|
|
|
|
VG_UUID => $infos[2], |
51
|
|
|
|
|
|
|
ATTR => $infos[3], |
52
|
|
|
|
|
|
|
SIZE => int($infos[4]||0), |
53
|
|
|
|
|
|
|
LV_UUID => $infos[5], |
54
|
|
|
|
|
|
|
SEG_COUNT => $infos[6], |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
|
close $handle; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return @volumes; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _getPhysicalVolumes { |
64
|
0
|
|
|
0
|
|
|
my (%params) = ( |
65
|
|
|
|
|
|
|
command => 'pvs --noheading --nosuffix --units M -o pv_name,pv_fmt,pv_attr,pv_size,pv_free,pv_uuid,pv_pe_count,vg_uuid', |
66
|
|
|
|
|
|
|
@_ |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $handle = getFileHandle(%params); |
70
|
0
|
0
|
|
|
|
|
return unless $handle; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my @volumes; |
73
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
74
|
0
|
|
|
|
|
|
my @infos = split(/\s+/, $line); |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $pe_size; |
77
|
0
|
0
|
0
|
|
|
|
if ($infos[7] && $infos[7]>0) { |
78
|
0
|
|
|
|
|
|
$pe_size = int($infos[4] / $infos[7]); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
0
|
|
|
|
push @volumes, { |
|
|
|
0
|
|
|
|
|
82
|
|
|
|
|
|
|
DEVICE => $infos[1], |
83
|
|
|
|
|
|
|
FORMAT => $infos[2], |
84
|
|
|
|
|
|
|
ATTR => $infos[3], |
85
|
|
|
|
|
|
|
SIZE => int($infos[4]||0), |
86
|
|
|
|
|
|
|
FREE => int($infos[5]||0), |
87
|
|
|
|
|
|
|
PV_UUID => $infos[6], |
88
|
|
|
|
|
|
|
PV_PE_COUNT => $infos[7], |
89
|
|
|
|
|
|
|
PE_SIZE => $pe_size, |
90
|
|
|
|
|
|
|
VG_UUID => $infos[8] |
91
|
|
|
|
|
|
|
}; |
92
|
|
|
|
|
|
|
} |
93
|
0
|
|
|
|
|
|
close $handle; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return @volumes; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub _getVolumeGroups { |
99
|
0
|
|
|
0
|
|
|
my (%params) = ( |
100
|
|
|
|
|
|
|
command => 'vgs --noheading --nosuffix --units M -o vg_name,pv_count,lv_count,vg_attr,vg_size,vg_free,vg_uuid,vg_extent_size', |
101
|
|
|
|
|
|
|
@_ |
102
|
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
my $handle = getFileHandle(%params); |
105
|
0
|
0
|
|
|
|
|
return unless $handle; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
my @groups; |
108
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
109
|
0
|
|
|
|
|
|
my @infos = split(/\s+/, $line); |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
0
|
|
|
|
push @groups, { |
|
|
|
0
|
|
|
|
|
112
|
|
|
|
|
|
|
VG_NAME => $infos[1], |
113
|
|
|
|
|
|
|
PV_COUNT => $infos[2], |
114
|
|
|
|
|
|
|
LV_COUNT => $infos[3], |
115
|
|
|
|
|
|
|
ATTR => $infos[4], |
116
|
|
|
|
|
|
|
SIZE => int($infos[5]||0), |
117
|
|
|
|
|
|
|
FREE => int($infos[6]||0), |
118
|
|
|
|
|
|
|
VG_UUID => $infos[7], |
119
|
|
|
|
|
|
|
VG_EXTENT_SIZE => $infos[8], |
120
|
|
|
|
|
|
|
}; |
121
|
|
|
|
|
|
|
} |
122
|
0
|
|
|
|
|
|
close $handle; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
return @groups; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |