Class: Runcible::Extensions::Consumer

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

Instance Attribute Summary

Attributes inherited from Base

#logs

Instance Method Summary collapse

Methods inherited from Resources::Consumer

#applicability, #bind, #create, #delete, #install_units, path, #regenerate_applicability, #regenerate_applicability_by_id, #retrieve, #retrieve_all, #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, #exception_to_log, #format_payload_json, #generate_payload, #get_response, #initialize, #lazy_config=, #log_debug, #log_exception, #log_info, #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



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

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

Returns:

  • (RestClient::Response)

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



145
146
147
# File 'lib/runcible/extensions/consumer.rb', line 145

def applicable_errata(ids)
  applicable_for_type(ids, Runcible::Extensions::Errata.content_type)
end

#applicable_module_streams(ids) ⇒ RestClient::Response

Retrieve the set of modules that are applicable to a consumer(s)

Parameters:

  • ids (String, Array)

    string containing a single consumer id or an array of ids

Returns:

  • (RestClient::Response)

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



161
162
163
# File 'lib/runcible/extensions/consumer.rb', line 161

def applicable_module_streams(ids)
  applicable_for_type(ids, Runcible::Extensions::Module.content_type)
end

#applicable_rpms(ids) ⇒ RestClient::Response

Retrieve the set of rpms that are applicable to a consumer(s)

Parameters:

  • ids (String, Array)

    string containing a single consumer id or an array of ids

Returns:

  • (RestClient::Response)

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



153
154
155
# File 'lib/runcible/extensions/consumer.rb', line 153

def applicable_rpms(ids)
  applicable_for_type(ids, Runcible::Extensions::Rpm.content_type)
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



13
14
15
16
17
18
# File 'lib/runcible/extensions/consumer.rb', line 13

def bind_all(id, repo_id, type_id, options = {})
  details = repository_extension.retrieve_with_details(repo_id)['distributors'].map do |d|
    bind(id, repo_id, d['id'], options) if d['distributor_type_id'] == type_id
  end
  details.compact.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



48
49
50
51
52
# File 'lib/runcible/extensions/consumer.rb', line 48

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



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
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/runcible/extensions/consumer.rb', line 92

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
      content_unit[:unit_key] = if unit.is_a?(Hash)
                                  #allow user to pass in entire unit
                                  unit
                                else
                                  { 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



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

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)


134
135
136
137
138
139
# File 'lib/runcible/extensions/consumer.rb', line 134

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



26
27
28
29
30
31
# File 'lib/runcible/extensions/consumer.rb', line 26

def unbind_all(id, repo_id, type_id)
  details = repository_extension.retrieve_with_details(repo_id)['distributors'].map do |d|
    unbind(id, repo_id, d['id']) if d['distributor_type_id'] == type_id
  end
  details.compact.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



82
83
84
# File 'lib/runcible/extensions/consumer.rb', line 82

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



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

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