Skip to content

Commit

Permalink
Merge pull request #73 from zozoh94/redirect_to_master
Browse files Browse the repository at this point in the history
Support of master/slave
  • Loading branch information
plribeiro3000 committed May 7, 2018
2 parents c1c6d24 + 6968456 commit 31b629c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/fog/compute/xen_server/real.rb
Expand Up @@ -13,8 +13,15 @@ def initialize(options={})
@use_ssl = options[:xenserver_use_ssl] || false
@port = options[:xenserver_port] || 80
@verify_mode = options[:xenserver_verify_mode] || OpenSSL::SSL::VERIFY_PEER
@connection = Fog::XenServer::Connection.new(@host, @port, @use_ssl, @verify_mode, @timeout)
@connection = Fog::XenServer::Connection.new(
@host, @port, @use_ssl, @verify_mode, @timeout)

@connection.authenticate(@username, @password)

if @connection.slave?
@connection = Fog::XenServer::Connection.new(@connection.master, @port, @use_ssl, @verify_mode, @timeout)
@connection.authenticate(@username, @password)
end
end

def reload
Expand Down
19 changes: 19 additions & 0 deletions lib/fog/xen_server/connection.rb
Expand Up @@ -4,6 +4,7 @@ module Fog
module XenServer
class Connection
attr_reader :credentials
private :master_slave_request

def initialize(host, port, use_ssl, verify_mode, timeout)
@factory = XMLRPC::Client.new3(host: host, port: port, use_ssl: use_ssl, path: "/")
Expand All @@ -12,6 +13,24 @@ def initialize(host, port, use_ssl, verify_mode, timeout)
@factory.timeout = timeout
end

def master_slave_request
if @ms_response.nil?
@ms_response = @factory.call("host.get_all_records", @credentials)
end
end

def slave?
master_slave_request
@ms_response["Status"] == "Failure"
end

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

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/
Expand Down

0 comments on commit 31b629c

Please sign in to comment.