Class: Linecook::Commands::Ssh

Inherits:
VirtualBoxCommand show all
Defined in:
lib/linecook/commands/ssh.rb

Overview

:startdoc::desc ssh to a vm

Connects to a virtual machine using ssh, as configured in config/ssh.

Constant Summary

Constants inherited from VirtualBoxCommand

VirtualBoxCommand::HOST_REGEXP

Instance Method Summary collapse

Methods inherited from VirtualBoxCommand

#discardstate, #each_host, #each_vm_name, #host_list, #host_map, #load_hosts, #resolve_vm_names, #restore, #running?, #share, #ssh, #ssh!, #ssh_config_file=, #start, #start_ssh_socket, #stop

Methods included from Linecook::CommandUtils

#sh, #sh!

Methods inherited from Linecook::Command

#call, help, #initialize, parse, signature

Constructor Details

This class inherits a constructor from Linecook::Command

Instance Method Details

#default_hostObject



13
14
15
# File 'lib/linecook/commands/ssh.rb', line 13

def default_host
  load_hosts(ssh_config_file).collect {|host, vm_name| host }.first
end

#process(host = default_host) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/linecook/commands/ssh.rb', line 17

def process(host=default_host)
  if host.to_s.strip.empty?
    raise CommandError.new("no host specified")
  end

  ssh = "ssh -F '#{ssh_config_file}' '#{host}' --"

  # Patterned after vagrant/ssh.rb (circa 0.6.6)
  # Some hackery going on here. On Mac OS X Leopard (10.5), exec fails
  # (GH-51). As a workaround, we fork and wait. On all other platforms, we
  # simply exec.

  platform = RUBY_PLATFORM.to_s.downcase
  pid = nil
  pid = fork if platform.include?("darwin9") || platform.include?("darwin8")
  Kernel.exec(ssh)  if pid.nil?
  Process.wait(pid) if pid

  exit $?.exitstatus
end