Class: Runcible::Extensions::Consumer

Inherits:
Resources::Consumer show all
Defined in:
lib/runcible/extensions/consumer.rb

Class Method Summary collapse

Methods inherited from Resources::Consumer

applicability, bind, create, delete, install_units, path, retrieve, retrieve_binding, retrieve_bindings, retrieve_profile, unbind, uninstall_units, update, update_units, upload_profile

Methods inherited from Base

add_http_auth_header, add_oauth_header, call, combine_get_params, config, config=, generate_log_message, generate_payload, get_response, log_debug, log_exception, process_response, required_params

Class Method Details

.applicable_errata(ids, repoids = [], consumer_report = true) ⇒ RestClient::Response

Retrieve the set of errata that is applicable to a consumer(s)



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/runcible/extensions/consumer.rb', line 126

def self.applicable_errata(ids, repoids = [], consumer_report = true)

  ids = [ids] if ids.is_a? String
  consumer_criteria = { 'filters' => { 'id' => { '$in' => ids } } } unless ids.empty?
  repo_criteria = { 'filters' => { 'id' => { '$in' => repoids } } } unless repoids.empty?
  report_style = (consumer_report == true) ? 'by_consumer' : 'by_units'

  criteria  = {
    'consumer_criteria' => consumer_criteria,
    'repo_criteria' => repo_criteria,
    'unit_criteria' => { 'erratum' => { } },
    'override_config' => { 'report_style' => report_style }
  }
  self.applicability(criteria)
end

.bind_all(id, repo_id, notify_agent = true) ⇒ RestClient::Response

Bind a consumer to all repositories with a given ID



35
36
37
38
39
# File 'lib/runcible/extensions/consumer.rb', line 35

def self.bind_all(id, repo_id, notify_agent=true)
  Runcible::Extensions::Repository.retrieve_with_details(repo_id)['distributors'].collect do |d|
    self.bind(id, repo_id, d['id'], {:notify_agent=>notify_agent})
  end.flatten
end

.generate_content(type_id, units, options = {}) ⇒ Array

Generate the content units used by other functions



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/runcible/extensions/consumer.rb', line 90

def self.generate_content(type_id, units, options={})
  content = []

  case type_id
    when 'rpm', 'package_group'
      unit_key = :name
    when 'erratum'
      unit_key = :id
    else
      unit_key = :id
  end

  if options[:all]
    content_unit = {}
    content_unit[:type_id] = type_id
    content_unit[:unit_key] = {}
    content.push(content_unit)
  else
    units.each do |unit|
      content_unit = {}
      content_unit[:type_id] = type_id
      content_unit[:unit_key] = { unit_key => unit }
      content.push(content_unit)
    end
  end
  content
end

.install_content(id, type_id, units, options = {}) ⇒ RestClient::Response

Install content to a consumer



59
60
61
# File 'lib/runcible/extensions/consumer.rb', line 59

def self.install_content(id, type_id, units, options={})
  self.install_units(id, generate_content(type_id, units), options)
end

.unbind_all(id, repo_id) ⇒ RestClient::Response

Unbind a consumer to all repositories with a given ID



46
47
48
49
50
# File 'lib/runcible/extensions/consumer.rb', line 46

def self.unbind_all(id, repo_id)
  Runcible::Extensions::Repository.retrieve_with_details(repo_id)['distributors'].collect do |d|
    self.unbind(id, repo_id, d['id'])
  end.flatten
end

.uninstall_content(id, type_id, units) ⇒ RestClient::Response

Uninstall content from a consumer



80
81
82
# File 'lib/runcible/extensions/consumer.rb', line 80

def self.uninstall_content(id, type_id, units)
  self.uninstall_units(id, generate_content(type_id, units))
end

.update_content(id, type_id, units, options = {}) ⇒ RestClient::Response

Update content on a consumer



70
71
72
# File 'lib/runcible/extensions/consumer.rb', line 70

def self.update_content(id, type_id, units, options={})
  self.update_units(id, generate_content(type_id, units, options), options)
end