line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Virtualization::VmWareDesktop; |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# initial version: Walid Nouh |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
50623440
|
use strict; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
40
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
64
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
395
|
use FusionInventory::Agent::Tools; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
360
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub isEnabled { |
12
|
|
|
|
|
|
|
return |
13
|
0
|
|
0
|
0
|
0
|
|
canRun('/Library/Application Support/VMware Fusion/vmrun') || |
14
|
|
|
|
|
|
|
canRun('vmrun'); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub doInventory { |
18
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my $inventory = $params{inventory}; |
21
|
0
|
|
|
|
|
|
my $logger = $params{logger}; |
22
|
|
|
|
|
|
|
|
23
|
0
|
0
|
|
|
|
|
my $command = canRun('vmrun') ? |
24
|
|
|
|
|
|
|
'vmrun list' : "'/Library/Application Support/VMware Fusion/vmrun' list"; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
foreach my $machine (_getMachines( |
27
|
|
|
|
|
|
|
command => $command, logger => $logger |
28
|
|
|
|
|
|
|
)) { |
29
|
0
|
|
|
|
|
|
$inventory->addEntry( |
30
|
|
|
|
|
|
|
section => 'VIRTUALMACHINES', entry => $machine |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _getMachines { |
36
|
0
|
|
|
0
|
|
|
my (%params) = @_; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $handle = getFileHandle(%params); |
39
|
0
|
0
|
|
|
|
|
return unless $handle; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# skip first line |
42
|
0
|
|
|
|
|
|
my $line = <$handle>; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my @machines; |
45
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
46
|
0
|
|
|
|
|
|
chomp $line; |
47
|
0
|
0
|
|
|
|
|
next unless -f $line; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my %info = _getMachineInfo(file => $line, logger => $params{logger}); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $machine = { |
52
|
|
|
|
|
|
|
NAME => $info{'displayName'}, |
53
|
|
|
|
|
|
|
VCPU => 1, |
54
|
|
|
|
|
|
|
UUID => $info{'uuid.bios'}, |
55
|
0
|
|
|
|
|
|
MEMORY => $info{'memsize'}, |
56
|
|
|
|
|
|
|
STATUS => "running", |
57
|
|
|
|
|
|
|
SUBSYSTEM => "VmWare Fusion", |
58
|
|
|
|
|
|
|
VMTYPE => "VmWare", |
59
|
|
|
|
|
|
|
}; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
push @machines, $machine; |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
close $handle; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return @machines; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _getMachineInfo { |
69
|
0
|
|
|
0
|
|
|
my $handle = getFileHandle(@_); |
70
|
0
|
0
|
|
|
|
|
return unless $handle; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my %info; |
73
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
74
|
0
|
0
|
|
|
|
|
next unless $line =~ /^(\S+)\s*=\s*(\S+.*)/; |
75
|
0
|
|
|
|
|
|
my $key = $1; |
76
|
0
|
|
|
|
|
|
my $value = $2; |
77
|
0
|
|
|
|
|
|
$value =~ s/(^"|"$)//g; |
78
|
0
|
|
|
|
|
|
$info{$key} = $value; |
79
|
|
|
|
|
|
|
} |
80
|
0
|
|
|
|
|
|
close $handle; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return %info; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |