Created
July 1, 2014 17:49
-
-
Save daviddavis/f2007ccfaaac32df8d34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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, | |
# including the implied warranties of MERCHANTABILITY, | |
# 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 Actions | |
module Candlepin | |
module Environment | |
class UpdateContent < Candlepin::Abstract | |
input_format do | |
param :cp_id | |
end | |
def run | |
cp_id = input[:cp_id] | |
all_env_ids = all_env_content_ids | |
saved_cp_ids = saved_env_content_ids | |
add_ids = all_env_ids - saved_cp_ids | |
Resources::Candlepin::Environment.add_content(self.cp_id, add_ids) unless add_ids.empty? | |
delete_ids = saved_cp_ids - all_env_ids.to_a | |
Resources::Candlepin::Environment.delete_content(self.cp_id, delete_ids) unless delete_ids.empty? | |
end | |
def all_env_content_ids | |
self.content_view.repos(self.owner).select{|r| r.yum?}.reduce(Set.new) do |env_content_ids, repo| | |
env_content_ids << repo.content_id | |
end | |
end | |
def saved_env_content_ids | |
Resources::Candlepin::Environment.find(self.cp_id)[:environmentContent].map do |content| | |
content[:contentId] | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment