vagrant/lib/vagrant/command/ssh_config.rb

44 lines
1.3 KiB
Ruby
Raw Normal View History

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
with_target_vms(argv[0], true) do |vm|
2011-12-18 01:29:52 +00:00
raise Errors::VMNotCreatedError if !vm.created?
raise Errors::VMInaccessible if !vm.vm.accessible?
# We need to fix the file permissions of the key if they aren't set
# properly, otherwise if the user attempts to SSH in, it won't work!
vm.ssh.check_key_permissions(vm.ssh.private_key_path)
$stdout.puts(Util::TemplateRenderer.render("ssh_config", {
:host_key => options[:host] || vm.name || "vagrant",
:ssh_host => vm.config.ssh.host,
:ssh_user => vm.config.ssh.username,
:ssh_port => vm.ssh.port,
:private_key_path => vm.config.ssh.private_key_path,
:forward_agent => vm.config.ssh.forward_agent,
:forward_x11 => vm.config.ssh.forward_x11
}))
end
2010-08-25 06:55:53 +00:00
end
end
end
end