runcible / lib / runcible / resources / consumer.rb @ 27b106f4
1 |
module Runcible |
---|---|
2 |
module Resources |
3 |
# @see https://docs.pulpproject.org/dev-guide/integration/rest-api/consumer/index.html
|
4 |
class Consumer < Runcible::Base |
5 |
# Generates the API path for Consumers
|
6 |
#
|
7 |
# @param [String] id the ID of the consumer
|
8 |
# @return [String] the consumer path, may contain the id if passed
|
9 |
def self.path(id = nil) |
10 |
id.nil? ? 'consumers/' : "consumers/#{id}/" |
11 |
end
|
12 |
|
13 |
# Creates a consumer
|
14 |
#
|
15 |
# @param [String] id the ID of the consumer
|
16 |
# @param [Hash] optional container for all optional parameters
|
17 |
# @return [RestClient::Response]
|
18 |
def create(id, optional = {}) |
19 |
required = required_params(binding.send(:local_variables), binding)
|
20 |
call(:post, path, :payload => { :required => required, :optional => optional }) |
21 |
end
|
22 |
|
23 |
# Retrieves a consumer
|
24 |
#
|
25 |
# @param [String] id the ID of the consumer
|
26 |
# @return [RestClient::Response]
|
27 |
def retrieve(id) |
28 |
call(:get, path(id))
|
29 |
end
|
30 |
|
31 |
# Updates a consumer
|
32 |
#
|
33 |
# @param [String] id the ID of the consumer
|
34 |
# @param [Hash] optional container for all optional parameters
|
35 |
# @return [RestClient::Response]
|
36 |
def update(id, optional = {}) |
37 |
call(:put, path(id), :payload => { :delta => optional }) |
38 |
end
|
39 |
|
40 |
# Deletes a consumer
|
41 |
#
|
42 |
# @param [String] id the id of the consumer
|
43 |
# @return [RestClient::Response]
|
44 |
def delete(id) |
45 |
call(:delete, path(id))
|
46 |
end
|
47 |
|
48 |
# Create consumer profile
|
49 |
#
|
50 |
# @param [String] id the ID of the consumer
|
51 |
# @param [String] content_type the content type
|
52 |
# @param [Hash] profile hash representing the consumer profile
|
53 |
# @return [RestClient::Response]
|
54 |
def upload_profile(id, content_type, profile) |
55 |
required = required_params(binding.send(:local_variables), binding, ['id']) |
56 |
call(:post, path("#{id}/profiles/"), :payload => { :required => required }) |
57 |
end
|
58 |
|
59 |
# Retrieve a consumer profile
|
60 |
#
|
61 |
# @param [String] id the ID of the consumer
|
62 |
# @param [String] content_type the content type
|
63 |
# @return [RestClient::Response]
|
64 |
def retrieve_profile(id, content_type) |
65 |
call(:get, path("#{id}/profiles/#{content_type}/")) |
66 |
end
|
67 |
|
68 |
# Retrieve a consumer binding
|
69 |
#
|
70 |
# @param [String] id the ID of the consumer
|
71 |
# @param [String] repo_id the ID of the repository
|
72 |
# @param [String] distributor_id the ID of the distributor
|
73 |
# @return [RestClient::Response]
|
74 |
def retrieve_binding(id, repo_id, distributor_id) |
75 |
call(:get, path("#{id}/bindings/#{repo_id}/#{distributor_id}")) |
76 |
end
|
77 |
|
78 |
# Retrieve all consumer bindings
|
79 |
#
|
80 |
# @param [String] id the ID of the consumer
|
81 |
# @return [RestClient::Response]
|
82 |
def retrieve_bindings(id) |
83 |
call(:get, path("#{id}/bindings/")) |
84 |
end
|
85 |
|
86 |
# Bind a consumer to a repository for a given distributor
|
87 |
#
|
88 |
# @param [String] id the ID of the consumer
|
89 |
# @param [String] repo_id the ID of the repository
|
90 |
# @param [String] distributor_id the ID of the distributor
|
91 |
# @param [Hash] optional optional parameters
|
92 |
# @return [RestClient::Response]
|
93 |
def bind(id, repo_id, distributor_id, optional = {}) |
94 |
required = required_params(binding.send(:local_variables), binding, ['id']) |
95 |
call(:post, path("#{id}/bindings/"), :payload => { :required => required, :optional => optional }) |
96 |
end
|
97 |
|
98 |
# Unbind a consumer to a repository for a given distributor
|
99 |
#
|
100 |
# @param [String] id the ID of the consumer
|
101 |
# @param [String] repo_id the ID of the repository
|
102 |
# @param [String] distributor_id the ID of the distributor
|
103 |
# @return [RestClient::Response]
|
104 |
def unbind(id, repo_id, distributor_id) |
105 |
call(:delete, path("#{id}/bindings/#{repo_id}/#{distributor_id}")) |
106 |
end
|
107 |
|
108 |
# Install a set of units onto a consumer
|
109 |
#
|
110 |
# @param [String] id the ID of the consumer
|
111 |
# @param [Array] units array of units to install
|
112 |
# @param [Hash] options hash of install options
|
113 |
# @return [RestClient::Response]
|
114 |
def install_units(id, units, options = {}) |
115 |
required = required_params(binding.send(:local_variables), binding, ['id']) |
116 |
call(:post, path("#{id}/actions/content/install/"), :payload => { :required => required }) |
117 |
end
|
118 |
|
119 |
# Update a set of units on a consumer
|
120 |
#
|
121 |
# @param [String] id the ID of the consumer
|
122 |
# @param [Array] units array of units to update
|
123 |
# @param [Hash] options hash of update options
|
124 |
# @return [RestClient::Response]
|
125 |
def update_units(id, units, options = {}) |
126 |
required = required_params(binding.send(:local_variables), binding, ['id']) |
127 |
call(:post, path("#{id}/actions/content/update/"), :payload => { :required => required }) |
128 |
end
|
129 |
|
130 |
# Uninstall a set of units from a consumer
|
131 |
#
|
132 |
# @param [String] id the ID of the consumer
|
133 |
# @param [Array] units array of units to uninstall
|
134 |
# @param [Hash] options hash of uninstall options
|
135 |
# @return [RestClient::Response]
|
136 |
def uninstall_units(id, units, options = {}) |
137 |
required = required_params(binding.send(:local_variables), binding, ['id']) |
138 |
call(:post, path("#{id}/actions/content/uninstall/"), :payload => { :required => required }) |
139 |
end
|
140 |
|
141 |
# (Re)Generate applicability for some set of consumers
|
142 |
#
|
143 |
# @param [Hash] options payload representing criteria
|
144 |
# @return [RestClient::Response]
|
145 |
def regenerate_applicability(options = {}) |
146 |
call(:post, path('actions/content/regenerate_applicability/'), :payload => { :required => options}) |
147 |
end
|
148 |
|
149 |
# retrieve the applicability for some set of consumers
|
150 |
#
|
151 |
# @param [Hash] options hash representing criteria
|
152 |
# @return [RestClient::Response]
|
153 |
def applicability(options = {}) |
154 |
call(:post, path + 'content/applicability/', :payload => { :required => options }) |
155 |
end
|
156 |
end
|
157 |
end
|
158 |
end
|