line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Virtualization::Virtuozzo; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
41361106
|
use strict; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
70
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
67
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
423
|
use FusionInventory::Agent::Tools; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
167
|
|
7
|
1
|
|
|
1
|
|
439
|
use FusionInventory::Agent::Tools::Network; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
572
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub isEnabled { |
10
|
|
|
|
|
|
|
# Avoid duplicated entry with libvirt |
11
|
0
|
0
|
|
0
|
0
|
|
return if canRun('virsh'); |
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
|
return canRun('vzlist'); |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub getMACs { |
17
|
0
|
|
|
0
|
0
|
|
my ($ctid, $logger) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my @ipLines = getAllLines( |
20
|
|
|
|
|
|
|
command => "vzctl exec '$ctid' 'ip -0 a'", |
21
|
|
|
|
|
|
|
logger => $logger |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my @macs; |
25
|
0
|
|
|
|
|
|
foreach my $line (@ipLines) { |
26
|
0
|
0
|
|
|
|
|
next unless $line =~ /^\s+link\/ether ($mac_address_pattern)\s/; |
27
|
0
|
|
|
|
|
|
push @macs, $1; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
return join('/', @macs); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub doInventory { |
34
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $inventory = $params{inventory}; |
37
|
0
|
|
|
|
|
|
my $logger = $params{logger}; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $handle = getFileHandle( |
40
|
|
|
|
|
|
|
command => 'vzlist --all --no-header -o hostname,ctid,cpulimit,status,ostemplate', |
41
|
|
|
|
|
|
|
logger => $logger |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
return unless $handle; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# no service containers in glpi |
47
|
0
|
|
|
|
|
|
my $line = <$handle>; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
chomp $line; |
52
|
0
|
|
|
|
|
|
my ($name, $ctid, $cpus, $status, $subsys) = split(/[ \t]+/, $line); |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $memory = getFirstMatch( |
55
|
|
|
|
|
|
|
file => "/etc/vz/conf/$ctid.conf", |
56
|
|
|
|
|
|
|
pattern => qr/^SLMMEMORYLIMIT="\d+:(\d+)"$/, |
57
|
|
|
|
|
|
|
logger => $logger, |
58
|
|
|
|
|
|
|
); |
59
|
0
|
0
|
|
|
|
|
if ($memory) { |
60
|
0
|
|
|
|
|
|
$memory = $memory / 1024 / 1024; |
61
|
|
|
|
|
|
|
} else { |
62
|
0
|
|
|
|
|
|
$memory = getFirstMatch( |
63
|
|
|
|
|
|
|
file => "/etc/vz/conf/$ctid.conf", |
64
|
|
|
|
|
|
|
pattern => qr/^PRIVVMPAGES="\d+:(\d+)"$/, |
65
|
|
|
|
|
|
|
logger => $logger, |
66
|
|
|
|
|
|
|
); |
67
|
0
|
0
|
|
|
|
|
if ($memory) { |
68
|
0
|
|
|
|
|
|
$memory = $memory * 4 / 1024; |
69
|
|
|
|
|
|
|
} else { |
70
|
0
|
|
|
|
|
|
$memory = getFirstMatch( |
71
|
|
|
|
|
|
|
file => "/etc/vz/conf/$ctid.conf", |
72
|
|
|
|
|
|
|
pattern => qr/^PHYSPAGES="\d+:(\d+\w{0,1})"$/, |
73
|
|
|
|
|
|
|
logger => $logger, |
74
|
|
|
|
|
|
|
); |
75
|
0
|
0
|
|
|
|
|
if ($memory) { |
76
|
0
|
|
|
|
|
|
$memory =~ /:(\d+)(\w{0,1})/; |
77
|
0
|
0
|
|
|
|
|
if ($2 eq "M") { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
$memory=$1; |
79
|
|
|
|
|
|
|
} elsif ($2 eq "G") { |
80
|
0
|
|
|
|
|
|
$memory=$1*1024; |
81
|
|
|
|
|
|
|
} elsif ($2 eq "K") { |
82
|
0
|
|
|
|
|
|
$memory=$1/1024; |
83
|
|
|
|
|
|
|
} else { |
84
|
0
|
|
|
|
|
|
$memory=$1/1024/1024; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$inventory->addEntry( |
91
|
|
|
|
|
|
|
section => 'VIRTUALMACHINES', |
92
|
|
|
|
|
|
|
entry => { |
93
|
|
|
|
|
|
|
NAME => $name, |
94
|
|
|
|
|
|
|
VCPU => $cpus, |
95
|
|
|
|
|
|
|
UUID => $ctid, |
96
|
|
|
|
|
|
|
MEMORY => $memory, |
97
|
|
|
|
|
|
|
STATUS => $status, |
98
|
|
|
|
|
|
|
SUBSYSTEM => $subsys, |
99
|
|
|
|
|
|
|
VMTYPE => "Virtuozzo", |
100
|
|
|
|
|
|
|
MAC => getMACs($ctid, $logger) |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
close $handle; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |