lib/fog/xenserver/core.rb in fog-1.29.0 vs lib/fog/xenserver/core.rb in fog-1.30.0
- old
+ new
@@ -4,11 +4,19 @@
module Fog
module XenServer
class InvalidLogin < Fog::Errors::Error; end
class NotFound < Fog::Errors::Error; end
class RequestFailed < Fog::Errors::Error; end
+ class HostIsSlave < Fog::Errors::Error
+ attr_reader :master_ip
+ def initialize(master_ip)
+ @master_ip = master_ip
+ end
+
+ end
+
extend Fog::Provider
service(:compute, 'Compute')
class Connection
@@ -19,27 +27,19 @@
@factory = XMLRPC::Client.new(host, '/')
@factory.set_parser(NokogiriStreamParser.new)
@factory.timeout = timeout
end
- 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
-
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/
+ if response['Status'] == 'Failure'
+ if response['ErrorDescription'][0] == 'HOST_IS_SLAVE'
+ master_ip = response['ErrorDescription'][1]
+ raise Fog::XenServer::HostIsSlave.new(master_ip)
+ else
+ raise Fog::XenServer::InvalidLogin.new
+ end
+ end
@credentials = response["Value"]
end
def request(options, *params)
begin