Class: OpenNebula::Client
- Inherits:
-
Object
- Object
- OpenNebula::Client
- Defined in:
- lib/opennebula/lib/client.rb
Constant Summary collapse
- NO_ONE_AUTH_ERROR =
'ONE_AUTH file not present'- GRPC_NOT_SUPPORTED =
'gRPC API not supported'
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#one_auth ⇒ Object
readonly
Returns the value of attribute one_auth.
-
#one_endpoint ⇒ Object
readonly
Returns the value of attribute one_endpoint.
-
#one_zmq ⇒ Object
readonly
Returns the value of attribute one_zmq.
Instance Method Summary collapse
- #call(action, *args) ⇒ Object
- #get_version ⇒ Object
-
#initialize(secret = nil, endpoint = nil, options = {}) ⇒ OpenNebula::XMLClient || OpenNebula::GRPCClient
constructor
Initialize an OpenNebula client.
- #mk_endpoint(endpoint, env_var, default) ⇒ Object
Constructor Details
#initialize(secret = nil, endpoint = nil, options = {}) ⇒ OpenNebula::XMLClient || OpenNebula::GRPCClient
Initialize an OpenNebula client
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/opennebula/lib/client.rb', line 54 def initialize(secret = nil, endpoint = nil, = {}) if [:subscriber_endpoint] @one_zmq = [:subscriber_endpoint] elsif ENV['ONE_ZMQ'] @one_zmq = ENV['ONE_ZMQ'] else @one_zmq = 'tcp://localhost:2101' end auth_file = File.join(ENV['HOME'], '/.one/one_auth') one_auth_file = '/var/lib/one/.one/one_auth' @one_auth = if secret secret elsif ENV['ONE_AUTH'] && File.file?(ENV['ONE_AUTH']) File.read(ENV['ONE_AUTH']) elsif File.file?(auth_file) File.read(auth_file) elsif File.file?(one_auth_file) File.read(one_auth_file) else raise NO_ONE_AUTH_ERROR end @one_auth = @one_auth.rstrip is_grpc = ENV['ONEAPI_PROTOCOL'] == 'grpc' || .key?(:grpc) # Override protocol from endpoint name, if endpoint is defined is_grpc = !endpoint.include?('RPC2') if !endpoint.nil? && !endpoint.empty? if is_grpc begin require_relative 'grpc_client' rescue LoadError raise GRPC_NOT_SUPPORTED end @one_endpoint = mk_endpoint(endpoint, 'ONE_GRPC', 'localhost:2634').rstrip @client = GRPCClient.new(@one_auth, @one_endpoint, ) else require_relative 'xml_client' @one_endpoint = mk_endpoint(endpoint, 'ONE_XMLRPC', 'http://localhost:2633/RPC2').rstrip @client = XMLClient.new(@one_auth, @one_endpoint, ) end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
42 43 44 |
# File 'lib/opennebula/lib/client.rb', line 42 def client @client end |
#one_auth ⇒ Object (readonly)
Returns the value of attribute one_auth.
42 43 44 |
# File 'lib/opennebula/lib/client.rb', line 42 def one_auth @one_auth end |
#one_endpoint ⇒ Object (readonly)
Returns the value of attribute one_endpoint.
42 43 44 |
# File 'lib/opennebula/lib/client.rb', line 42 def one_endpoint @one_endpoint end |
#one_zmq ⇒ Object (readonly)
Returns the value of attribute one_zmq.
42 43 44 |
# File 'lib/opennebula/lib/client.rb', line 42 def one_zmq @one_zmq end |
Instance Method Details
#call(action, *args) ⇒ Object
107 108 109 |
# File 'lib/opennebula/lib/client.rb', line 107 def call(action, *args) @client.call(action, *args) end |
#get_version ⇒ Object
111 112 113 |
# File 'lib/opennebula/lib/client.rb', line 111 def get_version call('system.version') end |
#mk_endpoint(endpoint, env_var, default) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/opennebula/lib/client.rb', line 115 def mk_endpoint(endpoint, env_var, default) ep_file = File.join(ENV['HOME'], '/.one/one_endpoint') one_ep_file = '/var/lib/one/.one/one_endpoint' if endpoint endpoint elsif ENV[env_var] ENV[env_var] elsif File.exist?(ep_file) File.read(ep_file) elsif File.exist?(one_ep_file) File.read(one_ep_file) else default end end |