2011-12-18 01:29:52 +00:00
|
|
|
require 'optparse'
|
|
|
|
|
2010-08-25 06:55:53 +00:00
|
|
|
module Vagrant
|
|
|
|
module Command
|
2011-12-18 01:29:52 +00:00
|
|
|
class SSHConfig < Base
|
2010-08-25 06:55:53 +00:00
|
|
|
def execute
|
2011-12-18 01:29:52 +00:00
|
|
|
options = {}
|
|
|
|
|
|
|
|
opts = OptionParser.new do |opts|
|
|
|
|
opts.banner = "Usage: vagrant ssh-config [vm-name] [-h name]"
|
|
|
|
|
|
|
|
opts.separator ""
|
|
|
|
|
|
|
|
opts.on("-h", "--host COMMAND", "Name the host for the config..") do |h|
|
|
|
|
options[:host] = h
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
argv = parse_options(opts)
|
|
|
|
return if !argv
|
|
|
|
|
2011-12-27 01:59:18 +00:00
|
|
|
with_target_vms(argv[0], true) do |vm|
|
2011-12-18 01:29:52 +00:00
|
|
|
raise Errors::VMNotCreatedError if !vm.created?
|
2012-01-05 03:06:25 +00:00
|
|
|
raise Errors::VMInaccessible if !vm.state == :inaccessible
|
2011-12-18 01:29:52 +00:00
|
|
|
|
2012-01-07 01:57:50 +00:00
|
|
|
ssh_info = vm.ssh.info
|
2012-01-07 01:33:02 +00:00
|
|
|
variables = {
|
2011-12-18 01:29:52 +00:00
|
|
|
:host_key => options[:host] || vm.name || "vagrant",
|
2012-01-07 01:33:02 +00:00
|
|
|
:ssh_host => ssh_info[:host],
|
|
|
|
:ssh_port => ssh_info[:port],
|
|
|
|
:ssh_user => ssh_info[:username],
|
|
|
|
:private_key_path => ssh_info[:private_key_path],
|
|
|
|
:forward_agent => ssh_info[:forward_agent],
|
|
|
|
:forward_x11 => ssh_info[:forward_x11]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Render the template and output directly to STDOUT
|
2012-01-07 01:41:18 +00:00
|
|
|
$stdout.puts(Util::TemplateRenderer.render("ssh_config", variables))
|
2011-12-18 01:29:52 +00:00
|
|
|
end
|
2010-08-25 06:55:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|