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, #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, #format_payload_json, #generate_log_message, #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



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)



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_rpms(ids) ⇒ RestClient::Response

Retrieve the set of rpms that are applicable to a 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

Options Hash (options):

  • :notify_agent (Boolean)

    sends consumer a notification

  • :binding_config (Hash)

    sends consumer a notification



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



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



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



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



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



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



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



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