Class: Sambot::DeveloperWorkflow::Tunnels

Inherits:
Object
  • Object
show all
Defined in:
lib/sambot/developer_workflow/tunnels.rb

Constant Summary collapse

PID_PATH =
'/tmp/sambot-session.pid'
LOG_PATH =
'/tmp/sambot-session.log'
SESSION_ID =
'sambot'

Class Method Summary collapse

Class Method Details

.setup_ssh_tunnels(username, password, bastion_host_ip, forwards) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/sambot/developer_workflow/tunnels.rb', line 29

def self.setup_ssh_tunnels(username, password, bastion_host_ip, forwards)
  full_username = "DEV\\#{username}"
  UI.debug "Opening a connection to the Rackspace DEV/QE environment"
  Net::SSH.start(bastion_host_ip, full_username, :password => password) do |session|
    forwards.each { |key, value| Tunnel.create(session, key, value[:ip], value[:port], value[:local_port]) }
    session.loop {true}
  end
end

.start(username, password, bastion_host_ip, forwards) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/sambot/developer_workflow/tunnels.rb', line 12

def self.start(username, password, bastion_host_ip, forwards)
  UI.info("Starting daemon for tunneling - log is available at #{LOG_PATH}")
  Dante::Runner.new(SESSION_ID).execute(:daemonize => true, :pid_path => PID_PATH, :log_path => LOG_PATH) do
    setup_ssh_tunnels(username, password, bastion_host_ip, forwards)
  end
  sleep(2)
  puts "----- Background Daemon Log -----"
  puts File.read(LOG_PATH)
  puts "---------------------------------"
end

.stopObject



23
24
25
26
27
# File 'lib/sambot/developer_workflow/tunnels.rb', line 23

def self.stop
  Dante::Runner.new(SESSION_ID).execute(:kill => true, :pid_path => PID_PATH)
  UI.debug("All active sessions have been closed")
  File.delete(LOG_PATH) if File.exist?(LOG_PATH)
end