Class: Runcible::Extensions::Consumer

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

Instance 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, #generate_log_message, #generate_payload, #get_response, #initialize, #log_debug, #log_exception, #logger, #path, #process_response, #required_params

Constructor Details

This class inherits a constructor from Runcible::Base

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



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

def 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 }
  }
  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 bind_all(id, repo_id, notify_agent=true)
  repository_extension.retrieve_with_details(repo_id)['distributors'].collect do |d|
    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

Parameters:

  • type_id (String)

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

  • units (Array)

    array of units

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

    contains options which may impact the format of the content (e.g :all => true)

Returns:

  • (Array)

    array of formatted content units



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

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 install_content(id, type_id, units, options={})
  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 unbind_all(id, repo_id)
  repository_extension.retrieve_with_details(repo_id)['distributors'].collect do |d|
    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 uninstall_content(id, type_id, units)
  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 update_content(id, type_id, units, options={})
  update_units(id, generate_content(type_id, units, options), options)
end