Class: Proxy::Spacewalk::SpacewalkClient
- Inherits:
-
Object
- Object
- Proxy::Spacewalk::SpacewalkClient
- Includes:
- Log
- Defined in:
- lib/smart_proxy_spacewalk/spacewalk_client.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#login ⇒ Object
readonly
Returns the value of attribute login.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #delete_host(hostname) ⇒ Object
- #get_host_id_by_hostname(hostname) ⇒ Object
-
#initialize(opts = {}) ⇒ SpacewalkClient
constructor
A new instance of SpacewalkClient.
- #login! ⇒ Object
- #logout! ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ SpacewalkClient
Returns a new instance of SpacewalkClient.
9 10 11 12 13 14 |
# File 'lib/smart_proxy_spacewalk/spacewalk_client.rb', line 9 def initialize(opts = {}) @url = opts[:url] @login = opts[:login] @password = opts[:password] client.instance_variable_get(:@http).verify_mode = OpenSSL::SSL::VERIFY_NONE end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/smart_proxy_spacewalk/spacewalk_client.rb', line 7 def key @key end |
#login ⇒ Object (readonly)
Returns the value of attribute login.
7 8 9 |
# File 'lib/smart_proxy_spacewalk/spacewalk_client.rb', line 7 def login @login end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
7 8 9 |
# File 'lib/smart_proxy_spacewalk/spacewalk_client.rb', line 7 def password @password end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
7 8 9 |
# File 'lib/smart_proxy_spacewalk/spacewalk_client.rb', line 7 def url @url end |
Instance Method Details
#delete_host(hostname) ⇒ Object
25 26 27 28 |
# File 'lib/smart_proxy_spacewalk/spacewalk_client.rb', line 25 def delete_host(hostname) id = get_host_id_by_hostname(hostname) client.call('system.deleteSystem', key, id) end |
#get_host_id_by_hostname(hostname) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/smart_proxy_spacewalk/spacewalk_client.rb', line 16 def get_host_id_by_hostname(hostname) systems = client.call('system.search.hostname', key, hostname) system_ids = systems.map { |system| system['id'] } id = system_ids.first raise ::Proxy::Spacewalk::HostNotFound unless id logger.debug "Spacewalk: Resolved hostname #{hostname} to ID #{id}" id end |
#login! ⇒ Object
30 31 32 33 |
# File 'lib/smart_proxy_spacewalk/spacewalk_client.rb', line 30 def login! logger.debug "Spacewalk: Login with username #{login}." @key = client.call('auth.login', login, password) end |
#logout! ⇒ Object
35 36 37 38 39 40 |
# File 'lib/smart_proxy_spacewalk/spacewalk_client.rb', line 35 def logout! return unless key logger.debug "Spacewalk: Logout." client.call('auth.logout', key) @key = nil end |