Class: Berta::Utils::OpenNebula::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/berta/utils/opennebula/helper.rb

Overview

Class designed to help with working with OpenNebula

Constant Summary collapse

ERRORS =

Hash of errors that can be returned by opennebula

Hash.new(Berta::Errors::OpenNebula::ResourceRetrievalError)
.update(::OpenNebula::Error::EAUTHENTICATION => Berta::Errors::OpenNebula::AuthenticationError,
        ::OpenNebula::Error::EAUTHORIZATION => Berta::Errors::OpenNebula::UserNotAuthorizedError,
        ::OpenNebula::Error::ENO_EXISTS => Berta::Errors::OpenNebula::ResourceNotFoundError,
        ::OpenNebula::Error::EACTION => Berta::Errors::OpenNebula::ResourceStateError)
.freeze

Class Method Summary collapse

Class Method Details

.decode_error(errno) ⇒ Berta::Errors::OpenNebula::AuthenticationError, ...

Decodes OpenNebula error codes into exceptions and returns them



38
39
40
# File 'lib/berta/utils/opennebula/helper.rb', line 38

def decode_error(errno)
  ERRORS[errno]
end

.handle_errorObject

Handles OpenNebula error codes and turns them into exceptions



23
24
25
26
27
28
# File 'lib/berta/utils/opennebula/helper.rb', line 23

def handle_error
  raise Berta::Errors::OpenNebula::StubError, 'OpenNebula service-wrapper was called without a block!' unless block_given?
  return_value = yield
  return return_value unless ::OpenNebula.is_error?(return_value)
  raise decode_error(return_value.errno), return_value.message
end