line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Virtualization::HyperV; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
39810256
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
68
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
71
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use English qw(-no_match_vars); |
|
1
|
|
|
|
|
38
|
|
|
1
|
|
|
|
|
23
|
|
7
|
1
|
|
|
1
|
|
849
|
use UNIVERSAL::require; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
398
|
use FusionInventory::Agent::Tools; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
139
|
|
10
|
1
|
|
|
1
|
|
375
|
use FusionInventory::Agent::Tools::Hostname; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
420
|
|
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
|
0
|
0
|
|
|
|
|
my $status = |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$object->{EnabledState} == 2 ? 'running' : |
81
|
|
|
|
|
|
|
$object->{EnabledState} == 3 ? 'shutdown' : |
82
|
|
|
|
|
|
|
$object->{EnabledState} == 32768 ? 'paused' : |
83
|
|
|
|
|
|
|
'unknown' ; |
84
|
0
|
|
|
|
|
|
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
|
|
|
|
|
|
|
}; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
push @machines, $machine; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return @machines; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |