Class: OpenNebula::GRPCClient
- Inherits:
-
Object
- Object
- OpenNebula::GRPCClient
- Defined in:
- lib/opennebula/lib/grpc_client.rb
Constant Summary collapse
- GRPC_MAP =
gRPC mappings from OpenNebula actions to gRPC actions
GRPCMappings::MapLoader.load
Instance Method Summary collapse
- #call(action, *args) ⇒ Object
-
#initialize(secret, endpoint, options = {}) ⇒ OpenNebula::GRPCClient
constructor
Creates a new gRPC client object that will be used to call OpenNebula functions.
Constructor Details
#initialize(secret, endpoint, options = {}) ⇒ OpenNebula::GRPCClient
Creates a new gRPC client object that will be used to call OpenNebula functions.
41 42 43 44 45 |
# File 'lib/opennebula/lib/grpc_client.rb', line 41 def initialize(secret, endpoint, = {}) @one_auth = secret @one_endpoint = endpoint @timeout = [:timeout] || ENV['ONE_GRPC_TIMEOUT']&.to_i end |
Instance Method Details
#call(action, *args) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/opennebula/lib/grpc_client.rb', line 47 def call(action, *args) handler = GRPC_MAP[action] raise Error.new("Method 'one.#{action}' not defined", Error::EGRPC_CALL) unless handler = {} [:deadline] = Time.now.to_i + @timeout if @timeout response = handler.call(@one_auth, @one_endpoint, *args, ) if response.respond_to?(:oid) response.oid elsif response.respond_to?(:xml) response.xml else Error.new("Unexpected response: #{response.inspect}", Error::EGRPC_CALL) end rescue GRPC::DeadlineExceeded Error.new("Timeout exceeded for gRPC call '#{action}'", Error::ETIMEOUT) rescue GRPC::Unavailable => e Error.new("#{action}: #{(e.)}", Error::EGRPC_CALL) rescue GRPC::BadStatus => e Error.new((e.), grpc_code_to_one(e.code)) rescue StandardError => e Error.new("#{action}: #{e.}", Error::EGRPC_CALL) end |