-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #5821 - Capsule Content API/Backend
- Loading branch information
Showing
29 changed files
with
585 additions
and
196 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
app/controllers/katello/api/v2/capsule_content_controller.rb
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
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 |
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
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 |
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
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
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 |
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
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
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
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
30
app/lib/actions/katello/capsule_content/update_without_content.rb
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
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 |
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
Oops, something went wrong.