Class: Vagrant::Command::SSHConfig

Inherits:
Base
  • Object
show all
Includes:
Util::SafePuts
Defined in:
lib/vagrant/command/ssh_config.rb

Instance Method Summary collapse

Methods included from Util::SafePuts

#safe_puts

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Vagrant::Command::Base

Instance Method Details

#executeObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/vagrant/command/ssh_config.rb', line 10

def execute
 options = {}

 opts = OptionParser.new do |opts|
   opts.banner = "Usage: vagrant ssh-config [vm-name] [--host name]"

   opts.separator ""

   opts.on("--host NAME", "Name the host for the config..") do |h|
     options[:host] = h
   end
 end

 argv = parse_options(opts)
 return if !argv

 with_target_vms(argv, :single_target => true) do |vm|
   raise Errors::VMNotCreatedError if !vm.created?
   raise Errors::VMInaccessible if !vm.state == :inaccessible

   ssh_info  = vm.ssh.info
   variables = {
     :host_key => options[:host] || vm.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
   template = "commands/ssh_config/config"
   safe_puts(Util::TemplateRenderer.render(template, variables))
 end

 # Success, exit status 0
 0
end