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

Constructor Details

This class inherits a constructor from Runcible::Base

Instance Method Details

#activate_node(id, update_strategy = "additive") ⇒ RestClient::Response

Activate a consumer as a pulp node

Parameters:

  • id (String)

    the consumer ID

  • update_strategy (String) (defaults to: "additive")

    update_strategy for the node (defaults to additive)

Returns:

  • (RestClient::Response)

    response from update call



61
62
63
64
65
# File 'lib/runcible/extensions/consumer.rb', line 61

def activate_node(id, update_strategy="additive")
  delta = {:notes=>{'_child-node' => true,
                    '_node-update-strategy' => update_strategy}}
  self.update(id, delta)
end

#applicable_errata(ids) ⇒ 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)

    array of repository ids

  • consumer_report (Boolean)

    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)



172
173
174
175
176
177
178
179
180
# File 'lib/runcible/extensions/consumer.rb', line 172

def applicable_errata(ids)
  ids = [ids] if ids.is_a? String

  criteria  = {
    'criteria' => { 'filters' => { 'id' => { '$in' => ids } } },
    'content_types' => [Runcible::Extensions::Errata.content_type]
  }
  applicability(criteria)
end

#bind_all(id, repo_id, type_id, options = {}) ⇒ 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

  • type_id (String)

    the distributor type_id to bind to

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

    options to pass to the bindings

Options Hash (options):

  • :notify_agent (Boolean)

    sends consumer a notification

  • :binding_config (Hash)

    sends consumer a notification

Returns:

  • (RestClient::Response)

    set of tasks representing each bind operation



38
39
40
41
42
# File 'lib/runcible/extensions/consumer.rb', line 38

def bind_all(id, repo_id, type_id, options={})
  repository_extension.retrieve_with_details(repo_id)['distributors'].collect do |d|
    bind(id, repo_id, d['id'], options) if d['distributor_type_id'] == type_id
  end.reject{|f| f.nil?}.flatten
end

#deactivate_node(id) ⇒ RestClient::Response

Deactivate a consumer as a pulp node

Parameters:

  • id (String)

    the consumer ID

Returns:

  • (RestClient::Response)

    response from update call



71
72
73
74
75
# File 'lib/runcible/extensions/consumer.rb', line 71

def deactivate_node(id)
  delta = {:notes=>{'child-node' => nil,
                    'update_strategy' => nil}}
  self.update(id, :delta=>delta)
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



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/runcible/extensions/consumer.rb', line 115

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

  case type_id
    when 'rpm', 'package_group'
      unit_key = :name
    when 'erratum'
      unit_key = :id
    when 'repository'
      unit_key = :repo_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)
  elsif units.nil?
    content = [{:unit_key=> nil, :type_id=>type_id}]
  else
    units.each do |unit|
      content_unit = {}
      content_unit[:type_id] = type_id
      if unit.is_a?(Hash)
        #allow user to pass in entire unit
        content_unit[:unit_key] = unit
      else
        content_unit[:unit_key] = { unit_key => unit }
      end

      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



84
85
86
# File 'lib/runcible/extensions/consumer.rb', line 84

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

#regenerate_applicability_by_ids(ids) ⇒ RestClient::Response

Regenerate the applicability for a set of consumers

Parameters:

  • ids (String, Array)

    array of consumer ids

Returns:

  • (RestClient::Response)


157
158
159
160
161
162
# File 'lib/runcible/extensions/consumer.rb', line 157

def regenerate_applicability_by_ids(ids)
  criteria  = {
    'consumer_criteria' => { 'filters' => { 'id' => { '$in' => ids } } }
  }
  regenerate_applicability(criteria)
end

#unbind_all(id, repo_id, type_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

  • type_id (String)

    the distributor type_id to unbind from

Returns:

  • (RestClient::Response)

    set of tasks representing each unbind operation



50
51
52
53
54
# File 'lib/runcible/extensions/consumer.rb', line 50

def unbind_all(id, repo_id, type_id)
  repository_extension.retrieve_with_details(repo_id)['distributors'].collect do |d|
    unbind(id, repo_id, d['id']) if d['distributor_type_id'] == type_id
  end.reject{|f| f.nil?}.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



105
106
107
# File 'lib/runcible/extensions/consumer.rb', line 105

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



95
96
97
# File 'lib/runcible/extensions/consumer.rb', line 95

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