module Egon::Undercloud::PortCheckMixin

Public Instance Methods

port_open?(ip, port, stringio=nil) click to toggle source
# File lib/egon/undercloud/port-check-mixin.rb, line 12
def port_open?(ip, port, stringio=nil)
  begin
    url = "http://#{ip}:#{port}"
    stringio_write(stringio, "Testing #{url}")
    res = Net::HTTP.get_response(URI(url))
    stringio_write(stringio, res.body)
    stringio_write(stringio, "Port #{port} is open")
    true
  rescue => e
    stringio_write(stringio, e.message)
    stringio_write(stringio, e.backtrace)
    stringio_write(stringio, "Port #{port} is closed")
    false
  end
end
stringio_write(stringio, text) click to toggle source
# File lib/egon/undercloud/port-check-mixin.rb, line 7
def stringio_write(stringio, text)
  $stdout.puts text if stringio.nil?
  stringio.puts text unless stringio.nil?
end