class VagrantPlugins::SecuredCloud::Action::WaitForState

This can be used with “Call” built-in to check if the machine is created and branch in the middleware.

Public Class Methods

new(app, env) click to toggle source
# File lib/secured-cloud-vagrant/actions/wait_for_state.rb, line 12
def initialize(app, env)
        @app = app
        @machine = env[:machine]
        @logger = Log4r::Logger.new('vagrant::secured_cloud::action::wait_for_state')
end

Public Instance Methods

call(env) click to toggle source
# File lib/secured-cloud-vagrant/actions/wait_for_state.rb, line 18
                    def call(env)
                    
                            @logger.debug("Waiting for VM state to be powered OFF ...")
                            
                            vm_resource_url = @machine.id
                            
                            if !vm_resource_url.nil? && !vm_resource_url.empty?
                            
                                    begin
                                      
                                      # Create a Secured Cloud Connection instance to connect tot he SecuredCloud API
  authInfo = @machine.provider_config.auth
  sc_connection = SecuredCloudConnection.new(authInfo.url, authInfo.applicationKey, authInfo.sharedSecret)
                                    
                                      # Get the VM details and check the power status
                                     while (SecuredCloudRestClient.getVMDetails(sc_connection, vm_resource_url).get_power_status == "POWERED_ON") do
                                              
                                              # Sleep for 2 seconds
    sleep 2
                                              
                                            end
                                            
                                    rescue Errno::ETIMEDOUT
                                            env[:ui].error(I18n.t("secured_cloud_vagrant.errors.request_timed_out", :request => "get the VM details"))
rescue Exception => e
  env[:ui].error(I18n.t("secured_cloud_vagrant.errors.generic_error", :error_message => e.message))
                                    end
                            end                                
                            
                            @app.call(env)
                    end