2011-12-18 01:29:52 +00:00
|
|
|
require 'optparse'
|
|
|
|
|
2012-03-18 23:41:26 +00:00
|
|
|
require "vagrant/util/safe_puts"
|
|
|
|
|
2012-04-19 20:59:48 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module CommandSSHConfig
|
2012-06-26 23:18:02 +00:00
|
|
|
class Command < Vagrant.plugin("1", :command)
|
2012-04-19 20:59:48 +00:00
|
|
|
include Vagrant::Util::SafePuts
|
2012-03-18 23:41:26 +00:00
|
|
|
|
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 ""
|
|
|
|
|
2012-03-11 17:38:23 +00:00
|
|
|
opts.on("--host COMMAND", "Name the host for the config..") do |h|
|
2011-12-18 01:29:52 +00:00
|
|
|
options[:host] = h
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
argv = parse_options(opts)
|
|
|
|
return if !argv
|
|
|
|
|
2012-03-11 22:32:17 +00:00
|
|
|
with_target_vms(argv, :single_target => true) do |vm|
|
2012-04-19 20:59:48 +00:00
|
|
|
raise Vagrant::Errors::VMNotCreatedError if !vm.created?
|
|
|
|
raise Vagrant::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-08 05:56:14 +00:00
|
|
|
template = "commands/ssh_config/config"
|
2012-04-19 20:59:48 +00:00
|
|
|
safe_puts(Vagrant::Util::TemplateRenderer.render(template, variables))
|
2011-12-18 01:29:52 +00:00
|
|
|
end
|
2012-03-23 15:07:35 +00:00
|
|
|
|
|
|
|
# Success, exit status 0
|
|
|
|
0
|
|
|
|
end
|
2010-08-25 06:55:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|