Sha256: 309bc54dc2580b266cdfa757c550d3f0ee1bb06c97fc8501a4ea1fa74d487365

Contents?: true

Size: 1.33 KB

Versions: 8

Compression:

Stored size: 1.33 KB

Contents

require 'log4r'

require 'vagrant-deltacloud-provider/action/abstract_action'
require 'vagrant-deltacloud-provider/client/deltacloud'

module VagrantPlugins
  module Deltacloud
    module Action
      # This action reads the state of the machine and puts it in the
      # `:machine_state_id` key in the environment.
      class ReadState < AbstractAction
        def initialize(app, _env)
          @app    = app
          @logger = Log4r::Logger.new('vagrant_deltacloud::action::read_state')
        end

        def execute(env)
          env[:machine_state_id] = read_state(env)
          env[:deltacloud_client] = Deltacloud::DeltacloudClient.instance
          @app.call(env)
        end

        def read_state(env)
          machine = env[:machine]
          env[:deltacloud_client] = Deltacloud::DeltacloudClient.instance
          return :not_created if machine.id.nil?

          # Find the machine
          server = env[:deltacloud_client].get_instance_details(env, machine.id)
          if server.nil? || server.status == 'DELETED'
            # The machine can't be found
            @logger.info('Machine not found or deleted, assuming it got destroyed.')
            machine.id = nil
            return :not_created
          end

          # Return the state
          server.status.downcase.to_sym
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
vagrant-deltacloud-provider-0.0.9 lib/vagrant-deltacloud-provider/action/read_state.rb
vagrant-deltacloud-provider-0.0.8 lib/vagrant-deltacloud-provider/action/read_state.rb
vagrant-deltacloud-provider-0.0.7 lib/vagrant-deltacloud-provider/action/read_state.rb
vagrant-deltacloud-provider-0.0.6 lib/vagrant-deltacloud-provider/action/read_state.rb
vagrant-deltacloud-provider-0.0.5 lib/vagrant-deltacloud-provider/action/read_state.rb
vagrant-deltacloud-provider-0.0.4 lib/vagrant-deltacloud-provider/action/read_state.rb
vagrant-deltacloud-provider-0.0.3 lib/vagrant-deltacloud-provider/action/read_state.rb
vagrant-deltacloud-provider-0.0.2 lib/vagrant-deltacloud-provider/action/read_state.rb