Class: Runcible::Extensions::ConsumerGroup

Inherits:
Resources::ConsumerGroup show all
Defined in:
lib/runcible/extensions/consumer_group.rb

Instance Attribute Summary

Attributes inherited from Base

#logs

Instance Method Summary collapse

Methods inherited from Resources::ConsumerGroup

#associate, #create, #delete, #install_units, #path, #retrieve, #unassociate, #uninstall_units, #update_units

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

#add_consumers_by_id(id, consumer_ids) ⇒ RestClient::Response

Add consumers by ID to a consumer group



9
10
11
# File 'lib/runcible/extensions/consumer_group.rb', line 9

def add_consumers_by_id(id, consumer_ids)
  associate(id, make_consumer_criteria(consumer_ids))
end

#generate_content(type_id, units, options = {}) ⇒ Array

Generate the content units used by other functions



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/runcible/extensions/consumer_group.rb', line 72

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 group



41
42
43
# File 'lib/runcible/extensions/consumer_group.rb', line 41

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

#make_consumer_criteria(consumer_ids) ⇒ Hash

Generates consumer criteria query



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

def make_consumer_criteria(consumer_ids)
  {:criteria =>
        {:filters =>
          {:id => {'$in' => consumer_ids}}
        }
  }
end

#remove_consumers_by_id(id, consumer_ids) ⇒ RestClient::Response

Remove consumers by ID from a consumer group



18
19
20
# File 'lib/runcible/extensions/consumer_group.rb', line 18

def remove_consumers_by_id(id, consumer_ids)
  unassociate(id, make_consumer_criteria(consumer_ids))
end

#uninstall_content(id, type_id, units) ⇒ RestClient::Response

Uninstall content from a consumer group



62
63
64
# File 'lib/runcible/extensions/consumer_group.rb', line 62

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 group



52
53
54
# File 'lib/runcible/extensions/consumer_group.rb', line 52

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