| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::ESX; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
19147154
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
62
|
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
84
|
|
|
5
|
2
|
|
|
2
|
|
5
|
use base 'FusionInventory::Agent::Task'; |
|
|
2
|
|
|
|
|
40
|
|
|
|
2
|
|
|
|
|
725
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
687
|
use FusionInventory::Agent::Config; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
16
|
|
|
8
|
2
|
|
|
2
|
|
773
|
use FusionInventory::Agent::HTTP::Client::Fusion; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
19
|
|
|
9
|
2
|
|
|
2
|
|
49
|
use FusionInventory::Agent::Logger; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
99
|
|
|
10
|
2
|
|
|
2
|
|
739
|
use FusionInventory::Agent::Inventory; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
20
|
|
|
11
|
2
|
|
|
2
|
|
777
|
use FusionInventory::Agent::XML::Query::Inventory; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
12
|
|
|
12
|
2
|
|
|
2
|
|
762
|
use FusionInventory::Agent::SOAP::VMware; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
16
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = "2.2.1"; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub isEnabled { |
|
17
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
18
|
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
|
if (!$self->{target}->isa('FusionInventory::Agent::Target::Server')) { |
|
20
|
0
|
|
|
|
|
|
$self->{logger}->debug("ESX task not compatible with local target"); |
|
21
|
0
|
|
|
|
|
|
return; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
return 1; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub connect { |
|
28
|
0
|
|
|
0
|
1
|
|
my ( $self, %params ) = @_; |
|
29
|
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $url = 'https://' . $params{host} . '/sdk/vimService'; |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $vpbs = |
|
33
|
|
|
|
|
|
|
FusionInventory::Agent::SOAP::VMware->new(url => $url, vcenter => 1 ); |
|
34
|
0
|
0
|
|
|
|
|
if ( !$vpbs->connect( $params{user}, $params{password} ) ) { |
|
35
|
0
|
|
|
|
|
|
$self->{lastError} = $vpbs->{lastError}; |
|
36
|
0
|
|
|
|
|
|
return; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
$self->{vpbs} = $vpbs; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub createFakeDeviceid { |
|
43
|
0
|
|
|
0
|
1
|
|
my ( $self, $host ) = @_; |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $hostname = $host->getHostname(); |
|
46
|
0
|
|
|
|
|
|
my $bootTime = $host->getBootTime(); |
|
47
|
0
|
|
|
|
|
|
my ( $year, $month, $day, $hour, $min, $sec ); |
|
48
|
0
|
0
|
|
|
|
|
if ( $bootTime =~ |
|
49
|
|
|
|
|
|
|
/(\d{4})-(\d{1,2})-(\d{1,2})T(\d{1,2}):(\d{1,2}):(\d{1,2})/ ) |
|
50
|
|
|
|
|
|
|
{ |
|
51
|
0
|
|
|
|
|
|
$year = $1; |
|
52
|
0
|
|
|
|
|
|
$month = $2; |
|
53
|
0
|
|
|
|
|
|
$day = $3; |
|
54
|
0
|
|
|
|
|
|
$hour = $4; |
|
55
|
0
|
|
|
|
|
|
$min = $5; |
|
56
|
0
|
|
|
|
|
|
$sec = $6; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
else { |
|
59
|
0
|
|
|
|
|
|
my $ty; |
|
60
|
|
|
|
|
|
|
my $tm; |
|
61
|
0
|
|
|
|
|
|
( $ty, $tm, $day, $hour, $min, $sec ) = |
|
62
|
|
|
|
|
|
|
( localtime(time) )[ 5, 4, 3, 2, 1, 0 ]; |
|
63
|
0
|
|
|
|
|
|
$year = $ty + 1900; |
|
64
|
0
|
|
|
|
|
|
$month = $tm + 1; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
0
|
|
|
|
|
|
my $deviceid = sprintf "%s-%02d-%02d-%02d-%02d-%02d-%02d", |
|
67
|
|
|
|
|
|
|
$hostname, $year, $month, $day, $hour, $min, $sec; |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
return $deviceid; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub createInventory { |
|
73
|
0
|
|
|
0
|
1
|
|
my ( $self, $id, $tag ) = @_; |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
die unless $self->{vpbs}; |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $vpbs = $self->{vpbs}; |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $host; |
|
80
|
0
|
|
|
|
|
|
$host = $vpbs->getHostFullInfo($id); |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $inventory = FusionInventory::Agent::Inventory->new( |
|
83
|
|
|
|
|
|
|
logger => $self->{logger}, |
|
84
|
0
|
|
|
|
|
|
tag => $tag |
|
85
|
|
|
|
|
|
|
); |
|
86
|
0
|
|
|
|
|
|
$inventory->{deviceid} = $self->createFakeDeviceid($host); |
|
87
|
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$inventory->{isInitialised} = 1; |
|
89
|
0
|
|
|
|
|
|
$inventory->{h}{CONTENT}{HARDWARE}{ARCHNAME} = ['remote']; |
|
90
|
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
$inventory->setBios( $host->getBiosInfo() ); |
|
92
|
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
$inventory->setHardware( $host->getHardwareInfo() ); |
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
foreach my $cpu ($host->getCPUs()) { |
|
96
|
0
|
|
|
|
|
|
$inventory->addEntry(section => 'CPUS', entry => $cpu); |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
foreach my $controller ($host->getControllers()) { |
|
100
|
0
|
|
|
|
|
|
$inventory->addEntry(section => 'CONTROLLERS', entry => $controller); |
|
101
|
|
|
|
|
|
|
|
|
102
|
0
|
0
|
0
|
|
|
|
if ($controller->{PCICLASS} && $controller->{PCICLASS} eq '300') { |
|
103
|
|
|
|
|
|
|
$inventory->addEntry( |
|
104
|
|
|
|
|
|
|
section => 'VIDEOS', |
|
105
|
|
|
|
|
|
|
entry => { |
|
106
|
|
|
|
|
|
|
NAME => $controller->{NAME}, |
|
107
|
|
|
|
|
|
|
PCISLOT => $controller->{PCISLOT}, |
|
108
|
|
|
|
|
|
|
} |
|
109
|
0
|
|
|
|
|
|
); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
my %ipaddr; |
|
114
|
0
|
|
|
|
|
|
foreach my $network ($host->getNetworks()) { |
|
115
|
0
|
0
|
|
|
|
|
$ipaddr{ $network->{IPADDRESS} } = 1 if $network->{IPADDRESS}; |
|
116
|
0
|
|
|
|
|
|
$inventory->addEntry(section => 'NETWORKS', entry => $network); |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
$inventory->setHardware( { IPADDR => join '/', ( keys %ipaddr ) } ); |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# TODO |
|
122
|
|
|
|
|
|
|
# foreach (@{$host->[0]{config}{fileSystemVolume}{mountInfo}}) { |
|
123
|
|
|
|
|
|
|
# |
|
124
|
|
|
|
|
|
|
# } |
|
125
|
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
foreach my $storage ($host->getStorages()) { |
|
127
|
|
|
|
|
|
|
# TODO |
|
128
|
|
|
|
|
|
|
# $volumnMapping{$entry->{canonicalName}} = $entry->{deviceName}; |
|
129
|
0
|
|
|
|
|
|
$inventory->addEntry(section => 'STORAGES', entry => $storage); |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
foreach my $drive ($host->getDrives()) { |
|
133
|
0
|
|
|
|
|
|
$inventory->addEntry( section => 'DRIVES', entry => $drive); |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
foreach my $machine ($host->getVirtualMachines()) { |
|
137
|
0
|
|
|
|
|
|
$inventory->addEntry(section => 'VIRTUALMACHINES', entry => $machine); |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
return $inventory; |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
#sub getJobs { |
|
145
|
|
|
|
|
|
|
# my ($self) = @_; |
|
146
|
|
|
|
|
|
|
# |
|
147
|
|
|
|
|
|
|
# my $logger = $self->{logger}; |
|
148
|
|
|
|
|
|
|
# my $network = $self->{network}; |
|
149
|
|
|
|
|
|
|
# |
|
150
|
|
|
|
|
|
|
# my $jsonText = $network->get ({ |
|
151
|
|
|
|
|
|
|
# source => $self->{backendURL}.'/?a=getJobs&d=TODO', |
|
152
|
|
|
|
|
|
|
# timeout => 60, |
|
153
|
|
|
|
|
|
|
# }); |
|
154
|
|
|
|
|
|
|
# if (!defined($jsonText)) { |
|
155
|
|
|
|
|
|
|
# $logger->debug("No answer from server for deployment job."); |
|
156
|
|
|
|
|
|
|
# return; |
|
157
|
|
|
|
|
|
|
# } |
|
158
|
|
|
|
|
|
|
# |
|
159
|
|
|
|
|
|
|
# |
|
160
|
|
|
|
|
|
|
# return from_json( $jsonText, { utf8 => 1 } ); |
|
161
|
|
|
|
|
|
|
#} |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub getHostIds { |
|
164
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
165
|
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
return $self->{vpbs}->getHostIds(); |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub run { |
|
170
|
0
|
|
|
0
|
1
|
|
my ( $self, %params ) = @_; |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
$self->{client} = FusionInventory::Agent::HTTP::Client::Fusion->new( |
|
173
|
|
|
|
|
|
|
logger => $self->{logger}, |
|
174
|
|
|
|
|
|
|
user => $params{user}, |
|
175
|
|
|
|
|
|
|
password => $params{password}, |
|
176
|
|
|
|
|
|
|
proxy => $params{proxy}, |
|
177
|
|
|
|
|
|
|
ca_cert_file => $params{ca_cert_file}, |
|
178
|
|
|
|
|
|
|
ca_cert_dir => $params{ca_cert_dir}, |
|
179
|
|
|
|
|
|
|
no_ssl_check => $params{no_ssl_check}, |
|
180
|
|
|
|
|
|
|
debug => $self->{debug} |
|
181
|
0
|
|
|
|
|
|
); |
|
182
|
0
|
0
|
|
|
|
|
die unless $self->{client}; |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
my $globalRemoteConfig = $self->{client}->send( |
|
185
|
|
|
|
|
|
|
"url" => $self->{target}->{url}, |
|
186
|
|
|
|
|
|
|
args => { |
|
187
|
|
|
|
|
|
|
action => "getConfig", |
|
188
|
|
|
|
|
|
|
machineid => $self->{deviceid}, |
|
189
|
0
|
|
|
|
|
|
task => { ESX => $VERSION }, |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
); |
|
192
|
|
|
|
|
|
|
|
|
193
|
0
|
0
|
|
|
|
|
return unless $globalRemoteConfig->{schedule}; |
|
194
|
0
|
0
|
|
|
|
|
return unless ref( $globalRemoteConfig->{schedule} ) eq 'ARRAY'; |
|
195
|
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
foreach my $job ( @{ $globalRemoteConfig->{schedule} } ) { |
|
|
0
|
|
|
|
|
|
|
|
197
|
0
|
0
|
|
|
|
|
next unless $job->{task} eq "ESX"; |
|
198
|
0
|
|
|
|
|
|
$self->{esxRemote} = $job->{remote}; |
|
199
|
|
|
|
|
|
|
} |
|
200
|
0
|
0
|
|
|
|
|
if ( !$self->{esxRemote} ) { |
|
201
|
0
|
|
|
|
|
|
$self->{logger}->info("ESX support disabled server side."); |
|
202
|
0
|
|
|
|
|
|
return; |
|
203
|
|
|
|
|
|
|
} |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
my $jobs = $self->{client}->send( |
|
206
|
|
|
|
|
|
|
"url" => $self->{esxRemote}, |
|
207
|
|
|
|
|
|
|
args => { |
|
208
|
|
|
|
|
|
|
action => "getJobs", |
|
209
|
|
|
|
|
|
|
machineid => $self->{deviceid} |
|
210
|
|
|
|
|
|
|
} |
|
211
|
0
|
|
|
|
|
|
); |
|
212
|
|
|
|
|
|
|
|
|
213
|
0
|
0
|
|
|
|
|
return unless $jobs; |
|
214
|
0
|
0
|
|
|
|
|
return unless ref( $jobs->{jobs} ) eq 'ARRAY'; |
|
215
|
|
|
|
|
|
|
$self->{logger}->info( |
|
216
|
0
|
|
|
|
|
|
"Got " . int( @{ $jobs->{jobs} } ) . " VMware host(s) to inventory." ); |
|
|
0
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
# my $esx = FusionInventory::Agent::Task::ESX->new({ |
|
219
|
|
|
|
|
|
|
# config => $config |
|
220
|
|
|
|
|
|
|
# }); |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
my $ocsClient = FusionInventory::Agent::HTTP::Client::OCS->new( |
|
223
|
|
|
|
|
|
|
logger => $self->{logger}, |
|
224
|
|
|
|
|
|
|
user => $params{user}, |
|
225
|
|
|
|
|
|
|
password => $params{password}, |
|
226
|
|
|
|
|
|
|
proxy => $params{proxy}, |
|
227
|
|
|
|
|
|
|
ca_cert_file => $params{ca_cert_file}, |
|
228
|
|
|
|
|
|
|
ca_cert_dir => $params{ca_cert_dir}, |
|
229
|
|
|
|
|
|
|
no_ssl_check => $params{no_ssl_check}, |
|
230
|
0
|
|
|
|
|
|
); |
|
231
|
|
|
|
|
|
|
|
|
232
|
0
|
|
|
|
|
|
foreach my $job ( @{ $jobs->{jobs} } ) { |
|
|
0
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
|
|
234
|
0
|
0
|
|
|
|
|
if ( !$self->connect( |
|
235
|
|
|
|
|
|
|
host => $job->{host}, |
|
236
|
|
|
|
|
|
|
user => $job->{user}, |
|
237
|
|
|
|
|
|
|
password => $job->{password} |
|
238
|
|
|
|
|
|
|
)) { |
|
239
|
|
|
|
|
|
|
$self->{client}->send( |
|
240
|
|
|
|
|
|
|
"url" => $self->{esxRemote}, |
|
241
|
|
|
|
|
|
|
args => { |
|
242
|
|
|
|
|
|
|
action => 'setLog', |
|
243
|
|
|
|
|
|
|
machineid => $self->{deviceid}, |
|
244
|
|
|
|
|
|
|
part => 'login', |
|
245
|
|
|
|
|
|
|
uuid => $job->{uuid}, |
|
246
|
|
|
|
|
|
|
msg => $self->{lastError}, |
|
247
|
0
|
|
|
|
|
|
code => 'ko' |
|
248
|
|
|
|
|
|
|
} |
|
249
|
|
|
|
|
|
|
); |
|
250
|
|
|
|
|
|
|
|
|
251
|
0
|
|
|
|
|
|
next; |
|
252
|
|
|
|
|
|
|
} |
|
253
|
|
|
|
|
|
|
|
|
254
|
0
|
|
|
|
|
|
my $hostIds = $self->getHostIds(); |
|
255
|
0
|
|
|
|
|
|
foreach my $hostId (@$hostIds) { |
|
256
|
|
|
|
|
|
|
my $inventory = $self->createInventory( |
|
257
|
|
|
|
|
|
|
$hostId, $self->{config}->{tag} |
|
258
|
0
|
|
|
|
|
|
); |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
my $message = FusionInventory::Agent::XML::Query::Inventory->new( |
|
261
|
|
|
|
|
|
|
deviceid => $self->{deviceid}, |
|
262
|
0
|
|
|
|
|
|
content => $inventory->getContent() |
|
263
|
|
|
|
|
|
|
); |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
$ocsClient->send( |
|
266
|
0
|
|
|
|
|
|
url => $self->{target}->getUrl(), |
|
267
|
|
|
|
|
|
|
message => $message |
|
268
|
|
|
|
|
|
|
); |
|
269
|
|
|
|
|
|
|
} |
|
270
|
|
|
|
|
|
|
$self->{client}->send( |
|
271
|
|
|
|
|
|
|
"url" => $self->{esxRemote}, |
|
272
|
|
|
|
|
|
|
args => { |
|
273
|
|
|
|
|
|
|
action => 'setLog', |
|
274
|
|
|
|
|
|
|
machineid => $self->{deviceid}, |
|
275
|
|
|
|
|
|
|
uuid => $job->{uuid}, |
|
276
|
0
|
|
|
|
|
|
code => 'ok' |
|
277
|
|
|
|
|
|
|
} |
|
278
|
|
|
|
|
|
|
); |
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
} |
|
281
|
|
|
|
|
|
|
|
|
282
|
0
|
|
|
|
|
|
return $self; |
|
283
|
|
|
|
|
|
|
} |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
# Only used by the command line tool |
|
286
|
|
|
|
|
|
|
#sub new { |
|
287
|
|
|
|
|
|
|
# my ( undef, $params ) = @_; |
|
288
|
|
|
|
|
|
|
# |
|
289
|
|
|
|
|
|
|
# my $logger = FusionInventory::Agent::Logger->new(); |
|
290
|
|
|
|
|
|
|
# |
|
291
|
|
|
|
|
|
|
# my $self = { config => $params->{config}, logger => $logger }; |
|
292
|
|
|
|
|
|
|
# bless $self; |
|
293
|
|
|
|
|
|
|
#} |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
1; |
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
__END__ |