line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Virtualization::Xen; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
40610352
|
use strict; |
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
111
|
|
4
|
1
|
|
|
1
|
|
10
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
95
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
598
|
use FusionInventory::Agent::Tools; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
437
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $runMeIfTheseChecksFailed = ["FusionInventory::Agent::Task::Inventory::Virtualization::Libvirt"]; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub isEnabled { |
11
|
0
|
|
|
0
|
0
|
|
return canRun('xm'); |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub doInventory { |
15
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
my $inventory = $params{inventory}; |
18
|
0
|
|
|
|
|
|
my $logger = $params{logger}; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my $command = 'xm list'; |
21
|
0
|
|
|
|
|
|
foreach my $machine (_getVirtualMachines(command => $command, logger => $logger)) { |
22
|
0
|
|
|
|
|
|
my $uuid = _getUUID( |
23
|
|
|
|
|
|
|
command => "xm list -l $machine->{NAME}", |
24
|
|
|
|
|
|
|
logger => $logger |
25
|
|
|
|
|
|
|
); |
26
|
0
|
|
|
|
|
|
$machine->{UUID} = $uuid; |
27
|
0
|
|
|
|
|
|
$inventory->addEntry( |
28
|
|
|
|
|
|
|
section => 'VIRTUALMACHINES', entry => $machine |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _getUUID { |
34
|
0
|
|
|
0
|
|
|
my (%params) = @_; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
return getFirstMatch( |
37
|
|
|
|
|
|
|
pattern => qr/\( uuid \s ([^)]+) \)/x, |
38
|
|
|
|
|
|
|
%params |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _getVirtualMachines { |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
0
|
|
|
my $handle = getFileHandle(@_); |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
return unless $handle; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# xm status |
49
|
0
|
|
|
|
|
|
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
|
0
|
|
|
|
|
|
my $line = <$handle>; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my @machines; |
62
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
63
|
0
|
|
|
|
|
|
chomp $line; |
64
|
0
|
|
|
|
|
|
my ($name, $vmid, $memory, $vcpu, $status) = split(' ', $line); |
65
|
0
|
0
|
|
|
|
|
next if $name eq 'Domain-0'; |
66
|
0
|
0
|
|
|
|
|
next if $vmid == 0; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$status =~ s/-//g; |
69
|
0
|
0
|
|
|
|
|
$status = $status ? $status_list{$status} : 'off'; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $machine = { |
72
|
|
|
|
|
|
|
MEMORY => $memory, |
73
|
|
|
|
|
|
|
NAME => $name, |
74
|
|
|
|
|
|
|
STATUS => $status, |
75
|
|
|
|
|
|
|
SUBSYSTEM => 'xm', |
76
|
|
|
|
|
|
|
VMTYPE => 'xen', |
77
|
|
|
|
|
|
|
VCPU => $vcpu, |
78
|
|
|
|
|
|
|
VMID => $vmid, |
79
|
|
|
|
|
|
|
}; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
push @machines, $machine; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
0
|
|
|
|
|
|
close $handle; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
return @machines; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |