Module: VagrantPlugins::SoftLayer::Util::Warden
- Included in:
- Action::CreateInstance, Action::DestroyInstance, Action::JoinLoadBalancer, Action::LoadBalancerCleanup, Action::ReadSSHInfo, Action::ReadState, Action::RebuildInstance, Action::ResumeInstance, Action::StartInstance, Action::StopInstance, Action::SuspendInstance, Action::UpdateDNS, Action::WaitForProvision, Action::WaitForRebuild
- Defined in:
- lib/vagrant-softlayer/util/warden.rb
Instance Method Summary collapse
-
#sl_warden(rescue_proc = nil, retry_interval = 0, &block) ⇒ Object
Handles gracefully SoftLayer API calls.
Instance Method Details
#sl_warden(rescue_proc = nil, retry_interval = 0, &block) ⇒ Object
Handles gracefully SoftLayer API calls.
The block code is executed, catching both common connection errors and API exceptions.
Optionally, in the not-so-uncommon case when the object (e.g. the SoftLayer instance) is not found, executes a proc and/or retry the API call after some seconds.
A future version of the method will add a retry timeout.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vagrant-softlayer/util/warden.rb', line 16 def sl_warden(rescue_proc = nil, retry_interval = 0, &block) begin yield rescue ::OpenSSL::SSL::SSLError raise Errors::SLCertificateError rescue SocketError, ::SoftLayer::SoftLayerAPIException => e if e.class == ::SoftLayer::SoftLayerAPIException && (e..start_with?("Unable to find object") || e..start_with?("Object does not exist")) out = rescue_proc.call if rescue_proc if retry_interval > 0 sleep retry_interval retry else return out end else raise Errors::SLApiError, :class => e.class, :message => e. end end end |