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



34
35
36
# File 'lib/runcible/extensions/consumer_group.rb', line 34

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



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
# File 'lib/runcible/extensions/consumer_group.rb', line 97

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



66
67
68
# File 'lib/runcible/extensions/consumer_group.rb', line 66

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



51
52
53
54
55
56
57
# File 'lib/runcible/extensions/consumer_group.rb', line 51

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



43
44
45
# File 'lib/runcible/extensions/consumer_group.rb', line 43

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



87
88
89
# File 'lib/runcible/extensions/consumer_group.rb', line 87

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



77
78
79
# File 'lib/runcible/extensions/consumer_group.rb', line 77

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