Sha256: ff4b8ecd8823d38438531e2aa8a3d3fcf4e9f305d0fe462ba0cb99ec52e70425

Contents?: true

Size: 1.02 KB

Versions: 11

Compression:

Stored size: 1.02 KB

Contents

require "log4r"

module VagrantPlugins
  module Shell
    module Action
      # This action reads the SSH info for the machine and puts it into the
      # `:machine_ssh_info` key in the environment.
      class ReadSSHInfo
        def initialize(app, env)
          @app    = app
          @logger = Log4r::Logger.new("vagrant_shell::action::read_ssh_info")
        end

        def call(env)
          env[:machine_ssh_info] = read_ssh_info(env[:machine])

          @app.call(env)
        end

        def read_ssh_info(machine)
          return nil if machine.id.nil?

          # Read the DNS info
          output = %x{ #{machine.provider_config.script} ssh-info #{machine.id} }
          if $?.to_i > 0
            raise Errors::ShellError, :message => "Failure: #{env[:machine].provider_config.script} ssh-info #{machine.id}"
          end

          host,port = output.split(/\s+/)[0,2] # TODO check formatting
          return {
            :host => host,
            :port => port
          }
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
vagrant-shell-0.2.22 lib/vagrant-shell/action/read_ssh_info.rb
vagrant-shell-0.2.21 lib/vagrant-shell/action/read_ssh_info.rb
vagrant-shell-0.2.20 lib/vagrant-shell/action/read_ssh_info.rb
vagrant-shell-0.2.19 lib/vagrant-shell/action/read_ssh_info.rb
vagrant-shell-0.2.17 lib/vagrant-shell/action/read_ssh_info.rb
vagrant-shell-0.2.16 lib/vagrant-shell/action/read_ssh_info.rb
vagrant-shell-0.2.15 lib/vagrant-shell/action/read_ssh_info.rb
vagrant-shell-0.2.13 lib/vagrant-shell/action/read_ssh_info.rb
vagrant-shell-0.2.12 lib/vagrant-shell/action/read_ssh_info.rb
vagrant-shell-0.2.9 lib/vagrant-shell/action/read_ssh_info.rb
vagrant-shell-0.2.8 lib/vagrant-shell/action/read_ssh_info.rb