Class: HostManager::Client
- Inherits:
-
Base
- Object
- Base
- HostManager::Client
show all
- Defined in:
- lib/host-manager.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#add_entry, #build_hosts_data, #compose_host_names, #execute, #get_hosts, #host_name, #host_suffix, #log, #update_hosts_file, #valid_entry?
Constructor Details
#initialize(ip, port) ⇒ Client
Returns a new instance of Client.
264
265
266
|
# File 'lib/host-manager.rb', line 264
def initialize(ip, port)
@socket = TCPSocket.new(ip, port)
end
|
Class Method Details
.create(ip, port) ⇒ Object
293
294
295
|
# File 'lib/host-manager.rb', line 293
def self.create(ip, port)
self.new(ip, port)
end
|
Instance Method Details
#close ⇒ Object
268
269
270
271
|
# File 'lib/host-manager.rb', line 268
def close
log.info('Closing client connection.')
@socket.close
end
|
#send(data) ⇒ Object
288
289
290
291
|
# File 'lib/host-manager.rb', line 288
def send(data)
log.info("Sending data via client: #{data.to_json}")
@socket.write data.to_json + "\n"
end
|
#sync_hosts(container_data) ⇒ Object
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
# File 'lib/host-manager.rb', line 273
def sync_hosts(container_data)
data = build_hosts_data(container_data)
begin
update_hosts_file(data)
`service dnsmasq restart`
rescue => e
log.error("Caught exception attempting to write to hosts file with data #{data.to_json}. #{e}")
end
send(data)
end
|