Class: Runcible::Resources::Consumer

Inherits:
Base
  • Object
show all
Defined in:
lib/runcible/resources/consumer.rb

Overview

Direct Known Subclasses

Extensions::Consumer

Instance Attribute Summary

Attributes inherited from Base

#logs

Class Method Summary collapse

Instance Method Summary collapse

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

Class Method Details

.path(id = nil) ⇒ String

Generates the API path for Consumers

Parameters:

  • id (String) (defaults to: nil)

    the ID of the consumer

Returns:

  • (String)

    the consumer path, may contain the id if passed



9
10
11
# File 'lib/runcible/resources/consumer.rb', line 9

def self.path(id = nil)
  id.nil? ? 'consumers/' : "consumers/#{id}/"
end

Instance Method Details

#applicability(options = {}) ⇒ RestClient::Response

retrieve the applicability for some set of consumers

Parameters:

  • options (Hash) (defaults to: {})

    hash representing criteria

Returns:

  • (RestClient::Response)


170
171
172
# File 'lib/runcible/resources/consumer.rb', line 170

def applicability(options = {})
  call(:post, path + 'content/applicability/', :payload => { :required => options })
end

#bind(id, repo_id, distributor_id, optional = {}) ⇒ RestClient::Response

Bind a consumer to a repository for a given distributor

Parameters:

  • id (String)

    the ID of the consumer

  • repo_id (String)

    the ID of the repository

  • distributor_id (String)

    the ID of the distributor

  • optional (Hash) (defaults to: {})

    optional parameters

Returns:

  • (RestClient::Response)


100
101
102
103
# File 'lib/runcible/resources/consumer.rb', line 100

def bind(id, repo_id, distributor_id, optional = {})
  required = required_params(binding.send(:local_variables), binding, ['id'])
  call(:post, path("#{id}/bindings/"), :payload => { :required => required, :optional => optional })
end

#create(id, optional = {}) ⇒ RestClient::Response

Creates a consumer

Parameters:

  • id (String)

    the ID of the consumer

  • optional (Hash) (defaults to: {})

    container for all optional parameters

Returns:

  • (RestClient::Response)


18
19
20
21
# File 'lib/runcible/resources/consumer.rb', line 18

def create(id, optional = {})
  required = required_params(binding.send(:local_variables), binding)
  call(:post, path, :payload => { :required => required, :optional => optional })
end

#delete(id) ⇒ RestClient::Response

Deletes a consumer

Parameters:

  • id (String)

    the id of the consumer

Returns:

  • (RestClient::Response)


51
52
53
# File 'lib/runcible/resources/consumer.rb', line 51

def delete(id)
  call(:delete, path(id))
end

#install_units(id, units, options = {}) ⇒ RestClient::Response

Install a set of units onto a consumer

Parameters:

  • id (String)

    the ID of the consumer

  • units (Array)

    array of units to install

  • options (Hash) (defaults to: {})

    hash of install options

Returns:

  • (RestClient::Response)


121
122
123
124
# File 'lib/runcible/resources/consumer.rb', line 121

def install_units(id, units, options = {})
  required = required_params(binding.send(:local_variables), binding, ['id'])
  call(:post, path("#{id}/actions/content/install/"), :payload => { :required => required })
end

#regenerate_applicability(options = {}) ⇒ RestClient::Response

(Re)Generate applicability for some set of consumers

Parameters:

  • options (Hash) (defaults to: {})

    payload representing criteria

Returns:

  • (RestClient::Response)


152
153
154
# File 'lib/runcible/resources/consumer.rb', line 152

def regenerate_applicability(options = {})
  call(:post, path('actions/content/regenerate_applicability/'), :payload => { :required => options})
end

#regenerate_applicability_by_id(id, options = {}) ⇒ RestClient::Response

(Re)Generate applicability for a single consumer. This does not cause a pulp lock, see pulp.plan.io/issues/1173#note-12

Parameters:

  • id (String)

    the ID of the consumer

  • options (Hash) (defaults to: {})

    payload representing criteria

Returns:

  • (RestClient::Response)


162
163
164
# File 'lib/runcible/resources/consumer.rb', line 162

def regenerate_applicability_by_id(id, options = {})
  call(:post, path(id) + 'actions/content/regenerate_applicability/', :payload => { :required => options})
end

#retrieve(id = nil) ⇒ RestClient::Response

Retrieves a consumer

Parameters:

  • id (String) (defaults to: nil)

    the ID of the consumer

Returns:

  • (RestClient::Response)


27
28
29
# File 'lib/runcible/resources/consumer.rb', line 27

def retrieve(id = nil)
  call(:get, path(id))
end

#retrieve_allRestClient::Response

Retrieves all consumers

Returns:

  • (RestClient::Response)


34
35
36
# File 'lib/runcible/resources/consumer.rb', line 34

def retrieve_all
  retrieve
end

#retrieve_binding(id, repo_id, distributor_id) ⇒ RestClient::Response

Retrieve a consumer binding

Parameters:

  • id (String)

    the ID of the consumer

  • repo_id (String)

    the ID of the repository

  • distributor_id (String)

    the ID of the distributor

Returns:

  • (RestClient::Response)


81
82
83
# File 'lib/runcible/resources/consumer.rb', line 81

def retrieve_binding(id, repo_id, distributor_id)
  call(:get, path("#{id}/bindings/#{repo_id}/#{distributor_id}"))
end

#retrieve_bindings(id) ⇒ RestClient::Response

Retrieve all consumer bindings

Parameters:

  • id (String)

    the ID of the consumer

Returns:

  • (RestClient::Response)


89
90
91
# File 'lib/runcible/resources/consumer.rb', line 89

def retrieve_bindings(id)
  call(:get, path("#{id}/bindings/"))
end

#retrieve_profile(id, content_type) ⇒ RestClient::Response

Retrieve a consumer profile

Parameters:

  • id (String)

    the ID of the consumer

  • content_type (String)

    the content type

Returns:

  • (RestClient::Response)


71
72
73
# File 'lib/runcible/resources/consumer.rb', line 71

def retrieve_profile(id, content_type)
  call(:get, path("#{id}/profiles/#{content_type}/"))
end

#unbind(id, repo_id, distributor_id) ⇒ RestClient::Response

Unbind a consumer to a repository for a given distributor

Parameters:

  • id (String)

    the ID of the consumer

  • repo_id (String)

    the ID of the repository

  • distributor_id (String)

    the ID of the distributor

Returns:

  • (RestClient::Response)


111
112
113
# File 'lib/runcible/resources/consumer.rb', line 111

def unbind(id, repo_id, distributor_id)
  call(:delete, path("#{id}/bindings/#{repo_id}/#{distributor_id}"))
end

#uninstall_units(id, units, options = {}) ⇒ RestClient::Response

Uninstall a set of units from a consumer

Parameters:

  • id (String)

    the ID of the consumer

  • units (Array)

    array of units to uninstall

  • options (Hash) (defaults to: {})

    hash of uninstall options

Returns:

  • (RestClient::Response)


143
144
145
146
# File 'lib/runcible/resources/consumer.rb', line 143

def uninstall_units(id, units, options = {})
  required = required_params(binding.send(:local_variables), binding, ['id'])
  call(:post, path("#{id}/actions/content/uninstall/"), :payload => { :required => required })
end

#update(id, optional = {}) ⇒ RestClient::Response

Updates a consumer

Parameters:

  • id (String)

    the ID of the consumer

  • optional (Hash) (defaults to: {})

    container for all optional parameters

Returns:

  • (RestClient::Response)


43
44
45
# File 'lib/runcible/resources/consumer.rb', line 43

def update(id, optional = {})
  call(:put, path(id), :payload => { :delta => optional })
end

#update_units(id, units, options = {}) ⇒ RestClient::Response

Update a set of units on a consumer

Parameters:

  • id (String)

    the ID of the consumer

  • units (Array)

    array of units to update

  • options (Hash) (defaults to: {})

    hash of update options

Returns:

  • (RestClient::Response)


132
133
134
135
# File 'lib/runcible/resources/consumer.rb', line 132

def update_units(id, units, options = {})
  required = required_params(binding.send(:local_variables), binding, ['id'])
  call(:post, path("#{id}/actions/content/update/"), :payload => { :required => required })
end

#upload_profile(id, content_type, profile) ⇒ RestClient::Response

Create consumer profile

Parameters:

  • id (String)

    the ID of the consumer

  • content_type (String)

    the content type

  • profile (Hash)

    hash representing the consumer profile

Returns:

  • (RestClient::Response)


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

def upload_profile(id, content_type, profile)
  required = required_params(binding.send(:local_variables), binding, ['id'])
  call(:post, path("#{id}/profiles/"), :payload => { :required => required })
end