Skip to content

Commit

Permalink
Fixes #5821 - Capsule Content API/Backend
Browse files Browse the repository at this point in the history
  • Loading branch information
iNecas committed May 20, 2014
1 parent 471c33f commit ac09bc2
Show file tree
Hide file tree
Showing 29 changed files with 585 additions and 196 deletions.
107 changes: 107 additions & 0 deletions app/controllers/katello/api/v2/capsule_content_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#
# 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 Katello
class Api::V2::CapsuleContentController < Api::V2::ApiController

before_filter :authenticate
skip_before_filter :authorize

resource_description do
api_base_url "#{Katello.config.url_prefix}/api"
end

before_filter :find_capsule
before_filter :find_environment, :only => [:add_lifecycle_environment, :remove_lifecycle_environment]

def_param_group :lifecycle_environments do
param :id, Integer, :desc => 'Id of the capsule', :required => true
param :organization_id, Integer, :desc => 'Id of the organization to limit environments on'
end

def_param_group :update_lifecycle_environments do
param :id, Integer, :desc => 'Id of the capsule', :required => true
param :environment_id, Integer, :desc => 'Id of the lifecycle environment', :required => true
end


api :GET, '/capsules/:id/content'
param :id, Integer, :desc => 'Id of the capsule', :required => true
def show
# TODO: render sync status: out of sync, sync in progress, up to date
fail NotImplementedError
end


api :POST, '/capsules/:id/content/synchronize', 'Synchronize the content to the capsule'
param :id, Integer, :desc => 'Id of the capsule', :required => true
param :environment_ids, Array, 'Ids of the environments to be synchronized. If not specified, all the environments attached to the capsule will be synchronized'
def synchronize
fail NotImplementedError
end

api :GET, '/capsules/:id/content/lifecycle_environments', 'List the lifecycle environments attached to the capsule'
param_group :lifecycle_environments
def lifecycle_environments
@lifecycle_environments = capsule_content.lifecycle_environments(params[:organization_id])
end

api :GET, '/capsules/:id/content/available_lifecycle_environments', 'List the lifecycle environments not attached to the capsule'
param_group :lifecycle_environments
def available_lifecycle_environments
@lifecycle_environments = capsule_content.available_lifecycle_environments(params[:organization_id])
render 'katello/api/v2/capsule_content/lifecycle_environments'
end

api :POST, '/capsules/:id/content/lifecycle_environments', 'Add lifecycle environments to the capsule'
param_group :update_lifecycle_environments
def add_lifecycle_environment
task = sync_task(::Actions::Katello::CapsuleContent::AddLifecycleEnvironment,
capsule_content, @environment)
respond_for_async :resource => task
end

api :DELETE, '/capsules/:id/content/lifecycle_environments/:environment_id', 'Remove lifecycle environments from the capsule'
param_group :update_lifecycle_environments
def remove_lifecycle_environment
task = sync_task(::Actions::Katello::CapsuleContent::RemoveLifecycleEnvironment,
capsule_content, @environment)
respond_for_async :resource => task
end

api :POST, '/capsules/:id/content/sync', 'Synchronize the content to the capsule'
param :id, Integer, :desc => 'Id of the capsule', :required => true
param :environment_id, Integer, :desc => 'Id of the environment to limit the synchronization on'
def sync
find_environment if params[:environment_id]
task = async_task(::Actions::Katello::CapsuleContent::Sync, capsule_content, @environment)
respond_for_async :resource => task
end

protected

def find_capsule
# TODO: scope by authorization
@capsule = SmartProxy.find(params[:id])
end

def find_environment
# TODO: scope by authorization
@environment = Katello::KTEnvironment.find(params[:environment_id])
end

def capsule_content
CapsuleContent.new(@capsule)
end

end
end
43 changes: 43 additions & 0 deletions app/controllers/katello/api/v2/capsules_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# 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 Katello
class Api::V2::CapsulesController < ::Api::V2::SmartProxiesController

resource_description do
api_base_url "#{Katello.config.url_prefix}/api"
end

api :GET, '/capsules', 'List all capsules'
param_group :search, Api::V2::ApiController
def index
super
end

api :GET, '/capsules/:id', 'Show the capsule details'
param :id, Integer, :desc => 'Id of the capsule', :required => true
def show
super
end

protected

def resource_class
SmartProxy
end

def resource_name
:smart_proxy
end

end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,20 @@
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

module Actions
module Fort
module Katello
module CapsuleContent
class AddLifecycleEnvironment < ::Actions::EntryAction

class RepositoryCreate < ::Actions::Pulp::Abstract
def plan(capsule_content, environment)
capsule_content.add_lifecycle_environment(environment)

def self.subscribe
::Katello::Actions::RepositoryCreate
end

def plan(repo)
plan_self('id' => repo.id)
end

input_format do
param :id, Integer
end

def run
repo = ::Katello::Repository.find(input['id'])
Node.with_environment(repo.environment).each do |node|
node.update_environments
bound_repos = ::Katello::Repository.in_environment(environment)
bound_repos.each do |repo|
plan_action(CapsuleContent::AddRepository, capsule_content, repo)
end
end
end

end
end

end

end
40 changes: 40 additions & 0 deletions app/lib/actions/katello/capsule_content/add_repository.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# 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 Katello
module CapsuleContent
class AddRepository < ::Actions::EntryAction

def plan(capsule_content, repository)
distributor = repository.find_node_distributor
unless distributor
fail "Could not find node distributor for repository %s" % repository.pulp_id
end

plan_action(Pulp::Consumer::BindDistributor,
uuid: capsule_content.consumer_uuid,
repo_id: repository.pulp_id,
distributor_id: distributor['id'],
bind_options: bind_options)
end

private

def bind_options
{ notify_agent: false, binding_config: { strategy: 'mirror' } }
end

end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,20 @@
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

module Actions
module Fort
class NodeMetadataGenerate < ::Actions::Pulp::Abstract
module Katello
module CapsuleContent
class RemoveLifecycleEnvironment < ::Actions::EntryAction

def self.subscribe
Actions::Katello::Repository::NodeMetadataGenerate
end

def plan(*args)
plan_self(trigger.input.merge(trigger_output: trigger.output))
end
def plan(capsule_content, environment)
capsule_content.remove_lifecycle_environment(environment)

def run
repo = ::Katello::Repository.find(input['id'])
if repo.environment
Node.with_environment(repo.environment).each do |node|
node.sync(:repository => repo)
bound_repos = ::Katello::Repository.in_environment(environment)
bound_repos.each do |repo|
plan_action(CapsuleContent::RemoveRepository, capsule_content, repo)
end
end
end

end
end

end

end
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,23 @@
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

module Actions
module Fort

class ChangesetPromote < ::Actions::Pulp::Abstract

def self.subscribe
::Katello::Actions::ChangesetPromote
end

def plan(changeset)
plan_self('id' => changeset.id)
end

input_format do
param :id, Integer
end

def run
changeset = ::Katello::Changeset.find(input['id'])
environment = changeset.environment
changeset.content_views.each do |view|
Node.with_environment(environment).each do |node|
node.sync(:environment => environment, :content_view => view)
module Katello
module CapsuleContent
class RemoveRepository < ::Actions::EntryAction

def plan(capsule_content, repository)
distributor = repository.find_node_distributor
unless distributor
fail "Could not find node distributor for repository %s" % repository.pulp_id
end

plan_action(Pulp::Consumer::UnbindDistributor,
uuid: capsule_content.consumer_uuid,
repo_id: repository.pulp_id,
distributor_id: distributor['id'])
end
end

end
end

end
end
31 changes: 31 additions & 0 deletions app/lib/actions/katello/capsule_content/sync.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# 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 Katello
module CapsuleContent
class Sync < ::Actions::EntryAction

def plan(capsule_content, environment = nil)
repository_ids = if environment
::Katello::Repository.in_environment(environment).pluck(:pulp_id)
end

plan_action(Pulp::Consumer::SyncNode,
uuid: capsule_content.consumer_uuid,
repository_ids: repository_ids)
end

end
end
end
end
30 changes: 30 additions & 0 deletions app/lib/actions/katello/capsule_content/update_without_content.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# 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 Katello
module CapsuleContent
class UpdateWithoutContent < ::Actions::EntryAction

def plan(environment)
::Katello::CapsuleContent.with_environment(environment).each do |capsule_content|
plan_action(Pulp::Consumer::SyncNode,
uuid: capsule_content.consumer_uuid,
skip_content: true)

end
end

end
end
end
end
1 change: 1 addition & 0 deletions app/lib/actions/katello/content_view/update_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def plan(content_view, environment, new_content_id = nil)
unless content_view.default?
plan_action(Katello::Foreman::ContentUpdate, environment, content_view)
end
plan_action(CapsuleContent::UpdateWithoutContent, environment)
end

end
Expand Down
Loading

0 comments on commit ac09bc2

Please sign in to comment.