Class: RhnSatellite::Connection::Handler

Inherits:
Object
  • Object
show all
Includes:
RhnSatellite::Common::Debug
Defined in:
lib/rhn_satellite/connection/handler.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RhnSatellite::Common::Debug

#debug, included

Constructor Details

#initialize(hostname, username = nil, password = nil, timeout = 30, https = true, https_verify = true) ⇒ Handler

Returns a new instance of Handler.



52
53
54
55
56
57
58
59
# 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

Class Attribute Details

.default_hostnameObject

Returns the value of attribute default_hostname.



8
9
10
# File 'lib/rhn_satellite/connection/handler.rb', line 8

def default_hostname
  @default_hostname
end

.default_httpsObject



26
27
28
# File 'lib/rhn_satellite/connection/handler.rb', line 26

def default_https
  @default_https.nil? ? (@default_https=true) : @default_https
end

.default_https_verifyObject

Returns the value of attribute default_https_verify.



8
9
10
# File 'lib/rhn_satellite/connection/handler.rb', line 8

def default_https_verify
  @default_https_verify
end

.default_passwordObject

Returns the value of attribute default_password.



8
9
10
# File 'lib/rhn_satellite/connection/handler.rb', line 8

def default_password
  @default_password
end

.default_timeoutObject



22
23
24
# File 'lib/rhn_satellite/connection/handler.rb', line 22

def default_timeout
  @default_timeout ||= 30
end

.default_usernameObject

Returns the value of attribute default_username.



8
9
10
# File 'lib/rhn_satellite/connection/handler.rb', line 8

def default_username
  @default_username
end

Class Method Details

.instance_for(identifier, hostname = nil, username = nil, password = nil, timeout = nil, https = nil, https_verify = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# 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

.reset_allObject



38
39
40
# File 'lib/rhn_satellite/connection/handler.rb', line 38

def reset_all
  @instances = {}
end

.reset_defaultsObject



42
43
44
# 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) ⇒ Object



34
35
36
# File 'lib/rhn_satellite/connection/handler.rb', line 34

def reset_instance(identifier)
    instances.delete(identifier)
end

Instance Method Details

#connectObject



99
100
101
102
103
104
105
106
# 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?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/rhn_satellite/connection/handler.rb', line 95

def connected?
    !connection.nil?
end

#default_call(cmd, *args) ⇒ Object



112
113
114
# File 'lib/rhn_satellite/connection/handler.rb', line 112

def default_call(cmd,*args)
  in_transaction(true) {|token| make_call(cmd,token,*args) }
end

#disconnectObject



108
109
110
# File 'lib/rhn_satellite/connection/handler.rb', line 108

def disconnect
    @connection = nil
end

#in_transaction(do_login = false, &blk) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rhn_satellite/connection/handler.rb', line 83

def in_transaction(=false,&blk)
    begin
        begin_transaction
        token =  ?  : nil 
        result = yield(token)
        logout if 
    ensure
        end_transaction
    end
    result
end

#login(duration = nil) ⇒ Object



61
62
63
# File 'lib/rhn_satellite/connection/handler.rb', line 61

def (duration=nil)
    @auth_token ||= make_call('auth.login', *[@username, @password, duration].compact)
end

#logoutObject



65
66
67
68
69
70
# 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) ⇒ Object

Makes a remote call.



74
75
76
77
78
79
80
81
# 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