line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Virtualization::HyperV; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
45404806
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
56
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use English qw(-no_match_vars); |
|
1
|
|
|
|
|
32
|
|
|
1
|
|
|
|
|
19
|
|
7
|
1
|
|
|
1
|
|
549
|
use UNIVERSAL::require; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
388
|
use FusionInventory::Agent::Tools; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
126
|
|
10
|
1
|
|
|
1
|
|
329
|
use FusionInventory::Agent::Tools::Hostname; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
386
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub isEnabled { |
13
|
0
|
|
|
0
|
0
|
|
return $OSNAME eq 'MSWin32'; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub doInventory { |
17
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $inventory = $params{inventory}; |
20
|
0
|
|
|
|
|
|
my $logger = $params{inventory}; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
foreach my $machine (_getVirtualMachines(logger => $logger)) { |
23
|
0
|
|
|
|
|
|
$inventory->addEntry( |
24
|
|
|
|
|
|
|
section => 'VIRTUALMACHINES', entry => $machine |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _getVirtualMachines { |
30
|
0
|
|
|
0
|
|
|
FusionInventory::Agent::Tools::Win32->require(); |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $hostname = getHostname(short => 1); |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my @machines; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# index memory, cpu and BIOS UUID information |
37
|
|
|
|
|
|
|
my %memory; |
38
|
0
|
|
|
|
|
|
foreach my $object (FusionInventory::Agent::Tools::Win32::getWMIObjects( |
39
|
|
|
|
|
|
|
moniker => 'winmgmts://./root/virtualization', |
40
|
|
|
|
|
|
|
class => 'MSVM_MemorySettingData', |
41
|
|
|
|
|
|
|
properties => [ qw/InstanceID VirtualQuantity/ ] |
42
|
|
|
|
|
|
|
)) { |
43
|
0
|
|
|
|
|
|
my $id = $object->{InstanceID}; |
44
|
0
|
0
|
|
|
|
|
next unless $id =~ /^Microsoft:([^\\]+)/; |
45
|
0
|
|
|
|
|
|
$memory{$1} = $object->{VirtualQuantity}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my %vcpu; |
49
|
0
|
|
|
|
|
|
foreach my $object (FusionInventory::Agent::Tools::Win32::getWMIObjects( |
50
|
|
|
|
|
|
|
moniker => 'winmgmts://./root/virtualization', |
51
|
|
|
|
|
|
|
class => 'MSVM_ProcessorSettingData', |
52
|
|
|
|
|
|
|
properties => [ qw/InstanceID VirtualQuantity/ ] |
53
|
|
|
|
|
|
|
)) { |
54
|
0
|
|
|
|
|
|
my $id = $object->{InstanceID}; |
55
|
0
|
0
|
|
|
|
|
next unless $id =~ /^Microsoft:([^\\]+)/; |
56
|
0
|
|
|
|
|
|
$vcpu{$1} = $object->{VirtualQuantity}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my %biosguid; |
60
|
0
|
|
|
|
|
|
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
|
|
|
|
|
|
my $id = $object->{InstanceID}; |
66
|
0
|
0
|
|
|
|
|
next unless $id =~ /^Microsoft:([^\\]+)/; |
67
|
0
|
|
|
|
|
|
$biosguid{$1} = $object->{BIOSGUID}; |
68
|
0
|
|
|
|
|
|
$biosguid{$1} =~ tr/{}//d; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
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
|
0
|
0
|
|
|
|
|
next if lc($object->{Name}) eq lc($hostname); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $status = |
80
|
|
|
|
|
|
|
$object->{EnabledState} == 2 ? 'running' : |
81
|
|
|
|
|
|
|
$object->{EnabledState} == 3 ? 'shutdown' : |
82
|
0
|
0
|
|
|
|
|
$object->{EnabledState} == 32768 ? 'paused' : |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
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
|
0
|
|
|
|
|
|
}; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
push @machines, $machine; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return @machines; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |