line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Virtualization::Xen; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
53428017
|
use strict; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
236
|
|
4
|
2
|
|
|
2
|
|
16
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
157
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
1116
|
use FusionInventory::Agent::Tools; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1312
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $runMeIfTheseChecksFailed = ["FusionInventory::Agent::Task::Inventory::Virtualization::Libvirt"]; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub isEnabled { |
11
|
0
|
|
|
0
|
0
|
0
|
return canRun('xm'); |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub doInventory { |
15
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
0
|
my $inventory = $params{inventory}; |
18
|
0
|
|
|
|
|
0
|
my $logger = $params{logger}; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
0
|
my $command = 'xm list'; |
21
|
0
|
|
|
|
|
0
|
foreach my $machine (_getVirtualMachines(command => $command, logger => $logger)) { |
22
|
0
|
|
|
|
|
0
|
my $uuid = _getUUID( |
23
|
|
|
|
|
|
|
command => "xm list -l $machine->{NAME}", |
24
|
|
|
|
|
|
|
logger => $logger |
25
|
|
|
|
|
|
|
); |
26
|
0
|
|
|
|
|
0
|
$machine->{UUID} = $uuid; |
27
|
0
|
|
|
|
|
0
|
$inventory->addEntry( |
28
|
|
|
|
|
|
|
section => 'VIRTUALMACHINES', entry => $machine |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _getUUID { |
34
|
1
|
|
|
1
|
|
288
|
my (%params) = @_; |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
11
|
return getFirstMatch( |
37
|
|
|
|
|
|
|
pattern => qr/\( uuid \s ([^)]+) \)/x, |
38
|
|
|
|
|
|
|
%params |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _getVirtualMachines { |
43
|
|
|
|
|
|
|
|
44
|
2
|
|
|
2
|
|
337
|
my $handle = getFileHandle(@_); |
45
|
|
|
|
|
|
|
|
46
|
2
|
50
|
|
|
|
6
|
return unless $handle; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# xm status |
49
|
2
|
|
|
|
|
18
|
my %status_list = ( |
50
|
|
|
|
|
|
|
'r' => 'running', |
51
|
|
|
|
|
|
|
'b' => 'blocked', |
52
|
|
|
|
|
|
|
'p' => 'paused', |
53
|
|
|
|
|
|
|
's' => 'shutdown', |
54
|
|
|
|
|
|
|
'c' => 'crashed', |
55
|
|
|
|
|
|
|
'd' => 'dying', |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# drop headers |
59
|
2
|
|
|
|
|
40
|
my $line = <$handle>; |
60
|
|
|
|
|
|
|
|
61
|
2
|
|
|
|
|
3
|
my @machines; |
62
|
2
|
|
|
|
|
9
|
while (my $line = <$handle>) { |
63
|
56
|
|
|
|
|
69
|
chomp $line; |
64
|
56
|
|
|
|
|
63
|
my ($name, $vmid, $memory, $vcpu, $status); |
65
|
56
|
|
|
|
|
147
|
my @fields = split(' ', $line); |
66
|
56
|
100
|
|
|
|
112
|
if (@fields == 4) { |
67
|
40
|
|
|
|
|
59
|
($name, $memory, $vcpu) = @fields; |
68
|
40
|
|
|
|
|
53
|
$status = 'off'; |
69
|
|
|
|
|
|
|
} else { |
70
|
16
|
|
|
|
|
29
|
($name, $vmid, $memory, $vcpu, $status) = @fields; |
71
|
16
|
|
|
|
|
48
|
$status =~ s/-//g; |
72
|
16
|
100
|
|
|
|
37
|
$status = $status ? $status_list{$status} : 'off'; |
73
|
16
|
100
|
|
|
|
44
|
next if $vmid == 0; |
74
|
|
|
|
|
|
|
} |
75
|
54
|
50
|
|
|
|
109
|
next if $name eq 'Domain-0'; |
76
|
|
|
|
|
|
|
|
77
|
54
|
|
|
|
|
274
|
my $machine = { |
78
|
|
|
|
|
|
|
MEMORY => $memory, |
79
|
|
|
|
|
|
|
NAME => $name, |
80
|
|
|
|
|
|
|
STATUS => $status, |
81
|
|
|
|
|
|
|
SUBSYSTEM => 'xm', |
82
|
|
|
|
|
|
|
VMTYPE => 'xen', |
83
|
|
|
|
|
|
|
VCPU => $vcpu, |
84
|
|
|
|
|
|
|
}; |
85
|
|
|
|
|
|
|
|
86
|
54
|
|
|
|
|
213
|
push @machines, $machine; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
89
|
2
|
|
|
|
|
57
|
close $handle; |
90
|
|
|
|
|
|
|
|
91
|
2
|
|
|
|
|
20
|
return @machines; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |