line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Virtualization::Qemu; |
2
|
|
|
|
|
|
|
# With Qemu 0.10.X, some option will be added to get more and easly information (UUID, memory, ...) |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
38799337
|
use strict; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
101
|
|
5
|
1
|
|
|
1
|
|
20
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
84
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
399
|
use FusionInventory::Agent::Tools; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
220
|
|
8
|
1
|
|
|
1
|
|
605
|
use FusionInventory::Agent::Tools::Unix; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
513
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub isEnabled { |
11
|
|
|
|
|
|
|
# Avoid duplicated entry with libvirt |
12
|
0
|
0
|
|
0
|
0
|
|
return if canRun('virsh'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
return |
15
|
0
|
|
0
|
|
|
|
canRun('qemu') || |
16
|
|
|
|
|
|
|
canRun('kvm') || |
17
|
|
|
|
|
|
|
canRun('qemu-kvm'); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _parseProcessList { |
21
|
0
|
|
|
0
|
|
|
my ($process) = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my $values = {}; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
my @options = split (/ -/, $process->{CMD}); |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
foreach my $option (@options) { |
29
|
0
|
0
|
|
|
|
|
if ($option =~ m/^(?:[fhsv]d[a-d]|cdrom) (\S+)/) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
$values->{name} = $1 if !$values->{name}; |
31
|
|
|
|
|
|
|
} elsif ($option =~ m/^name (\S+)/) { |
32
|
0
|
|
|
|
|
|
$values->{name} = $1; |
33
|
|
|
|
|
|
|
} elsif ($option =~ m/^m (\S+)/) { |
34
|
0
|
|
|
|
|
|
$values->{mem} = $1; |
35
|
|
|
|
|
|
|
} elsif ($option =~ m/^uuid (\S+)/) { |
36
|
0
|
|
|
|
|
|
$values->{uuid} = $1; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
if ($option =~ /smbios/) { |
40
|
0
|
0
|
|
|
|
|
if ($option =~ m/smbios.*uuid=([a-zA-Z0-9-]+)/) { |
41
|
0
|
|
|
|
|
|
$values->{uuid} = $1; |
42
|
|
|
|
|
|
|
} |
43
|
0
|
0
|
|
|
|
|
if ($option =~ m/smbios.*serial=([a-zA-Z0-9-]+)/) { |
44
|
0
|
|
|
|
|
|
$values->{serial} = $1; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if ($values->{mem} == 0 ) { |
50
|
|
|
|
|
|
|
# Default value |
51
|
0
|
|
|
|
|
|
$values->{mem} = 128; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
return $values; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub doInventory { |
58
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $inventory = $params{inventory}; |
61
|
0
|
|
|
|
|
|
my $logger = $params{logger}; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
foreach my $process (getProcesses(logger => $logger)) { |
64
|
|
|
|
|
|
|
# match only if an qemu instance |
65
|
0
|
0
|
|
|
|
|
next if $process->{CMD} =~ /^\[/; |
66
|
0
|
0
|
|
|
|
|
next if $process->{CMD} !~ /(qemu|kvm|qemu-kvm|qemu-system\S+) .*\S/x; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
my $values = _parseProcessList($process); |
69
|
0
|
0
|
|
|
|
|
next unless $values; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$inventory->addEntry( |
72
|
|
|
|
|
|
|
section => 'VIRTUALMACHINES', |
73
|
|
|
|
|
|
|
entry => { |
74
|
|
|
|
|
|
|
NAME => $values->{name}, |
75
|
|
|
|
|
|
|
UUID => $values->{uuid}, |
76
|
|
|
|
|
|
|
VCPU => 1, |
77
|
|
|
|
|
|
|
MEMORY => $values->{mem}, |
78
|
|
|
|
|
|
|
STATUS => "running", |
79
|
|
|
|
|
|
|
SUBSYSTEM => $values->{vmtype}, |
80
|
|
|
|
|
|
|
VMTYPE => $values->{vmtype}, |
81
|
|
|
|
|
|
|
SERIAL => $values->{serial}, |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |