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, 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
93
94
95
96
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 93
def applicable_errata
respond_for_index(:collection => scoped_search(Katello::Erratum.applicable_to_hosts(@hosts), 'updated', 'desc',
:resource_class => Erratum))
end
|
#available_incremental_updates ⇒ Object
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 183
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 |cve|
version = cve.content_view_version
version_environment = version_environments[version] || {:content_view_version => version, :environments => []}
version_environment[:environments] << cve.environment unless version_environment[:environments].include?(cve.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(cve).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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 42
def bulk_add_host_collections
unless params[:host_collection_ids].blank?
display_messages = []
@host_collections.each do |host_collection|
pre_host_collection_count = host_collection.host_ids.count
host_collection.host_ids = (host_collection.host_ids + @hosts.map(&:id)).uniq
host_collection.save!
final_count = host_collection.host_ids.count - pre_host_collection_count
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 71
def bulk_remove_host_collections
display_messages = []
unless params[:host_collection_ids].blank?
@host_collections.each do |host_collection|
pre_host_collection_count = host_collection.host_ids.count
host_collection.host_ids = (host_collection.host_ids - @hosts.map(&:id)).uniq
host_collection.save!
final_count = pre_host_collection_count - host_collection.host_ids.count
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 225
def change_content_source
hosts = ::Host.where(id: params[:host_ids])
throw_resource_not_found(name: 'host', id: params[:host_ids]) unless hosts.any?
lifecycle_environment = KTEnvironment.readable.find(params[:environment_id])
content_view = Katello::ContentView.readable.find(params[:content_view_id])
content_source = SmartProxy.authorized(:view_smart_proxies).find(params[:content_source_id])
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.assign_single_environment(
:content_view_id => content_view.id,
:environment_id => lifecycle_environment.id
)
host.update_candlepin_associations
end
render plain: template
end
|
#content_overrides ⇒ Object
121
122
123
124
125
126
127
128
129
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 121
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
108
109
110
111
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 108
def destroy_hosts
task = async_task(::Actions::BulkAction, ::Actions::Katello::Host::Destroy, @hosts)
respond_for_async :resource => task
end
|
#environment_content_view ⇒ Object
135
136
137
138
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 135
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
101
102
103
104
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 101
def installable_errata
respond_for_index(:collection => scoped_search(Katello::Erratum.installable_for_hosts(@hosts), 'updated', 'desc',
:resource_class => Erratum))
end
|
#module_streams ⇒ Object
211
212
213
214
215
216
217
218
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 211
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
143
144
145
146
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 143
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
158
159
160
161
162
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 158
def resolve_traces
result = Katello::HostTraceManager.resolve_traces(@traces)
render json: result
end
|
#system_purpose ⇒ Object
169
170
171
172
173
174
175
176
177
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 169
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
150
151
152
153
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 150
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
|