class ManageIQ::API::Client
Constants
- DEFAULT_URL
- VERSION
Attributes
api[R]
authentication[R]
client_options[R]
collections[R]
connection[R]
identity[R]
logger[R]
product_info[R]
server_info[R]
url[R]
user_settings[R]
Public Class Methods
logger()
click to toggle source
# File lib/manageiq/api/client/client.rb, line 20 def self.logger @logger ||= NullLogger.new end
logger=(logger)
click to toggle source
# File lib/manageiq/api/client/client.rb, line 24 def self.logger=(logger) @logger = logger end
new(client_options = {})
click to toggle source
# File lib/manageiq/api/client/client.rb, line 28 def initialize(client_options = {}) @client_options = client_options.dup @logger = client_options[:logger] || self.class.logger @url = extract_url(client_options) @authentication = ManageIQ::API::Client::Authentication.new(client_options) reconnect end
Public Instance Methods
load_definitions()
click to toggle source
# File lib/manageiq/api/client/client.rb, line 36 def load_definitions entrypoint = connection.get("", :attributes => "authorization") @api = ManageIQ::API::Client::API.new(entrypoint) @user_settings = Hash(entrypoint["settings"]).dup @identity = ManageIQ::API::Client::Identity.new(Hash(entrypoint["identity"])) @authorization = Hash(entrypoint["authorization"]).dup @server_info = ServerInfo.new(Hash(entrypoint["server_info"])) @product_info = ProductInfo.new(Hash(entrypoint["product_info"])) @collections = load_collections(entrypoint["collections"]) end
reconnect()
click to toggle source
# File lib/manageiq/api/client/client.rb, line 60 def reconnect @connection = ManageIQ::API::Client::Connection.new(self, client_options.slice(:ssl, :open_timeout, :timeout)) load_definitions end
update_authentication(auth_options = {})
click to toggle source
# File lib/manageiq/api/client/client.rb, line 47 def update_authentication(auth_options = {}) return @authentication unless ManageIQ::API::Client::Authentication.auth_options_specified?(auth_options) saved_auth = @authentication @authentication = ManageIQ::API::Client::Authentication.new(auth_options) begin reconnect rescue @authentication = saved_auth raise end @authentication end
Private Instance Methods
create_method(name, &block)
click to toggle source
# File lib/manageiq/api/client/client.rb, line 86 def create_method(name, &block) self.class.send(:define_method, name, &block) end
extract_url(options)
click to toggle source
# File lib/manageiq/api/client/client.rb, line 78 def extract_url(options) url = options[:url] || DEFAULT_URL url = URI.parse(url) unless url.kind_of?(URI) url rescue raise "Malformed ManageIQ Appliance URL #{url} specified" end
load_collections(collection_list)
click to toggle source
# File lib/manageiq/api/client/client.rb, line 69 def load_collections(collection_list) collection_list.collect do |collection_def| klass = ManageIQ::API::Client::Collection.subclass(collection_def["name"]) collection = klass.new(self, collection_def) create_method(collection.name.to_sym) { collection } collection end end