Sha256: 8a77153f41f97a6ef3f0de11b4f7ac0c24c4303c74800acf50c5bb4a5ec27ce9

Contents?: true

Size: 1.13 KB

Versions: 24

Compression:

Stored size: 1.13 KB

Contents

module Vagrant
  module Command
    class SSHCommand < NamedBase
      class_option :execute, :type => :string, :default => false, :aliases => "-e"
      register "ssh", "SSH into the currently running Vagrant environment."

      def execute
        if options[:execute]
          ssh_execute
        else
          ssh_connect
        end
      end

      protected

      def ssh_execute
        ssh_vm.ssh.execute do |ssh|
          ssh_vm.env.ui.info I18n.t("vagrant.commands.ssh.execute", :command => options[:execute])
          ssh.exec!(options[:execute]) do |channel, type, data|
            ssh_vm.env.ui.info "#{data}"
          end
        end
      end

      def ssh_connect
        raise Errors::VMNotCreatedError if !ssh_vm.created?
        raise Errors::VMNotRunningError if !ssh_vm.vm.running?
        ssh_vm.ssh.connect
      end

      def ssh_vm
        @ssh_vm ||= begin
          vm = self.name.nil? && env.multivm? ? env.primary_vm : nil
          raise Errors::MultiVMTargetRequired, :command => "ssh" if !vm && target_vms.length > 1
          vm = target_vms.first if !vm
          vm
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 4 rubygems

Version Path
vagrantup-0.7.8 lib/vagrant/command/ssh.rb
vagrantup-0.7.7 lib/vagrant/command/ssh.rb
vagrantup-0.7.6 lib/vagrant/command/ssh.rb
vagrantup-0.7.5 lib/vagrant/command/ssh.rb
vagrantup-0.7.4 lib/vagrant/command/ssh.rb
vagrantup-0.7.3 lib/vagrant/command/ssh.rb
vagrantup-0.7.2 lib/vagrant/command/ssh.rb
vagrantup-0.7.1 lib/vagrant/command/ssh.rb
vagrantup-0.7.0 lib/vagrant/command/ssh.rb
vagrantup-0.6.9 lib/vagrant/command/ssh.rb
vagrant-0.7.8 lib/vagrant/command/ssh.rb
vagrant-0.7.7 lib/vagrant/command/ssh.rb
vagrant-0.7.6 lib/vagrant/command/ssh.rb
vagrant-0.7.5 lib/vagrant/command/ssh.rb
vagrant-0.7.4 lib/vagrant/command/ssh.rb
fixed-vagrant-0.7.4.dev lib/vagrant/command/ssh.rb
vagrant-0.7.3 lib/vagrant/command/ssh.rb
nixme-vagrant-0.7.2 lib/vagrant/command/ssh.rb
vagrant-0.7.2 lib/vagrant/command/ssh.rb
vagrant-0.7.1 lib/vagrant/command/ssh.rb