Sha256: 61352d2725fc6205921a701d28c8592793283036c8360d2695bd00f574baa54a

Contents?: true

Size: 1.46 KB

Versions: 19

Compression:

Stored size: 1.46 KB

Contents

require "log4r"

module Vagrant
  module Action
    module Builtin
      # This class will run a single command on the remote machine and will
      # mirror the output to the UI. The resulting exit status of the command
      # will exist in the `:ssh_run_exit_status` key in the environment.
      class SSHRun
        def initialize(app, env)
          @app    = app
          @logger = Log4r::Logger.new("vagrant::action::builtin::ssh_run")
        end

        def call(env)
          command = env[:ssh_run_command]

          @logger.debug("Executing command: #{command}")
          exit_status = 0
          exit_status = env[:machine].communicate.execute(command, :error_check => false) do |type, data|
            # Determine the proper channel to send the output onto depending
            # on the type of data we are receiving.
            channel = type == :stdout ? :out : :error

            # Print the output as it comes in, but don't prefix it and don't
            # force a new line so that the output is properly preserved however
            # it may be formatted.
            env[:ui].info(data.to_s,
                          :prefix => false,
                          :new_line => false,
                          :channel => channel)
          end

          # Set the exit status on a known environmental variable
          env[:ssh_run_exit_status] = exit_status

          # Call the next middleware
          @app.call(env)
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 6 rubygems

Version Path
tamtam-vagrant-reload-1.1.3 vendor/cache/vagrant-0ac2a8738841/lib/vagrant/action/builtin/ssh_run.rb
tamtam-vagrant-reload-1.1.2 vendor/cache/vagrant-0ac2a8738841/lib/vagrant/action/builtin/ssh_run.rb
tamtam-vagrant-reload-1.1.1 vendor/cache/vagrant-0ac2a8738841/lib/vagrant/action/builtin/ssh_run.rb
tamtam-vagrant-reload-1.1 vendor/cache/vagrant-0ac2a8738841/lib/vagrant/action/builtin/ssh_run.rb
tnargav-1.3.6 lib/vagrant/action/builtin/ssh_run.rb
tnargav-1.3.3 lib/vagrant/action/builtin/ssh_run.rb
vagrant-shell-0.2.9 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/lib/vagrant/action/builtin/ssh_run.rb
tnargav-1.2.3 lib/vagrant/action/builtin/ssh_run.rb
vagrant-shell-0.2.8 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/lib/vagrant/action/builtin/ssh_run.rb
vagrant-shell-0.2.6 vendor/bundle/gems/tnargav-1.2.2/lib/vagrant/action/builtin/ssh_run.rb
vagrant-shell-0.2.5 vendor/bundle/gems/tnargav-1.2.2/lib/vagrant/action/builtin/ssh_run.rb
tnargav-1.2.2 lib/vagrant/action/builtin/ssh_run.rb
vagrantup-1.1.3 lib/vagrant/action/builtin/ssh_run.rb
vagrantup-1.1.2 lib/vagrant/action/builtin/ssh_run.rb
vagrantup-1.1.1 lib/vagrant/action/builtin/ssh_run.rb
vagrantup-1.1.0 lib/vagrant/action/builtin/ssh_run.rb
vagrantup-1.1.4 lib/vagrant/action/builtin/ssh_run.rb
vagrant-actionio-0.0.9 vendor/bundle/bundler/gems/vagrant-c74251a1d9c0/lib/vagrant/action/builtin/ssh_run.rb
vagrant-lxc-0.0.1 vendor/vagrant/lib/vagrant/action/builtin/ssh_run.rb