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
|
2
|
|
|
2
|
|
44618574
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
61
|
|
5
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
70
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
732
|
use FusionInventory::Agent::Tools; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
355
|
|
8
|
2
|
|
|
2
|
|
963
|
use FusionInventory::Agent::Tools::Unix; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
873
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub isEnabled { |
11
|
|
|
|
|
|
|
# Avoid duplicated entry with libvirt |
12
|
0
|
0
|
|
0
|
0
|
0
|
return if canRun('virsh'); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
return |
15
|
0
|
|
0
|
|
|
0
|
canRun('qemu') || |
16
|
|
|
|
|
|
|
canRun('kvm') || |
17
|
|
|
|
|
|
|
canRun('qemu-kvm'); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _parseProcessList { |
21
|
3
|
|
|
3
|
|
8603
|
my ($process) = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
3
|
|
|
|
|
5
|
my $values = {}; |
25
|
|
|
|
|
|
|
|
26
|
3
|
|
|
|
|
14
|
my @options = split (/ -/, $process->{CMD}); |
27
|
|
|
|
|
|
|
|
28
|
3
|
|
|
|
|
4
|
foreach my $option (@options) { |
29
|
23
|
100
|
|
|
|
69
|
if ($option =~ m/^(?:[fhsv]d[a-d]|cdrom) (\S+)/) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
30
|
2
|
50
|
|
|
|
8
|
$values->{name} = $1 if !$values->{name}; |
31
|
|
|
|
|
|
|
} elsif ($option =~ m/^name (\S+)/) { |
32
|
2
|
|
|
|
|
5
|
$values->{name} = $1; |
33
|
|
|
|
|
|
|
} elsif ($option =~ m/^m (\S+)/) { |
34
|
3
|
|
|
|
|
6
|
$values->{mem} = $1; |
35
|
|
|
|
|
|
|
} elsif ($option =~ m/^uuid (\S+)/) { |
36
|
1
|
|
|
|
|
2
|
$values->{uuid} = $1; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
23
|
100
|
|
|
|
33
|
if ($option =~ /smbios/) { |
40
|
1
|
50
|
|
|
|
5
|
if ($option =~ m/smbios.*uuid=([a-zA-Z0-9-]+)/) { |
41
|
1
|
|
|
|
|
2
|
$values->{uuid} = $1; |
42
|
|
|
|
|
|
|
} |
43
|
1
|
50
|
|
|
|
5
|
if ($option =~ m/smbios.*serial=([a-zA-Z0-9-]+)/) { |
44
|
1
|
|
|
|
|
2
|
$values->{serial} = $1; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
3
|
50
|
|
|
|
9
|
if ($values->{mem} == 0 ) { |
50
|
|
|
|
|
|
|
# Default value |
51
|
0
|
|
|
|
|
0
|
$values->{mem} = 128; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
3
|
|
|
|
|
38
|
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
|
|
|
|
|
|
|
$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
|
0
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |