Skip to content

Commit 37de827

Browse files
committed
Read messaging options
1 parent 6b2c63a commit 37de827

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

workers/event_catcher/event_catcher.rb

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
require "manageiq-messaging"
22
require "sd_notify"
33
require "rbvmomi"
4+
require "json"
45

56
class EventCatcher
6-
def initialize(ems_id, default_endpoint, default_authentication, messaging_opts, page_size = 20)
7-
@ems_id = ems_id
8-
@hostname = default_endpoint["hostname"]
9-
@username = default_authentication["userid"]
10-
@password = default_authentication["password"]
11-
@port = default_endpoint["port"]
12-
@messaging_host = messaging_opts["host"] || "localhost"
13-
@messaging_port = messaging_opts["port"] || 9092
14-
@page_size = page_size
7+
def initialize(ems_id, default_endpoint, default_authentication, messaging, page_size = 20)
8+
@ems_id = ems_id
9+
@default_endpoint = default_endpoint
10+
@default_authentication = default_authentication
11+
@messaging = messaging
12+
@page_size = page_size
1513
end
1614

1715
def run!
@@ -44,22 +42,22 @@ def stop!
4442

4543
private
4644

47-
attr_reader :ems_id, :hostname, :messaging_host, :messaging_port, :password, :port, :page_size, :username
45+
attr_reader :ems_id, :default_endpoint, :default_authentication, :messaging, :page_size
4846

4947
def connect
5048
vim_opts = {
5149
:ns => 'urn:vim25',
52-
:host => hostname,
50+
:host => default_endpoint["hostname"],
5351
:ssl => true,
54-
:insecure => true,
52+
:insecure => default_endpoint["verify_ssl"] == OpenSSL::SSL::VERIFY_NONE,
5553
:path => '/sdk',
56-
:port => port,
57-
:rev => '6.5',
54+
:port => default_endpoint["port"],
55+
:rev => '7.0',
5856
}
5957

6058
RbVmomi::VIM.new(vim_opts).tap do |vim|
6159
vim.rev = vim.serviceContent.about.apiVersion
62-
vim.serviceContent.sessionManager.Login(:userName => username, :password => password)
60+
vim.serviceContent.sessionManager.Login(:userName => default_authentication["userid"], :password => default_authentication["password"])
6361
end
6462
end
6563

@@ -217,8 +215,8 @@ def publish_events(events)
217215

218216
def messaging_client
219217
@messaging_client ||= ManageIQ::Messaging::Client.open(
220-
:host => messaging_host,
221-
:port => messaging_port,
218+
:host => messaging["host"],
219+
:port => messaging["port"],
222220
:protocol => :Kafka,
223221
:encoding => "json",
224222
:client_ref => "vmware-event-catcher-#{ems_id}"
@@ -246,18 +244,17 @@ def setproctitle
246244
def main(args)
247245
setproctitle
248246

249-
ems = args["ems"].detect { |e| e["type"] == "ManageIQ::Providers::Vmware::InfraManager" }
250-
247+
ems = args["ems"].detect { |e| e["type"] == "ManageIQ::Providers::Vmware::InfraManager" }
251248
default_endpoint = ems["endpoints"].detect { |ep| ep["role"] == "default" }
252249
default_authentication = ems["authentications"].detect { |auth| auth["authtype"] == "default" }
250+
messaging = args["messaging"]
253251

254-
event_catcher = EventCatcher.new(ems["id"], default_endpoint, default_authentication, {}) # TODO: args["messaging_opts"])
252+
event_catcher = EventCatcher.new(ems["id"], default_endpoint, default_authentication, messaging)
255253

256254
event_catcher.run!
257255
end
258256

259257
def parse_args
260-
require "json"
261258
JSON.parse($stdin.read)
262259
end
263260

0 commit comments

Comments
 (0)