module LunaScanner

Constants

VERSION

Public Class Methods

check_ssh_key!() click to toggle source
# File lib/luna_scanner.rb, line 37
def check_ssh_key!
  raise SSHKeyNotFoundError.new("Please provide ssh key file: #{ssh_key}") if not File.exist?(ssh_key)

  ssh_key
end
local_ip() click to toggle source
# File lib/luna_scanner.rb, line 18
def local_ip
  @local_ip ||= begin
    orig = Socket.do_not_reverse_lookup
    Socket.do_not_reverse_lookup =true # turn off reverse DNS resolution temporarily
    UDPSocket.open do |s|
      s.connect '64.233.187.99', 1 #google
      s.addr.last
    end
  rescue

  ensure
    Socket.do_not_reverse_lookup = orig
  end
end
pwd() click to toggle source
# File lib/luna_scanner.rb, line 14
def pwd
  @pwd ||= Dir.pwd
end
root() click to toggle source
# File lib/luna_scanner.rb, line 10
def root
  @root_path ||= File.expand_path("../", __FILE__)
end
ssh_key() click to toggle source
# File lib/luna_scanner.rb, line 33
def ssh_key
  @ssh_key ||= Dir.home.to_s + "/yu_pri"
end
start_ssh(ip, &block) click to toggle source
# File lib/luna_scanner.rb, line 43
def start_ssh(ip, &block)
  Net::SSH.start(
      "#{ip}", 'root',
      :auth_methods => ["publickey"],
      :user_known_hosts_file => "/dev/null",
      :timeout => 8,
      :verbose => :error,
      :keys => [ ssh_key ]  # Fix key permission: chmod g-wr ./yu_pri  chmod o-wr ./yu_pri  chmod u-w ./yu_pri
  ) do |session|
    block.call(session)
  end
end