File: LVM.pm

package info (click to toggle)
fusioninventory-agent 1%3A2.3.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 19,636 kB
  • ctags: 1,451
  • sloc: perl: 89,223; xml: 422; sh: 83; python: 26; makefile: 22
file content (125 lines) | stat: -rw-r--r-- 3,131 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package FusionInventory::Agent::Task::Inventory::Linux::LVM;

use strict;
use warnings;

use English qw(-no_match_vars);

use FusionInventory::Agent::Tools;

sub isEnabled {
    canRun('lvs');
}

sub doInventory {
    my (%params) = @_;

    my $inventory = $params{inventory};
    my $logger    = $params{logger};

    foreach my $volume (_getLogicalVolumes(logger => $logger)) {
        $inventory->addEntry(section => 'LOGICAL_VOLUMES', entry => $volume);
    }

    foreach my $volume (_getPhysicalVolumes(logger => $logger)) {
        $inventory->addEntry(section => 'PHYSICAL_VOLUMES', entry => $volume);
    }

    foreach my $group (_getVolumeGroups(logger => $logger)) {
        $inventory->addEntry(section => 'VOLUME_GROUPS', entry => $group);
    }
}

sub _getLogicalVolumes {
    my (%params) = (
        command => 'lvs -a --noheading --nosuffix --units M -o lv_name,vg_uuid,lv_attr,lv_size,lv_uuid,seg_count',
        @_
    );

    my $handle = getFileHandle(%params);
    return unless $handle;

    my @volumes;
    while (my $line = <$handle>) {
        my @infos = split(/\s+/, $line);

        push @volumes, {
            LV_NAME   => $infos[1],
            VG_UUID   => $infos[2],
            ATTR      => $infos[3],
            SIZE      => int($infos[4]||0),
            LV_UUID   => $infos[5],
            SEG_COUNT => $infos[6],
        }

    }
    close $handle;

    return @volumes;
}

sub _getPhysicalVolumes {
    my (%params) = (
        command => 'pvs --noheading --nosuffix --units M -o pv_name,pv_fmt,pv_attr,pv_size,pv_free,pv_uuid,pv_pe_count,vg_uuid',
        @_
    );

    my $handle = getFileHandle(%params);
    return unless $handle;

    my @volumes;
    while (my $line = <$handle>) {
        my @infos = split(/\s+/, $line);

        my $pe_size;
        if ($infos[7] && $infos[7]>0) {
            $pe_size = int($infos[4] / $infos[7]);
        }

        push @volumes, {
            DEVICE      => $infos[1],
            FORMAT      => $infos[2],
            ATTR        => $infos[3],
            SIZE        => int($infos[4]||0),
            FREE        => int($infos[5]||0),
            PV_UUID     => $infos[6],
            PV_PE_COUNT => $infos[7],
            PE_SIZE     => $pe_size,
            VG_UUID     => $infos[8]
        };
    }
    close $handle;

    return @volumes;
}

sub _getVolumeGroups {
    my (%params) = (
        command => 'vgs --noheading --nosuffix --units M -o vg_name,pv_count,lv_count,vg_attr,vg_size,vg_free,vg_uuid,vg_extent_size',
        @_
    );

    my $handle = getFileHandle(%params);
    return unless $handle;

    my @groups;
    while (my $line = <$handle>) {
        my @infos = split(/\s+/, $line);

        push @groups, {
            VG_NAME        => $infos[1],
            PV_COUNT       => $infos[2],
            LV_COUNT       => $infos[3],
            ATTR           => $infos[4],
            SIZE           => int($infos[5]||0),
            FREE           => int($infos[6]||0),
            VG_UUID        => $infos[7],
            VG_EXTENT_SIZE => $infos[8],
        };
    }
    close $handle;

    return @groups;
}

1;