Class: VagrantPlugins::OpenStack::Action::WaitForTask
- Inherits:
-
Object
- Object
- VagrantPlugins::OpenStack::Action::WaitForTask
- Defined in:
- lib/vagrant-openstack-plugin/action/wait_for_task.rb
Overview
This action will wait for a machine to reach a specific state or quit by timeout.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #get_task(env) ⇒ Object
-
#initialize(app, env, task, timeout) ⇒ WaitForTask
constructor
A new instance of WaitForTask.
Constructor Details
#initialize(app, env, task, timeout) ⇒ WaitForTask
Returns a new instance of WaitForTask.
10 11 12 13 14 15 |
# File 'lib/vagrant-openstack-plugin/action/wait_for_task.rb', line 10 def initialize(app, env, task, timeout) @app = app @logger = Log4r::Logger.new('vagrant_openstack::action::wait_for_task') @task = Array.new(task).flatten @timeout = timeout end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/vagrant-openstack-plugin/action/wait_for_task.rb', line 17 def call(env) env[:result] = true task = get_task(env) if @task.include?(task) @logger.info("Machine already at task #{ task.to_s }") else @logger.info("Waiting for machine to reach task...") begin Timeout.timeout(@timeout) do sleep 5 until @task.include?(get_task(env)) end rescue Timeout::Error env[:result] = false end @app.call(env) end end |
#get_task(env) ⇒ Object
37 38 39 40 |
# File 'lib/vagrant-openstack-plugin/action/wait_for_task.rb', line 37 def get_task(env) infos = env[:openstack_compute].get_server_details(env[:machine].id) infos.body['server']['OS-EXT-STS:task_state'] end |