Sha256: 83dc7bf42f1cefafbc07f7d06b80b3061687eb03032c06b5a78ec91a1d9ee86c

Contents?: true

Size: 1.41 KB

Versions: 7

Compression:

Stored size: 1.41 KB

Contents

require 'log4r'
require 'vagrant-ovirt4/util/timer'
require 'vagrant/util/retryable'

module VagrantPlugins
  module OVirtProvider
    module Action

      # Wait till VM is stopped
      class WaitTillDown
        include Vagrant::Util::Retryable

        def initialize(app, env)
          @logger = Log4r::Logger.new("vagrant_ovirt4::action::wait_till_down")
          @app = app
        end

        def call(env)
          vm_service = env[:vms_service].vm_service(env[:machine].id)

          env[:ui].info(I18n.t("vagrant_ovirt4.wait_till_down"))
          for i in 1..300
            ready = true
            begin
              if vm_service.get == nil
                raise NoVMError, :error_message => '', :vm_id => env[:machine].id
              end
            rescue OvirtSDK4::Error => e
              fault_message = /Fault detail is \"\[?(.+?)\]?\".*/.match(e.message)[1] rescue e.message
              if config.debug
                raise e
              else
                raise Errors::NoVMError, :error_message => fault_message, :vm_id => env[:machine].id
              end
            end



            if vm_service.get.status.to_sym != :down
              ready = false
            end
            break if ready
            sleep 2
          end

          if not ready
            raise Errors::WaitForShutdownVmTimeout
          end

          
          @app.call(env)
        end

      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
vagrant-ovirt4-2.2.0 lib/vagrant-ovirt4/action/wait_till_down.rb
vagrant-ovirt4-2.1.3 lib/vagrant-ovirt4/action/wait_till_down.rb
vagrant-ovirt4-2.1.0 lib/vagrant-ovirt4/action/wait_till_down.rb
vagrant-ovirt4-2.0.0 lib/vagrant-ovirt4/action/wait_till_down.rb
vagrant-ovirt4-1.2.3 lib/vagrant-ovirt4/action/wait_till_down.rb
vagrant-ovirt4-1.2.2 lib/vagrant-ovirt4/action/wait_till_down.rb
vagrant-ovirt4-1.2.1 lib/vagrant-ovirt4/action/wait_till_down.rb