line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Virtualization::HyperV; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
52460578
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
85
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
136
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
25
|
use English qw(-no_match_vars); |
|
2
|
|
|
|
|
80
|
|
|
2
|
|
|
|
|
38
|
|
7
|
2
|
|
|
2
|
|
1529
|
use UNIVERSAL::require; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
32
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
769
|
use FusionInventory::Agent::Tools; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
399
|
|
10
|
2
|
|
|
2
|
|
1236
|
use FusionInventory::Agent::Tools::Hostname; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1241
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub isEnabled { |
13
|
0
|
|
|
0
|
0
|
0
|
return $OSNAME eq 'MSWin32'; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub doInventory { |
17
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
0
|
my $inventory = $params{inventory}; |
20
|
0
|
|
|
|
|
0
|
my $logger = $params{inventory}; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
0
|
foreach my $machine (_getVirtualMachines(logger => $logger)) { |
23
|
0
|
|
|
|
|
0
|
$inventory->addEntry( |
24
|
|
|
|
|
|
|
section => 'VIRTUALMACHINES', entry => $machine |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _getVirtualMachines { |
30
|
2
|
|
|
2
|
|
561
|
FusionInventory::Agent::Tools::Win32->require(); |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
123
|
my $hostname = getHostname(short => 1); |
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
|
|
4
|
my @machines; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# index memory, cpu and BIOS UUID information |
37
|
|
|
|
|
|
|
my %memory; |
38
|
2
|
|
|
|
|
10
|
foreach my $object (FusionInventory::Agent::Tools::Win32::getWMIObjects( |
39
|
|
|
|
|
|
|
moniker => 'winmgmts://./root/virtualization', |
40
|
|
|
|
|
|
|
class => 'MSVM_MemorySettingData', |
41
|
|
|
|
|
|
|
properties => [ qw/InstanceID VirtualQuantity/ ] |
42
|
|
|
|
|
|
|
)) { |
43
|
5
|
|
|
|
|
5466
|
my $id = $object->{InstanceID}; |
44
|
5
|
50
|
|
|
|
22
|
next unless $id =~ /^Microsoft:([^\\]+)/; |
45
|
5
|
|
|
|
|
17
|
$memory{$1} = $object->{VirtualQuantity}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
2
|
|
|
|
|
71
|
my %vcpu; |
49
|
2
|
|
|
|
|
11
|
foreach my $object (FusionInventory::Agent::Tools::Win32::getWMIObjects( |
50
|
|
|
|
|
|
|
moniker => 'winmgmts://./root/virtualization', |
51
|
|
|
|
|
|
|
class => 'MSVM_ProcessorSettingData', |
52
|
|
|
|
|
|
|
properties => [ qw/InstanceID VirtualQuantity/ ] |
53
|
|
|
|
|
|
|
)) { |
54
|
5
|
|
|
|
|
1177
|
my $id = $object->{InstanceID}; |
55
|
5
|
50
|
|
|
|
26
|
next unless $id =~ /^Microsoft:([^\\]+)/; |
56
|
5
|
|
|
|
|
20
|
$vcpu{$1} = $object->{VirtualQuantity}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
37
|
my %biosguid; |
60
|
2
|
|
|
|
|
11
|
foreach my $object (FusionInventory::Agent::Tools::Win32::getWMIObjects( |
61
|
|
|
|
|
|
|
moniker => 'winmgmts://./root/virtualization', |
62
|
|
|
|
|
|
|
class => 'MSVM_VirtualSystemSettingData', |
63
|
|
|
|
|
|
|
properties => [ qw/InstanceID BIOSGUID/ ] |
64
|
|
|
|
|
|
|
)) { |
65
|
0
|
|
|
|
|
0
|
my $id = $object->{InstanceID}; |
66
|
0
|
0
|
|
|
|
0
|
next unless $id =~ /^Microsoft:([^\\]+)/; |
67
|
0
|
|
|
|
|
0
|
$biosguid{$1} = $object->{BIOSGUID}; |
68
|
0
|
|
|
|
|
0
|
$biosguid{$1} =~ tr/{}//d; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
100
|
foreach my $object (FusionInventory::Agent::Tools::Win32::getWMIObjects( |
72
|
|
|
|
|
|
|
moniker => 'winmgmts://./root/virtualization', |
73
|
|
|
|
|
|
|
class => 'MSVM_ComputerSystem', |
74
|
|
|
|
|
|
|
properties => [ qw/ElementName EnabledState Name/ ] |
75
|
|
|
|
|
|
|
)) { |
76
|
|
|
|
|
|
|
# skip host |
77
|
6
|
50
|
|
|
|
917
|
next if lc($object->{Name}) eq lc($hostname); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $status = |
80
|
|
|
|
|
|
|
$object->{EnabledState} == 2 ? 'running' : |
81
|
|
|
|
|
|
|
$object->{EnabledState} == 3 ? 'shutdown' : |
82
|
6
|
0
|
|
|
|
22
|
$object->{EnabledState} == 32768 ? 'paused' : |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
83
|
|
|
|
|
|
|
'unknown' ; |
84
|
|
|
|
|
|
|
my $machine = { |
85
|
|
|
|
|
|
|
SUBSYSTEM => 'MS HyperV', |
86
|
|
|
|
|
|
|
VMTYPE => 'HyperV', |
87
|
|
|
|
|
|
|
STATUS => $status, |
88
|
|
|
|
|
|
|
NAME => $object->{ElementName}, |
89
|
|
|
|
|
|
|
UUID => $biosguid{$object->{Name}}, |
90
|
|
|
|
|
|
|
MEMORY => $memory{$object->{Name}}, |
91
|
|
|
|
|
|
|
VCPU => $vcpu{$object->{Name}}, |
92
|
6
|
|
|
|
|
48
|
}; |
93
|
|
|
|
|
|
|
|
94
|
6
|
|
|
|
|
14
|
push @machines, $machine; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
2
|
|
|
|
|
15
|
return @machines; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |