Class: Katello::Api::V2::HostsBulkActionsController
- Inherits:
-
ApiController
- Object
- Api::V2::BaseController
- ApiController
- Katello::Api::V2::HostsBulkActionsController
show all
- Includes:
- Concerns::Api::V2::BulkHostsExtensions
- Defined in:
- app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb
Constant Summary
collapse
- PARAM_ACTIONS =
{
:install_content => {
:package => :install_packages,
:package_group => :install_package_groups,
:errata => :install_errata
},
:update_content => {
:package => :update_packages,
:package_group => :update_package_groups
},
:remove_content => {
:package => :uninstall_packages,
:package_group => :uninstall_package_groups
}
}.with_indifferent_access
Instance Method Summary
collapse
#full_result_response, #resource_class, #scoped_search
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
#available_incremental_updates ⇒ Object
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 146
def available_incremental_updates
version_environments = {}
content_facets = Katello::Host::ContentFacet.with_non_installable_errata(@errata).
where("#{Katello::Host::ContentFacet.table_name}.host_id" => @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.where(:content_view_id => cve.content_view).where(:lifecycle_environment_id => cve.environment).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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 46
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
display_messages << _("Successfully added %{count} content host(s) to 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
|
#bulk_remove_host_collections ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 69
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 << _("Successfully removed %{count} content 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
|
#destroy_hosts ⇒ Object
128
129
130
131
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 128
def destroy_hosts
task = async_task(::Actions::BulkAction, ::Actions::Katello::Host::Destroy, @hosts)
respond_for_async :resource => task
end
|
#environment_content_view ⇒ Object
137
138
139
140
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 137
def environment_content_view
task = async_task(::Actions::BulkAction, ::Actions::Katello::Host::UpdateContentView, @hosts, @view.id, @environment.id)
respond_for_async :resource => task
end
|
#install_content ⇒ Object
102
103
104
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 102
def install_content
content_action
end
|
#installable_errata ⇒ Object
91
92
93
94
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 91
def installable_errata
respond_for_index(:collection => scoped_search(Katello::Erratum.installable_for_hosts(@hosts), 'updated', 'desc',
:resource_class => Erratum))
end
|
#remove_content ⇒ Object
122
123
124
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 122
def remove_content
content_action
end
|
#update_content ⇒ Object
112
113
114
|
# File 'app/controllers/katello/api/v2/hosts_bulk_actions_controller.rb', line 112
def update_content
content_action
end
|