runcible / lib / runcible / resources / consumer.rb @ df1b6e2a
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 = nil) |
28 |
call(:get, path(id))
|
29 |
end
|
30 |
|
31 |
# Retrieves all consumers
|
32 |
#
|
33 |
# @return [RestClient::Response]
|
34 |
def retrieve_all |
35 |
retrieve |
36 |
end
|
37 |
|
38 |
# Updates a consumer
|
39 |
#
|
40 |
# @param [String] id the ID of the consumer
|
41 |
# @param [Hash] optional container for all optional parameters
|
42 |
# @return [RestClient::Response]
|
43 |
def update(id, optional = {}) |
44 |
call(:put, path(id), :payload => { :delta => optional }) |
45 |
end
|
46 |
|
47 |
# Deletes a consumer
|
48 |
#
|
49 |
# @param [String] id the id of the consumer
|
50 |
# @return [RestClient::Response]
|
51 |
def delete(id) |
52 |
call(:delete, path(id))
|
53 |
end
|
54 |
|
55 |
# Create consumer profile
|
56 |
#
|
57 |
# @param [String] id the ID of the consumer
|
58 |
# @param [String] content_type the content type
|
59 |
# @param [Hash] profile hash representing the consumer profile
|
60 |
# @return [RestClient::Response]
|
61 |
def upload_profile(id, content_type, profile) |
62 |
required = required_params(binding.send(:local_variables), binding, ['id']) |
63 |
call(:post, path("#{id}/profiles/"), :payload => { :required => required }) |
64 |
end
|
65 |
|
66 |
# Retrieve a consumer profile
|
67 |
#
|
68 |
# @param [String] id the ID of the consumer
|
69 |
# @param [String] content_type the content type
|
70 |
# @return [RestClient::Response]
|
71 |
def retrieve_profile(id, content_type) |
72 |
call(:get, path("#{id}/profiles/#{content_type}/")) |
73 |
end
|
74 |
|
75 |
# Retrieve a consumer binding
|
76 |
#
|
77 |
# @param [String] id the ID of the consumer
|
78 |
# @param [String] repo_id the ID of the repository
|
79 |
# @param [String] distributor_id the ID of the distributor
|
80 |
# @return [RestClient::Response]
|
81 |
def retrieve_binding(id, repo_id, distributor_id) |
82 |
call(:get, path("#{id}/bindings/#{repo_id}/#{distributor_id}")) |
83 |
end
|
84 |
|
85 |
# Retrieve all consumer bindings
|
86 |
#
|
87 |
# @param [String] id the ID of the consumer
|
88 |
# @return [RestClient::Response]
|
89 |
def retrieve_bindings(id) |
90 |
call(:get, path("#{id}/bindings/")) |
91 |
end
|
92 |
|
93 |
# Bind a consumer to a repository for a given distributor
|
94 |
#
|
95 |
# @param [String] id the ID of the consumer
|
96 |
# @param [String] repo_id the ID of the repository
|
97 |
# @param [String] distributor_id the ID of the distributor
|
98 |
# @param [Hash] optional optional parameters
|
99 |
# @return [RestClient::Response]
|
100 |
def bind(id, repo_id, distributor_id, optional = {}) |
101 |
required = required_params(binding.send(:local_variables), binding, ['id']) |
102 |
call(:post, path("#{id}/bindings/"), :payload => { :required => required, :optional => optional }) |
103 |
end
|
104 |
|
105 |
# Unbind a consumer to a repository for a given distributor
|
106 |
#
|
107 |
# @param [String] id the ID of the consumer
|
108 |
# @param [String] repo_id the ID of the repository
|
109 |
# @param [String] distributor_id the ID of the distributor
|
110 |
# @return [RestClient::Response]
|
111 |
def unbind(id, repo_id, distributor_id) |
112 |
call(:delete, path("#{id}/bindings/#{repo_id}/#{distributor_id}")) |
113 |
end
|
114 |
|
115 |
# Install a set of units onto a consumer
|
116 |
#
|
117 |
# @param [String] id the ID of the consumer
|
118 |
# @param [Array] units array of units to install
|
119 |
# @param [Hash] options hash of install options
|
120 |
# @return [RestClient::Response]
|
121 |
def install_units(id, units, options = {}) |
122 |
required = required_params(binding.send(:local_variables), binding, ['id']) |
123 |
call(:post, path("#{id}/actions/content/install/"), :payload => { :required => required }) |
124 |
end
|
125 |
|
126 |
# Update a set of units on a consumer
|
127 |
#
|
128 |
# @param [String] id the ID of the consumer
|
129 |
# @param [Array] units array of units to update
|
130 |
# @param [Hash] options hash of update options
|
131 |
# @return [RestClient::Response]
|
132 |
def update_units(id, units, options = {}) |
133 |
required = required_params(binding.send(:local_variables), binding, ['id']) |
134 |
call(:post, path("#{id}/actions/content/update/"), :payload => { :required => required }) |
135 |
end
|
136 |
|
137 |
# Uninstall a set of units from a consumer
|
138 |
#
|
139 |
# @param [String] id the ID of the consumer
|
140 |
# @param [Array] units array of units to uninstall
|
141 |
# @param [Hash] options hash of uninstall options
|
142 |
# @return [RestClient::Response]
|
143 |
def uninstall_units(id, units, options = {}) |
144 |
required = required_params(binding.send(:local_variables), binding, ['id']) |
145 |
call(:post, path("#{id}/actions/content/uninstall/"), :payload => { :required => required }) |
146 |
end
|
147 |
|
148 |
# (Re)Generate applicability for some set of consumers
|
149 |
#
|
150 |
# @param [Hash] options payload representing criteria
|
151 |
# @return [RestClient::Response]
|
152 |
def regenerate_applicability(options = {}) |
153 |
call(:post, path('actions/content/regenerate_applicability/'), :payload => { :required => options}) |
154 |
end
|
155 |
|
156 |
# (Re)Generate applicability for a single consumer. This does not cause a
|
157 |
# pulp lock, see https://pulp.plan.io/issues/1173#note-12
|
158 |
#
|
159 |
# @param [String] id the ID of the consumer
|
160 |
# @param [Hash] options payload representing criteria
|
161 |
# @return [RestClient::Response]
|
162 |
def regenerate_applicability_by_id(id, options = {}) |
163 |
call(:post, path(id) + 'actions/content/regenerate_applicability/', :payload => { :required => options}) |
164 |
end
|
165 |
|
166 |
# retrieve the applicability for some set of consumers
|
167 |
#
|
168 |
# @param [Hash] options hash representing criteria
|
169 |
# @return [RestClient::Response]
|
170 |
def applicability(options = {}) |
171 |
call(:post, path + 'content/applicability/', :payload => { :required => options }) |
172 |
end
|
173 |
end
|
174 |
end
|
175 |
end
|