vagrant/plugins/commands/ssh_config/command.rb

54 lines
1.5 KiB
Ruby
Raw Normal View History

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-11-07 05:05:14 +00:00
class Command < Vagrant.plugin("2", :command)
2012-04-19 20:59:48 +00:00
include Vagrant::Util::SafePuts
2012-03-18 23:41:26 +00:00
def self.synopsis
"outputs OpenSSH valid configuration to connect to the machine"
end
2010-08-25 06:55:53 +00:00
def execute
2011-12-18 01:29:52 +00:00
options = {}
opts = OptionParser.new do |o|
Merge branch 'machine-abstraction' This branch brings in the "machine abstraction" code. This is a major milestone in the development of Vagrant as it abstracts all of the VirtualBox-specific code out into a plugin. There is zero VirtualBox specific code in the core ("lib/") directory at this point. Read on for important points. == Gotchas White it is technically possible now to write plugins for other providers, there is still major work to be done to make this feasible. The plugin interface itself is pretty much done, but there are some issues: * ":virtualbox" is the hardcoded provider to be used at the moment. * There is no way to configure a provider. For example, `config.vm.customize` would never work for anything other than VirtualBox, so there needs to be a way to have provider-specific configuration. This will come soon. * Shared folders and networking need to be rearchitected to be friendly for multiple providers, since it is unrealistic that a provider such as EC2 could provide the same level of networking, for example. * There is no way easy way (like `vagrant package --base`) to create boxes for providers other than VirtualBox. This will be addressed in a whole new feature of Vagrant probably in a future release after provider stuff has shipped. == Writing a Provider To write a provider, you create a Vagrant plugin that defines a "provider". See the "plugins/providers/virtualbox/plugin.rb" for more details. Providers themselves have an exremely simple API. The burden for writing providers mostly rests on the fact that you must define complex middleware sequences. Lots more work to come in the future, but this is a BIG MILESTONE!
2012-08-20 02:27:09 +00:00
o.banner = "Usage: vagrant ssh-config [vm-name] [--host name]"
o.separator ""
2011-12-18 01:29:52 +00:00
o.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
with_target_vms(argv, :single_target => true) do |machine|
ssh_info = machine.ssh_info
raise Vagrant::Errors::SSHNotReady if ssh_info.nil?
2011-12-18 01:29:52 +00:00
variables = {
:host_key => options[:host] || machine.name || "vagrant",
: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
# Success, exit status 0
0
end
2010-08-25 06:55:53 +00:00
end
end
end