Sha256: 4d52082c9f3c299700a9aa9a12c16fd4ce4cb909e9e1910c51ae851c59f57216

Contents?: true

Size: 1.04 KB

Versions: 37

Compression:

Stored size: 1.04 KB

Contents

require "log4r"

module VagrantPlugins
  module AWS
    module Action
      # This action reads the state of the machine and puts it in the
      # `:machine_state_id` key in the environment.
      class ReadState
        def initialize(app, env)
          @app    = app
          @logger = Log4r::Logger.new("vagrant_aws::action::read_state")
        end

        def call(env)
          env[:machine_state_id] = read_state(env[:aws_compute], env[:machine])

          @app.call(env)
        end

        def read_state(aws, machine)
          return :not_created if machine.id.nil?

          # Find the machine
          server = aws.servers.get(machine.id)
          if server.nil? || [:"shutting-down", :terminated].include?(server.state.to_sym)
            # The machine can't be found
            @logger.info("Machine not found or terminated, assuming it got destroyed.")
            machine.id = nil
            return :not_created
          end

          # Return the state
          return server.state.to_sym
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 10 rubygems

Version Path
vagrant-aws-mscottford-0.8.2 lib/vagrant-aws/action/read_state.rb
vagrant-aws-mscottford-0.8.1 lib/vagrant-aws/action/read_state.rb
vagrant-aws-mscottford-0.8.0 lib/vagrant-aws/action/read_state.rb
vagrant-gecko-aws-0.8.0 lib/vagrant-aws/action/read_state.rb
vagrant-aws-mkubenka-0.7.2.pre.24 lib/vagrant-aws/action/read_state.rb
vagrant-aws-detiber-0.7.2.pre.4 lib/vagrant-aws/action/read_state.rb
vagrant-aws-detiber-0.7.2.pre.3 lib/vagrant-aws/action/read_state.rb
vagrant-aws-detiber-0.7.2.pre.2 lib/vagrant-aws/action/read_state.rb
vagrant-aws-mkubenka-0.7.2.pre.22 lib/vagrant-aws/action/read_state.rb
vagrant-aws-mkubenka-0.7.2.pre.16 lib/vagrant-aws/action/read_state.rb
vagrant-aws-iam-decoder-0.7.2 lib/vagrant-aws/action/read_state.rb
vagrant-aws-mkubenka-0.7.2.pre.14 lib/vagrant-aws/action/read_state.rb
vagrant-aws-mkubenka-0.7.2.pre.11 lib/vagrant-aws/action/read_state.rb
vagrant-aws-mkubenka-0.7.2.pre.10 lib/vagrant-aws/action/read_state.rb
vagrant-aws-mkubenka-0.7.2.pre.9 lib/vagrant-aws/action/read_state.rb
vagrant-aws-mkubenka-0.7.2.pre.8 lib/vagrant-aws/action/read_state.rb
vagrant-aws-0.7.2 lib/vagrant-aws/action/read_state.rb
vagrant-aws-0.7.1 lib/vagrant-aws/action/read_state.rb
vagrant-aws-0.7.0 lib/vagrant-aws/action/read_state.rb
vagrant-aws-0.6.0 lib/vagrant-aws/action/read_state.rb