Class: Runcible::Extensions::ConsumerGroup

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

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

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

Add consumers by ID to a consumer group

Parameters:

  • id (String)

    the consumer group ID

  • consumer_ids (Array)

    array of consumer IDs to add to the group

Returns:

  • (RestClient::Response)

    list of consumer IDs



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

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



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

Parameters:

  • id (String)

    the consumer group 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



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

Parameters:

  • consumer_ids (Array)

    array of consumer IDs

Returns:

  • (Hash)

    the formatted query for consumers



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

Parameters:

  • id (String)

    the consumer group ID

  • consumer_ids (Array)

    array of consumer IDs to remove from the group

Returns:

  • (RestClient::Response)

    list of consumer IDs



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

Parameters:

  • id (String)

    the consumer group 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



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

Parameters:

  • id (String)

    the consumer group 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



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