class RhnSatellite::Connection::Handler

Attributes

default_hostname[RW]
default_https[W]
default_https_verify[RW]
default_password[RW]
default_timeout[W]
default_username[RW]

Public Class Methods

default_https() click to toggle source
# File lib/rhn_satellite/connection/handler.rb, line 26
def default_https
  @default_https.nil? ? (@default_https=true) : @default_https
end
default_timeout() click to toggle source
# File lib/rhn_satellite/connection/handler.rb, line 22
def default_timeout
  @default_timeout ||= 30
end
instance_for(identifier,hostname=nil,username=nil,password=nil,timeout=nil,https=nil,https_verify=nil) click to toggle source
# File lib/rhn_satellite/connection/handler.rb, line 11
def instance_for(identifier,hostname=nil,username=nil,password=nil,timeout=nil,https=nil,https_verify=nil)
    instances[identifier] ||= Handler.new(
        hostname||default_hostname,
        username||default_username,
        password||default_password,
        timeout || default_timeout,
        https.nil? ? default_https : https,
        https_verify.nil? ? default_https_verify : https_verify
    )
end
new(hostname,username=nil,password=nil,timeout=30,https=true,https_verify=true) click to toggle source
# File lib/rhn_satellite/connection/handler.rb, line 52
def initialize(hostname,username=nil,password=nil,timeout=30,https=true,https_verify=true)
    @hostname = hostname
    @username = username
    @password = password
    @timeout = timeout
    @https = https
    @https_verify = https_verify
end
reset_all() click to toggle source
# File lib/rhn_satellite/connection/handler.rb, line 38
def reset_all
  @instances = {}
end
reset_defaults() click to toggle source
# File lib/rhn_satellite/connection/handler.rb, line 42
def reset_defaults
  @default_hostname = @default_username = @default_password = @default_timeout = @default_https = nil
end
reset_instance(identifier) click to toggle source
# File lib/rhn_satellite/connection/handler.rb, line 34
def reset_instance(identifier)
    instances.delete(identifier)
end

Private Class Methods

instances() click to toggle source
# File lib/rhn_satellite/connection/handler.rb, line 47
def instances
    @instances ||= {}
end

Public Instance Methods

connect() click to toggle source
# File lib/rhn_satellite/connection/handler.rb, line 99
def connect
    debug("Connecting to #{url}")
    @connection = XMLRPC::Client.new2(url,nil,@timeout)
    if !@https_verify
      @connection.instance_variable_get(:@http).instance_variable_set(:@verify_mode, OpenSSL::SSL::VERIFY_NONE)
    end
    @connection
end
connected?() click to toggle source
# File lib/rhn_satellite/connection/handler.rb, line 95
def connected?
    !connection.nil?
end
default_call(cmd,*args) click to toggle source
# File lib/rhn_satellite/connection/handler.rb, line 112
def default_call(cmd,*args)
  in_transaction(true) {|token| make_call(cmd,token,*args) }
end
disconnect() click to toggle source
# File lib/rhn_satellite/connection/handler.rb, line 108
def disconnect
    @connection = nil
end
in_transaction(do_login=false) { |token| ... } click to toggle source
# File lib/rhn_satellite/connection/handler.rb, line 83
def in_transaction(do_login=false,&blk)
    begin
        begin_transaction
        token = do_login ? login : nil 
        result = yield(token)
        logout if do_login
    ensure
        end_transaction
    end
    result
end
login(duration=nil) click to toggle source
# File lib/rhn_satellite/connection/handler.rb, line 61
def login(duration=nil)
    @auth_token ||= make_call('auth.login', *[@username, @password, duration].compact)
end
logout() click to toggle source
# File lib/rhn_satellite/connection/handler.rb, line 65
def logout
    make_call('auth.logout',@auth_token) if @auth_token
    true
ensure
    @auth_token = nil
end
make_call(*args) click to toggle source

Makes a remote call.

# File lib/rhn_satellite/connection/handler.rb, line 74
def make_call(*args)
    raise "No connection established on #{@hostname}." unless connected?
    
    debug("Remote call: #{args.first} (#{args[1..-1].inspect})")
    result = connection.call(*args)
    debug("Result: #{result}\n")
    result
end

Private Instance Methods

api_path() click to toggle source
# File lib/rhn_satellite/connection/handler.rb, line 133
def api_path
   "/rpc/api" 
end
begin_transaction() click to toggle source
# File lib/rhn_satellite/connection/handler.rb, line 117
def begin_transaction
    connect
end
connection() click to toggle source
# File lib/rhn_satellite/connection/handler.rb, line 125
def connection
    @connection
end
end_transaction() click to toggle source

Ends a transaction and disconnects.

# File lib/rhn_satellite/connection/handler.rb, line 121
def end_transaction
    @connection = @auth_token = @version = nil
end
url() click to toggle source
# File lib/rhn_satellite/connection/handler.rb, line 129
def url
    @url ||= "#{@https ? 'https' : 'http'}://#{@hostname}#{api_path}"
end