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)

Parameters:

  • ids (String, Array)

    string containing a single consumer id or an array of ids

  • repoids (Array) (defaults to: [])

    array of repository ids

  • consumer_report (Boolean) (defaults to: true)

    if true, result will list consumers and their applicable errata; otherwise, it will list errata and the consumers they are applicable to

Returns:

  • (RestClient::Response)

    content applicability hash with details of errata available to consumer(s)



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/runcible/extensions/consumer.rb', line 118

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

Parameters:

  • id (String)

    the consumer ID

  • repo_id (String)

    the repo ID to bind to

  • notify_agent (Boolean) (defaults to: true)

    sends consumer a notification

Returns:

  • (RestClient::Response)

    set of tasks representing each bind operation



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) ⇒ Array

Generate the content units used by other functions

Parameters:

  • type_id (String)

    the type of content (e.g. rpm, errata)

  • units (Array)

    array of units

Returns:

  • (Array)

    array of formatted content units



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/runcible/extensions/consumer.rb', line 89

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

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

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

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

Install content to a consumer

Parameters:

  • id (String)

    the consumer ID

  • type_id (String)

    the type of content to install (e.g. rpm, errata)

  • units (Array)

    array of units to install

  • options (Hash) (defaults to: {})

    to pass to content install

Returns:

  • (RestClient::Response)

    task representing the install operation



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

Parameters:

  • id (String)

    the consumer ID

  • repo_id (String)

    the repo ID to unbind from

Returns:

  • (RestClient::Response)

    set of tasks representing each unbind operation



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

Parameters:

  • id (String)

    the consumer ID

  • type_id (String)

    the type of content to uninstall (e.g. rpm, errata)

  • units (Array)

    array of units to uninstall

Returns:

  • (RestClient::Response)

    task representing the uninstall operation



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

Parameters:

  • id (String)

    the consumer ID

  • type_id (String)

    the type of content to update (e.g. rpm, errata)

  • units (Array)

    array of units to update

  • options (Hash) (defaults to: {})

    to pass to content update

Returns:

  • (RestClient::Response)

    task representing the update operation



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)
end