app/lib/katello/bulk_actions.rb in katello-1.5.0 vs app/lib/katello/bulk_actions.rb in katello-2.2.2
- old
+ new
@@ -1,7 +1,7 @@
#
-# Copyright 2013 Red Hat, Inc.
+# Copyright 2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
@@ -9,92 +9,71 @@
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
module Katello
-class BulkActions
+ class BulkActions
+ attr_accessor :systems, :user, :organization
- attr_accessor :systems, :user, :organization
-
- def initialize(user, org, systems)
- self.systems = systems
- self.organization = org
- self.user = user
- end
-
- def install_errata(errata_ids)
- perform_bulk_action do |consumer_group|
- pulp_job = consumer_group.install_consumer_errata(errata_ids)
- save_job(pulp_job, :errata_install, :errata_ids, errata_ids)
+ def initialize(user, org, systems)
+ self.systems = systems
+ self.organization = org
+ self.user = user
end
- end
- def install_packages(packages)
- fail Errors::SystemGroupEmptyException if self.systems.empty?
- perform_bulk_action do |consumer_group|
- pulp_job = consumer_group.install_package(packages)
- save_job(pulp_job, :package_install, :packages, packages)
+ def install_packages(packages)
+ fail Errors::HostCollectionEmptyException if self.systems.empty?
+ perform_bulk_action do |consumer_group|
+ consumer_group.install_package(packages)
+ end
end
- end
- def uninstall_packages(packages)
- fail Errors::SystemGroupEmptyException if self.systems.empty?
- perform_bulk_action do |consumer_group|
- pulp_job = consumer_group.uninstall_package(packages)
- save_job(pulp_job, :package_remove, :packages, packages)
+ def uninstall_packages(packages)
+ fail Errors::HostCollectionEmptyException if self.systems.empty?
+ perform_bulk_action do |consumer_group|
+ consumer_group.uninstall_package(packages)
+ end
end
- end
- def update_packages(packages = nil)
- # if no packages are provided, a full system update will be performed (e.g ''yum update' equivalent)
- fail Errors::SystemGroupEmptyException if self.systems.empty?
- perform_bulk_action do |consumer_group|
- pulp_job = consumer_group.update_package(packages)
- save_job(pulp_job, :package_update, :packages, packages)
+ def update_packages(packages = nil)
+ # if no packages are provided, a full system update will be performed (e.g ''yum update' equivalent)
+ fail Errors::HostCollectionEmptyException if self.systems.empty?
+ perform_bulk_action do |consumer_group|
+ consumer_group.update_package(packages)
+ end
end
- end
- def install_package_groups(groups)
- fail Errors::SystemGroupEmptyException if self.systems.empty?
- perform_bulk_action do |consumer_group|
- pulp_job = consumer_group.install_package_group(groups)
- save_job(pulp_job, :package_group_install, :groups, groups)
+ def install_package_groups(groups)
+ fail Errors::HostCollectionEmptyException if self.systems.empty?
+ perform_bulk_action do |consumer_group|
+ consumer_group.install_package_group(groups)
+ end
end
- end
- def update_package_groups(groups)
- fail Errors::SystemGroupEmptyException if self.systems.empty?
- perform_bulk_action do |consumer_group|
- pulp_job = consumer_group.install_package_group(groups)
- save_job(pulp_job, :package_group_update, :groups, groups)
+ def update_package_groups(groups)
+ fail Errors::HostCollectionEmptyException if self.systems.empty?
+ perform_bulk_action do |consumer_group|
+ consumer_group.install_package_group(groups)
+ end
end
- end
- def uninstall_package_groups(groups)
- fail Errors::SystemGroupEmptyException if self.systems.empty?
- perform_bulk_action do |consumer_group|
- pulp_job = consumer_group.uninstall_package_group(groups)
- save_job(pulp_job, :package_group_remove, :groups, groups)
+ def uninstall_package_groups(groups)
+ fail Errors::HostCollectionEmptyException if self.systems.empty?
+ perform_bulk_action do |consumer_group|
+ consumer_group.uninstall_package_group(groups)
+ end
end
- end
- private
+ private
- def perform_bulk_action
- consumer_ids = self.systems.collect{|i| i.uuid}
- group = Glue::Pulp::ConsumerGroup.new
- group.pulp_id = ::UUIDTools::UUID.random_create.to_s
- group.consumer_ids = consumer_ids
- group.set_pulp_consumer_group
- yield(group)
- ensure
- group.del_pulp_consumer_group
+ def perform_bulk_action
+ consumer_ids = self.systems.collect { |i| i.uuid }
+ group = Glue::Pulp::ConsumerGroup.new
+ group.pulp_id = SecureRandom.uuid
+ group.consumer_ids = consumer_ids
+ group.set_pulp_consumer_group
+ yield(group)
+ ensure
+ group.del_pulp_consumer_group
+ end
end
-
- def save_job(pulp_job, job_type, parameters_type, parameters)
- job = Job.create!(:pulp_id => pulp_job.first[:task_group_id], :job_owner => self.user)
- job.create_tasks(self.organization, pulp_job, job_type, parameters_type => parameters)
- job
- end
-
-end
end