Class: RhnSatellite::Connection::Handler
- Inherits:
-
Object
- Object
- RhnSatellite::Connection::Handler
- Includes:
- RhnSatellite::Common::Debug
- Defined in:
- lib/rhn_satellite/connection/handler.rb
Class Attribute Summary collapse
-
.default_hostname ⇒ Object
Returns the value of attribute default_hostname.
- .default_https ⇒ Object
-
.default_https_verify ⇒ Object
Returns the value of attribute default_https_verify.
-
.default_password ⇒ Object
Returns the value of attribute default_password.
- .default_timeout ⇒ Object
-
.default_username ⇒ Object
Returns the value of attribute default_username.
Class Method Summary collapse
- .instance_for(identifier, hostname = nil, username = nil, password = nil, timeout = nil, https = nil, https_verify = nil) ⇒ Object
- .reset_all ⇒ Object
- .reset_defaults ⇒ Object
- .reset_instance(identifier) ⇒ Object
Instance Method Summary collapse
- #connect ⇒ Object
- #connected? ⇒ Boolean
- #default_call(cmd, *args) ⇒ Object
- #disconnect ⇒ Object
- #in_transaction(do_login = false, &blk) ⇒ Object
-
#initialize(hostname, username = nil, password = nil, timeout = 30, https = true, https_verify = true) ⇒ Handler
constructor
A new instance of Handler.
- #login(duration = nil) ⇒ Object
- #logout ⇒ Object
-
#make_call(*args) ⇒ Object
Makes a remote call.
Methods included from RhnSatellite::Common::Debug
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_hostname ⇒ Object
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_https ⇒ Object
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_verify ⇒ Object
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_password ⇒ Object
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_timeout ⇒ Object
22 23 24 |
# File 'lib/rhn_satellite/connection/handler.rb', line 22 def default_timeout @default_timeout ||= 30 end |
.default_username ⇒ Object
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_all ⇒ Object
38 39 40 |
# File 'lib/rhn_satellite/connection/handler.rb', line 38 def reset_all @instances = {} end |
.reset_defaults ⇒ Object
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
#connect ⇒ Object
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
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 |
#disconnect ⇒ Object
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(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) ⇒ Object
61 62 63 |
# 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 ⇒ Object
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 |