Class: Fog::XenServer::Connection
- Inherits:
-
Object
- Object
- Fog::XenServer::Connection
- Defined in:
- lib/fog/xenserver/connection.rb
Instance Attribute Summary collapse
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
Instance Method Summary collapse
- #authenticate(username, password) ⇒ Object
-
#initialize(host, port, use_ssl, verify_mode, timeout) ⇒ Connection
constructor
A new instance of Connection.
- #master ⇒ Object
- #request(options, *params) ⇒ Object
- #slave? ⇒ Boolean
Constructor Details
#initialize(host, port, use_ssl, verify_mode, timeout) ⇒ Connection
Returns a new instance of Connection.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/fog/xenserver/connection.rb', line 8 def initialize(host, port, use_ssl, verify_mode, timeout) @factory = XMLRPC::Client.new3(host: host, port: port, use_ssl: use_ssl, path: "/") if @factory.respond_to?(:http) @factory.http.verify_mode = verify_mode else @factory.instance_variable_get(:@http).verify_mode = verify_mode end @factory.set_parser(NokogiriStreamParser.new) @factory.timeout = timeout end |
Instance Attribute Details
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
6 7 8 |
# File 'lib/fog/xenserver/connection.rb', line 6 def credentials @credentials end |
Instance Method Details
#authenticate(username, password) ⇒ Object
31 32 33 34 35 |
# File 'lib/fog/xenserver/connection.rb', line 31 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 |
#master ⇒ Object
24 25 26 27 28 29 |
# File 'lib/fog/xenserver/connection.rb', line 24 def master master_slave_request return if @ms_response["ErrorDescription"].nil? return unless @ms_response["ErrorDescription"][0] == "HOST_IS_SLAVE" @ms_response["ErrorDescription"][1] end |
#request(options, *params) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/fog/xenserver/connection.rb', line 37 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) elsif params.length.eql?(1) and params.last.is_a?(Array) response = @factory.call(method, @credentials, params.first) 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 |
#slave? ⇒ Boolean
19 20 21 22 |
# File 'lib/fog/xenserver/connection.rb', line 19 def slave? master_slave_request @ms_response["Status"] == "Failure" end |