class Fog::XenServer::Connection
Attributes
credentials[R]
Public Class Methods
new(host, timeout)
click to toggle source
# File lib/fog/xenserver/core.rb, line 18 def initialize(host, timeout) @factory = XMLRPC::Client.new(host, '/') @factory.set_parser(NokogiriStreamParser.new) @factory.timeout = timeout end
Public Instance Methods
authenticate( username, password )
click to toggle source
# File lib/fog/xenserver/core.rb, line 39 def authenticate( username, password ) response = @factory.call('session.login_with_password', username.to_s, password.to_s) raise Fog::XenServer::InvalidLogin.new unless response["Status"] =~ /Success/ @credentials = response["Value"] end
find_pool_master( username, password )
click to toggle source
# File lib/fog/xenserver/core.rb, line 24 def find_pool_master( username, password ) @credentials = authenticate( username, password ) response = @factory.call('host.get_all_records', @credentials) if response['Status'] == "Failure" if response['ErrorDescription'][0] == "HOST_IS_SLAVE" ip_address = response['ErrorDescription'][1] ip_address = ip_address.chomp valid = !(IPAddr.new(ip_address) rescue nil).nil? if valid response['ErrorDescription'][1] end end end end
request(options, *params)
click to toggle source
# File lib/fog/xenserver/core.rb, line 45 def request(options, *params) begin parser = options.delete(:parser) method = options.delete(:method) if params.empty? response = @factory.call(method, @credentials) else if params.length.eql?(1) and params.first.is_a?(Hash) response = @factory.call(method, @credentials, params.first) elsif params.length.eql?(2) and params.last.is_a?(Array) response = @factory.call(method, @credentials, params.first, params.last) else response = eval("@factory.call('#{method}', '#{@credentials}', #{params.map {|p| p.is_a?(String) ? "'#{p}'" : p}.join(',')})") end end raise RequestFailed.new("#{method}: " + response["ErrorDescription"].to_s) unless response["Status"].eql? "Success" if parser parser.parse( response["Value"] ) response = parser.response end response end end