Sha256: 35c69bf573dba7ffb714e779426dc558d94c3f46f38b1f34fa91e2a628685c66

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require 'log4r'

module VagrantPlugins
  module Rimu
    module Actions
      # 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
          @machine = env[:machine]
          @logger = Log4r::Logger.new("vagrant_rimu::action::read_ssh_info")
        end

        def call(env)
          client = env[:rimu_api]
          env[:machine_ssh_info] = read_ssh_info(client, @machine)

          @app.call(env)
        end

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

          # Find the machine
          server = client.orders.order(machine.id.to_i)
          if server.nil?
            # The machine can't be found
            @logger.info("Machine couldn't be found, assuming it got destroyed.")
            machine.id = nil
            return nil
          end

          return {
            :host => server.allocated_ips["primary_ip"],
            :port => 22,
            :username => "root"
          }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-rimu-0.0.2 lib/vagrant-rimu/actions/read_ssh_info.rb