Class: Fog::XenServer::Connection
- Inherits:
-
Object
- Object
- Fog::XenServer::Connection
- Defined in:
- lib/fog/xenserver.rb
Instance Method Summary collapse
- #authenticate(username, password) ⇒ Object
-
#initialize(host) ⇒ Connection
constructor
A new instance of Connection.
- #request(options, *params) ⇒ Object
Constructor Details
#initialize(host) ⇒ Connection
Returns a new instance of Connection.
15 16 17 18 |
# File 'lib/fog/xenserver.rb', line 15 def initialize(host) @factory = XMLRPC::Client.new(host, '/') @factory.set_parser(XMLRPC::XMLParser::REXMLStreamParser.new) end |
Instance Method Details
#authenticate(username, password) ⇒ Object
20 21 22 23 24 |
# File 'lib/fog/xenserver.rb', line 20 def authenticate( username, password ) response = @factory.call('session.login_with_password', username, password ) raise Fog::XenServer::InvalidLogin.new unless response["Status"] =~ /Success/ @credentials = response["Value"] end |
#request(options, *params) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fog/xenserver.rb', line 26 def request(, *params) begin parser = .delete(:parser) method = .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 |