Skip to content

Commit ac09bc2

Browse files
committed
Fixes #5821 - Capsule Content API/Backend
1 parent 471c33f commit ac09bc2

29 files changed

+585
-196
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#
2+
# Copyright 2014 Red Hat, Inc.
3+
#
4+
# This software is licensed to you under the GNU General Public
5+
# License as published by the Free Software Foundation; either version
6+
# 2 of the License (GPLv2) or (at your option) any later version.
7+
# There is NO WARRANTY for this software, express or implied,
8+
# including the implied warranties of MERCHANTABILITY,
9+
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
10+
# have received a copy of GPLv2 along with this software; if not, see
11+
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
12+
13+
module Katello
14+
class Api::V2::CapsuleContentController < Api::V2::ApiController
15+
16+
before_filter :authenticate
17+
skip_before_filter :authorize
18+
19+
resource_description do
20+
api_base_url "#{Katello.config.url_prefix}/api"
21+
end
22+
23+
before_filter :find_capsule
24+
before_filter :find_environment, :only => [:add_lifecycle_environment, :remove_lifecycle_environment]
25+
26+
def_param_group :lifecycle_environments do
27+
param :id, Integer, :desc => 'Id of the capsule', :required => true
28+
param :organization_id, Integer, :desc => 'Id of the organization to limit environments on'
29+
end
30+
31+
def_param_group :update_lifecycle_environments do
32+
param :id, Integer, :desc => 'Id of the capsule', :required => true
33+
param :environment_id, Integer, :desc => 'Id of the lifecycle environment', :required => true
34+
end
35+
36+
37+
api :GET, '/capsules/:id/content'
38+
param :id, Integer, :desc => 'Id of the capsule', :required => true
39+
def show
40+
# TODO: render sync status: out of sync, sync in progress, up to date
41+
fail NotImplementedError
42+
end
43+
44+
45+
api :POST, '/capsules/:id/content/synchronize', 'Synchronize the content to the capsule'
46+
param :id, Integer, :desc => 'Id of the capsule', :required => true
47+
param :environment_ids, Array, 'Ids of the environments to be synchronized. If not specified, all the environments attached to the capsule will be synchronized'
48+
def synchronize
49+
fail NotImplementedError
50+
end
51+
52+
api :GET, '/capsules/:id/content/lifecycle_environments', 'List the lifecycle environments attached to the capsule'
53+
param_group :lifecycle_environments
54+
def lifecycle_environments
55+
@lifecycle_environments = capsule_content.lifecycle_environments(params[:organization_id])
56+
end
57+
58+
api :GET, '/capsules/:id/content/available_lifecycle_environments', 'List the lifecycle environments not attached to the capsule'
59+
param_group :lifecycle_environments
60+
def available_lifecycle_environments
61+
@lifecycle_environments = capsule_content.available_lifecycle_environments(params[:organization_id])
62+
render 'katello/api/v2/capsule_content/lifecycle_environments'
63+
end
64+
65+
api :POST, '/capsules/:id/content/lifecycle_environments', 'Add lifecycle environments to the capsule'
66+
param_group :update_lifecycle_environments
67+
def add_lifecycle_environment
68+
task = sync_task(::Actions::Katello::CapsuleContent::AddLifecycleEnvironment,
69+
capsule_content, @environment)
70+
respond_for_async :resource => task
71+
end
72+
73+
api :DELETE, '/capsules/:id/content/lifecycle_environments/:environment_id', 'Remove lifecycle environments from the capsule'
74+
param_group :update_lifecycle_environments
75+
def remove_lifecycle_environment
76+
task = sync_task(::Actions::Katello::CapsuleContent::RemoveLifecycleEnvironment,
77+
capsule_content, @environment)
78+
respond_for_async :resource => task
79+
end
80+
81+
api :POST, '/capsules/:id/content/sync', 'Synchronize the content to the capsule'
82+
param :id, Integer, :desc => 'Id of the capsule', :required => true
83+
param :environment_id, Integer, :desc => 'Id of the environment to limit the synchronization on'
84+
def sync
85+
find_environment if params[:environment_id]
86+
task = async_task(::Actions::Katello::CapsuleContent::Sync, capsule_content, @environment)
87+
respond_for_async :resource => task
88+
end
89+
90+
protected
91+
92+
def find_capsule
93+
# TODO: scope by authorization
94+
@capsule = SmartProxy.find(params[:id])
95+
end
96+
97+
def find_environment
98+
# TODO: scope by authorization
99+
@environment = Katello::KTEnvironment.find(params[:environment_id])
100+
end
101+
102+
def capsule_content
103+
CapsuleContent.new(@capsule)
104+
end
105+
106+
end
107+
end
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#
2+
# Copyright 2014 Red Hat, Inc.
3+
#
4+
# This software is licensed to you under the GNU General Public
5+
# License as published by the Free Software Foundation; either version
6+
# 2 of the License (GPLv2) or (at your option) any later version.
7+
# There is NO WARRANTY for this software, express or implied,
8+
# including the implied warranties of MERCHANTABILITY,
9+
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
10+
# have received a copy of GPLv2 along with this software; if not, see
11+
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
12+
13+
module Katello
14+
class Api::V2::CapsulesController < ::Api::V2::SmartProxiesController
15+
16+
resource_description do
17+
api_base_url "#{Katello.config.url_prefix}/api"
18+
end
19+
20+
api :GET, '/capsules', 'List all capsules'
21+
param_group :search, Api::V2::ApiController
22+
def index
23+
super
24+
end
25+
26+
api :GET, '/capsules/:id', 'Show the capsule details'
27+
param :id, Integer, :desc => 'Id of the capsule', :required => true
28+
def show
29+
super
30+
end
31+
32+
protected
33+
34+
def resource_class
35+
SmartProxy
36+
end
37+
38+
def resource_name
39+
:smart_proxy
40+
end
41+
42+
end
43+
end

engines/fort/app/lib/actions/fort/repository_create.rb renamed to app/lib/actions/katello/capsule_content/add_lifecycle_environment.rb

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,20 @@
1111
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
1212

1313
module Actions
14-
module Fort
14+
module Katello
15+
module CapsuleContent
16+
class AddLifecycleEnvironment < ::Actions::EntryAction
1517

16-
class RepositoryCreate < ::Actions::Pulp::Abstract
18+
def plan(capsule_content, environment)
19+
capsule_content.add_lifecycle_environment(environment)
1720

18-
def self.subscribe
19-
::Katello::Actions::RepositoryCreate
20-
end
21-
22-
def plan(repo)
23-
plan_self('id' => repo.id)
24-
end
25-
26-
input_format do
27-
param :id, Integer
28-
end
29-
30-
def run
31-
repo = ::Katello::Repository.find(input['id'])
32-
Node.with_environment(repo.environment).each do |node|
33-
node.update_environments
21+
bound_repos = ::Katello::Repository.in_environment(environment)
22+
bound_repos.each do |repo|
23+
plan_action(CapsuleContent::AddRepository, capsule_content, repo)
24+
end
3425
end
35-
end
3626

27+
end
3728
end
38-
3929
end
40-
4130
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#
2+
# Copyright 2014 Red Hat, Inc.
3+
#
4+
# This software is licensed to you under the GNU General Public
5+
# License as published by the Free Software Foundation; either version
6+
# 2 of the License (GPLv2) or (at your option) any later version.
7+
# There is NO WARRANTY for this software, express or implied,
8+
# including the implied warranties of MERCHANTABILITY,
9+
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
10+
# have received a copy of GPLv2 along with this software; if not, see
11+
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
12+
13+
module Actions
14+
module Katello
15+
module CapsuleContent
16+
class AddRepository < ::Actions::EntryAction
17+
18+
def plan(capsule_content, repository)
19+
distributor = repository.find_node_distributor
20+
unless distributor
21+
fail "Could not find node distributor for repository %s" % repository.pulp_id
22+
end
23+
24+
plan_action(Pulp::Consumer::BindDistributor,
25+
uuid: capsule_content.consumer_uuid,
26+
repo_id: repository.pulp_id,
27+
distributor_id: distributor['id'],
28+
bind_options: bind_options)
29+
end
30+
31+
private
32+
33+
def bind_options
34+
{ notify_agent: false, binding_config: { strategy: 'mirror' } }
35+
end
36+
37+
end
38+
end
39+
end
40+
end

engines/fort/app/lib/actions/fort/node_metadata_generate.rb renamed to app/lib/actions/katello/capsule_content/remove_lifecycle_environment.rb

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,20 @@
1111
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
1212

1313
module Actions
14-
module Fort
15-
class NodeMetadataGenerate < ::Actions::Pulp::Abstract
14+
module Katello
15+
module CapsuleContent
16+
class RemoveLifecycleEnvironment < ::Actions::EntryAction
1617

17-
def self.subscribe
18-
Actions::Katello::Repository::NodeMetadataGenerate
19-
end
20-
21-
def plan(*args)
22-
plan_self(trigger.input.merge(trigger_output: trigger.output))
23-
end
18+
def plan(capsule_content, environment)
19+
capsule_content.remove_lifecycle_environment(environment)
2420

25-
def run
26-
repo = ::Katello::Repository.find(input['id'])
27-
if repo.environment
28-
Node.with_environment(repo.environment).each do |node|
29-
node.sync(:repository => repo)
21+
bound_repos = ::Katello::Repository.in_environment(environment)
22+
bound_repos.each do |repo|
23+
plan_action(CapsuleContent::RemoveRepository, capsule_content, repo)
3024
end
3125
end
32-
end
3326

27+
end
3428
end
35-
3629
end
37-
3830
end

engines/fort/app/lib/actions/fort/changeset_promote.rb renamed to app/lib/actions/katello/capsule_content/remove_repository.rb

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,23 @@
1111
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
1212

1313
module Actions
14-
module Fort
15-
16-
class ChangesetPromote < ::Actions::Pulp::Abstract
17-
18-
def self.subscribe
19-
::Katello::Actions::ChangesetPromote
20-
end
21-
22-
def plan(changeset)
23-
plan_self('id' => changeset.id)
24-
end
25-
26-
input_format do
27-
param :id, Integer
28-
end
29-
30-
def run
31-
changeset = ::Katello::Changeset.find(input['id'])
32-
environment = changeset.environment
33-
changeset.content_views.each do |view|
34-
Node.with_environment(environment).each do |node|
35-
node.sync(:environment => environment, :content_view => view)
14+
module Katello
15+
module CapsuleContent
16+
class RemoveRepository < ::Actions::EntryAction
17+
18+
def plan(capsule_content, repository)
19+
distributor = repository.find_node_distributor
20+
unless distributor
21+
fail "Could not find node distributor for repository %s" % repository.pulp_id
3622
end
23+
24+
plan_action(Pulp::Consumer::UnbindDistributor,
25+
uuid: capsule_content.consumer_uuid,
26+
repo_id: repository.pulp_id,
27+
distributor_id: distributor['id'])
3728
end
38-
end
3929

30+
end
4031
end
41-
4232
end
4333
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# Copyright 2014 Red Hat, Inc.
3+
#
4+
# This software is licensed to you under the GNU General Public
5+
# License as published by the Free Software Foundation; either version
6+
# 2 of the License (GPLv2) or (at your option) any later version.
7+
# There is NO WARRANTY for this software, express or implied,
8+
# including the implied warranties of MERCHANTABILITY,
9+
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
10+
# have received a copy of GPLv2 along with this software; if not, see
11+
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
12+
13+
module Actions
14+
module Katello
15+
module CapsuleContent
16+
class Sync < ::Actions::EntryAction
17+
18+
def plan(capsule_content, environment = nil)
19+
repository_ids = if environment
20+
::Katello::Repository.in_environment(environment).pluck(:pulp_id)
21+
end
22+
23+
plan_action(Pulp::Consumer::SyncNode,
24+
uuid: capsule_content.consumer_uuid,
25+
repository_ids: repository_ids)
26+
end
27+
28+
end
29+
end
30+
end
31+
end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Copyright 2014 Red Hat, Inc.
3+
#
4+
# This software is licensed to you under the GNU General Public
5+
# License as published by the Free Software Foundation; either version
6+
# 2 of the License (GPLv2) or (at your option) any later version.
7+
# There is NO WARRANTY for this software, express or implied,
8+
# including the implied warranties of MERCHANTABILITY,
9+
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
10+
# have received a copy of GPLv2 along with this software; if not, see
11+
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
12+
13+
module Actions
14+
module Katello
15+
module CapsuleContent
16+
class UpdateWithoutContent < ::Actions::EntryAction
17+
18+
def plan(environment)
19+
::Katello::CapsuleContent.with_environment(environment).each do |capsule_content|
20+
plan_action(Pulp::Consumer::SyncNode,
21+
uuid: capsule_content.consumer_uuid,
22+
skip_content: true)
23+
24+
end
25+
end
26+
27+
end
28+
end
29+
end
30+
end

app/lib/actions/katello/content_view/update_environment.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def plan(content_view, environment, new_content_id = nil)
2929
unless content_view.default?
3030
plan_action(Katello::Foreman::ContentUpdate, environment, content_view)
3131
end
32+
plan_action(CapsuleContent::UpdateWithoutContent, environment)
3233
end
3334

3435
end

0 commit comments

Comments
 (0)