Class: Katello::Api::V2::HostsBulkActionsController
- Inherits:
-
ApiController
- Object
- Api::V2::BaseController
- ApiController
- Katello::Api::V2::HostsBulkActionsController
show all
- Includes:
- Api::V2::BulkHostsExtension, Foreman::Renderer::Scope::Macros::Base, Concerns::Api::V2::ContentOverridesController, Concerns::Api::V2::MultiCVParamsHandling, ContentSourceHelper
- Defined in:
- app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb
Overview
this is Katello's host bulk actions controller, not to be confused with Foreman's
rubocop:disable Metrics/ClassLength
Instance Method Summary
collapse
#configure_subman, #missing_content_source, #prepare_ssl_cert, #reconfigure_yggdrasild
#empty_search_query?, #full_result_response, #resource_class, #scoped_search, #skip_session
Methods included from Rendering
#respond_for_async, #respond_for_bulk_async, #respond_for_create, #respond_for_destroy, #respond_for_index, #respond_for_show, #respond_for_status, #respond_for_update, #respond_with_template, #respond_with_template_collection, #respond_with_template_resource, #try_specific_collection_template, #try_specific_resource_template
#api_version
Instance Method Details
#applicable_errata ⇒ Object
97
98
99
100
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 97
def applicable_errata
respond_for_index(:collection => scoped_search(Katello::Erratum.applicable_to_hosts(@hosts), 'updated', 'desc',
:resource_class => Erratum))
end
|
#assign_content_view_environments ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 152
def assign_content_view_environments
registered_hosts = @hosts.select(&:content_facet)
unregistered_count = @hosts.count - registered_hosts.count
registered_hosts.each do |host|
host.content_facet.content_view_environments = @content_view_environments
host.save!
end
success_message = n_("Updated content view environments for %{count} host",
"Updated content view environments for %{count} hosts",
registered_hosts.count) % { :count => registered_hosts.count }
response = { :message => success_message }
if unregistered_count > 0
skipped_message = n_("Skipped %{count} unregistered host",
"Skipped %{count} unregistered hosts",
unregistered_count) % { :count => unregistered_count }
response[:warningMessage] = skipped_message
end
render :json => response
end
|
#available_incremental_updates ⇒ Object
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 224
def available_incremental_updates
fail HttpErrors::BadRequest, _("errata_ids is a required parameter") if params[:errata_ids].empty?
version_environments = {}
content_facets = Katello::Host::ContentFacet.with_non_installable_errata(@errata, @hosts)
ContentViewEnvironment.for_content_facets(content_facets).each do |cvenv|
version = cvenv.content_view_version
next if version.content_view.rolling?
version_environment = version_environments[version] || {:content_view_version => version, :environments => []}
version_environment[:environments] << cvenv.environment unless version_environment[:environments].include?(cvenv.environment)
version_environment[:next_version] ||= version.next_incremental_version
version_environment[:content_host_count] ||= 0
version_environment[:content_host_count] += content_facets.with_content_view_environments(cvenv).count
if version.content_view.composite?
version_environment[:components] = version.components_needing_errata(@errata)
else
version_environment[:components] = nil
end
version_environments[version] = version_environment
end
response = version_environments.values.map { |version| OpenStruct.new(version) }
respond_for_index :collection => response, :template => :available_incremental_updates
end
|
#bulk_add_host_collections ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 44
def bulk_add_host_collections
unless params[:host_collection_ids].blank?
display_messages = []
host_ids = @hosts.map(&:id)
@host_collections.each do |host_collection|
membership_update = host_collection.add_host_ids!(
:requested_host_ids => host_ids,
:authorized_host_ids => host_ids
)
final_count = membership_update[:updated_host_ids].length
msg = if final_count == 0
_("All selected hosts were already members of host collection %{host_collection}.") %
{:host_collection => host_collection.name }
else
_("Added %{count} host(s) to host collection %{host_collection}.") %
{:count => final_count, :host_collection => host_collection.name }
end
display_messages << msg
end
end
respond_for_show :template => 'bulk_action', :resource_name => 'common',
:resource => { 'displayMessages' => display_messages }
end
|
#bulk_remove_host_collections ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 74
def bulk_remove_host_collections
display_messages = []
unless params[:host_collection_ids].blank?
host_ids = @hosts.map(&:id)
@host_collections.each do |host_collection|
membership_update = host_collection.remove_host_ids!(
:requested_host_ids => host_ids,
:authorized_host_ids => host_ids
)
final_count = membership_update[:updated_host_ids].length
display_messages << _("Removed %{count} host(s) from host collection %{host_collection}.") %
{:count => final_count, :host_collection => host_collection.name }
end
end
respond_for_show :template => 'bulk_action', :resource_name => 'common',
:resource => { 'displayMessages' => display_messages }
end
|
#change_content_source ⇒ Object
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 267
def change_content_source
hosts = ::Host.where(id: params[:host_ids])
throw_resource_not_found(name: 'host', id: params[:host_ids]) unless hosts.any?
organization = validate_hosts_organization(hosts)
content_source = SmartProxy.authorized(:view_smart_proxies).find(params[:content_source_id])
if params[:content_view_environments].blank? && params[:content_view_environment_ids].blank?
fail HttpErrors::UnprocessableEntity, _("Either content_view_environments or content_view_environment_ids must be provided")
end
content_view_environments = ::Katello::ContentViewEnvironment.fetch_content_view_environments(
labels: params[:content_view_environments],
ids: params[:content_view_environment_ids],
organization: organization
)
if content_view_environments.blank?
handle_errors(labels: params[:content_view_environments],
ids: params[:content_view_environment_ids])
end
template = prepare_ssl_cert(foreman_server_ca_cert) + configure_subman(content_source) + reconfigure_yggdrasild(hosts.first)
hosts.each do |host|
next unless host.content_facet
host.content_facet.content_source = content_source
host.content_facet.content_view_environments = content_view_environments
host.save! end
render plain: template
end
|
#content_overrides ⇒ Object
125
126
127
128
129
130
131
132
133
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 125
def content_overrides
content_overrides = params[:content_overrides] || []
content_override_values = content_overrides.map do |content_override_params|
validate_content_overrides_enabled(content_override_params)
end
task = async_task(::Actions::BulkAction, ::Actions::Katello::Host::UpdateContentOverrides, @hosts, content_override_values, false)
respond_for_async :resource => task
end
|
#destroy_hosts ⇒ Object
112
113
114
115
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 112
def destroy_hosts
task = async_task(::Actions::BulkAction, ::Actions::Katello::Host::Destroy, @hosts)
respond_for_async :resource => task
end
|
#environment_content_view ⇒ Object
139
140
141
142
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 139
def environment_content_view
task = async_task(::Actions::BulkAction, ::Actions::Katello::Host::UpdateContentView, @hosts, @view.id, @environment.id)
respond_for_async :resource => task
end
|
#installable_errata ⇒ Object
105
106
107
108
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 105
def installable_errata
respond_for_index(:collection => scoped_search(Katello::Erratum.installable_for_hosts(@hosts), 'updated', 'desc',
:resource_class => Erratum))
end
|
#module_streams ⇒ Object
253
254
255
256
257
258
259
260
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 253
def module_streams
options = {}
options[:group] = [:name, :stream]
options[:resource_class] = Katello::ModuleStream
host_module_streams = Katello::ModuleStream.available_for_hosts(@hosts)
respond_for_index(collection: scoped_search(host_module_streams, :name, :asc, options),
full_template: 'katello/api/v2/module_streams/name_streams')
end
|
#release_version ⇒ Object
183
184
185
186
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 183
def release_version
task = async_task(::Actions::BulkAction, ::Actions::Katello::Host::UpdateReleaseVersion, @hosts, params["release_version"])
respond_for_async :resource => task
end
|
#resolve_traces ⇒ Object
199
200
201
202
203
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 199
def resolve_traces
result = Katello::HostTraceManager.resolve_traces(@traces)
render json: result
end
|
#system_purpose ⇒ Object
210
211
212
213
214
215
216
217
218
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 210
def system_purpose
task = async_task(::Actions::BulkAction, ::Actions::Katello::Host::UpdateSystemPurpose,
@hosts,
params[:service_level],
params[:purpose_role],
params[:purpose_usage])
respond_for_async :resource => task
end
|
#traces ⇒ Object
190
191
192
193
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 190
def traces
collection = scoped_search(Katello::HostTracer.where(host_id: @hosts.pluck(:id)), 'application', 'desc', resource_class: Katello::HostTracer)
respond_for_index(:collection => collection, :full_template => 'katello/api/v2/host_tracer/index')
end
|