Class: Vagrant::Command::SSH
Instance Method Summary collapse
Methods inherited from Base
Methods included from Util::SafePuts
Constructor Details
This class inherits a constructor from Vagrant::Command::Base
Instance Method Details
#execute ⇒ Object
6 7 8 9 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 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/vagrant/command/ssh.rb', line 6 def execute = {} opts = OptionParser.new do |opts| opts. = "Usage: vagrant ssh [vm-name] [-c command] [-- extra ssh args]" opts.separator "" opts.on("-c", "--command COMMAND", "Execute an SSH command directly.") do |c| [:command] = c end opts.on("-p", "--plain", "Plain mode, leaves authentication up to user.") do |p| [:plain_mode] = p end end # Parse the options and return if we don't have any target. argv = (opts) return if !argv # Parse out the extra args to send to SSH, which is everything # after the "--" ssh_args = ARGV.drop_while { |i| i != "--" } ssh_args = ssh_args[1..-1] [:ssh_args] = ssh_args # If the remaining arguments ARE the SSH arguments, then just # clear it out. This happens because optparse returns what is # after the "--" as remaining ARGV, and Vagrant can think it is # a multi-vm name (wrong!) argv = [] if argv == ssh_args # Execute the actual SSH with_target_vms(argv, :single_target => true) do |vm| # Basic checks that are required for proper SSH raise Errors::VMNotCreatedError if !vm.created? raise Errors::VMInaccessible if !vm.state == :inaccessible raise Errors::VMNotRunningError if vm.state != :running if [:command] ssh_execute(vm, [:command]) else opts = { :plain_mode => [:plain_mode], :extra_args => [:ssh_args] } ssh_connect(vm, opts) end end # Success, exit status 0 0 end |