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