Class: Proxy::Spacewalk::SpacewalkClient

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/smart_proxy_spacewalk/spacewalk_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#keyObject (readonly)

Returns the value of attribute key.



7
8
9
# File 'lib/smart_proxy_spacewalk/spacewalk_client.rb', line 7

def key
  @key
end

#loginObject (readonly)

Returns the value of attribute login.



7
8
9
# File 'lib/smart_proxy_spacewalk/spacewalk_client.rb', line 7

def 
  @login
end

#passwordObject (readonly)

Returns the value of attribute password.



7
8
9
# File 'lib/smart_proxy_spacewalk/spacewalk_client.rb', line 7

def password
  @password
end

#urlObject (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 #{}."
  @key = client.call('auth.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