1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Fixed the issue according pool request #3356

This commit is contained in:
ooVoo LLC 2014-12-21 20:01:40 +02:00
parent 09c33efabc
commit ae509d43d0
2 changed files with 31 additions and 23 deletions

View file

@ -11,6 +11,7 @@ module Fog
requires :xenserver_url requires :xenserver_url
recognizes :xenserver_defaults recognizes :xenserver_defaults
recognizes :xenserver_timeout recognizes :xenserver_timeout
recognizes :xenserver_redirect_to_master
model_path 'fog/xenserver/models/compute' model_path 'fog/xenserver/models/compute'
model :blob model :blob
@ -117,18 +118,24 @@ module Fog
attr_reader :connection attr_reader :connection
def initialize(options={}) def initialize(options={})
@host = options[:xenserver_url] @host = options[:xenserver_url]
@username = options[:xenserver_username] @username = options[:xenserver_username]
@password = options[:xenserver_password] @password = options[:xenserver_password]
@defaults = options[:xenserver_defaults] || {} @defaults = options[:xenserver_defaults] || {}
@timeout = options[:xenserver_timeout] || 30 @timeout = options[:xenserver_timeout] || 30
@connection = Fog::XenServer::Connection.new(@host, @timeout) @redirect_to_master = options[:xenserver_redirect_to_master] || false
host_master = @connection.find_pool_master(@username, @password) @connection = Fog::XenServer::Connection.new(@host, @timeout)
if host_master!= @host
@host = host_master; if @redirect_to_master == false
@connection = Fog::XenServer::Connection.new(@host, @timeout) @connection = Fog::XenServer::Connection.new(@host, @timeout)
end elsif @redirect_to_master == true
@connection.authenticate(@username, @password) host_master = @connection.find_pool_master(@username, @password)
if host_master && host_master!= @host
@host = host_master;
@connection = Fog::XenServer::Connection.new(@host, @timeout)
end
end
@connection.authenticate(@username, @password)
end end
def reload def reload

View file

@ -13,7 +13,6 @@ module Fog
class Connection class Connection
require 'xmlrpc/client' require 'xmlrpc/client'
attr_reader :credentials attr_reader :credentials
def initialize(host, timeout) def initialize(host, timeout)
@ -23,18 +22,20 @@ module Fog
end end
def find_pool_master( username, password ) def find_pool_master( username, password )
response = @factory.call('session.login_with_password', username.to_s, password.to_s) @credentials = authenticate( username, password )
raise Fog::XenServer::InvalidLogin.new unless response["Status"] =~ /Success/ response = @factory.call('host.get_all_records', @credentials)
@credentials = response["Value"] if response['Status'] == "Failure"
response = @factory.call('host.get_all_records', @credentials) if response['ErrorDescription'][0] == "HOST_IS_SLAVE"
if response['Status'] == "Failure" ip_address = response['ErrorDescription'][1]
if response['ErrorDescription'][0] == "HOST_IS_SLAVE" ip_address = ip_address.chomp
response['ErrorDescription'][1] valid = !(IPAddr.new(ip_address) rescue nil).nil?
end if valid
end response['ErrorDescription'][1]
end
end
end
end end
def authenticate( username, password ) def authenticate( username, password )
response = @factory.call('session.login_with_password', username.to_s, password.to_s) response = @factory.call('session.login_with_password', username.to_s, password.to_s)
raise Fog::XenServer::InvalidLogin.new unless response["Status"] =~ /Success/ raise Fog::XenServer::InvalidLogin.new unless response["Status"] =~ /Success/