katello 3.6.0.rc1 → 3.6.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of katello might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb +9 -7
- data/app/controllers/katello/api/v2/host_subscriptions_controller.rb +7 -2
- data/app/controllers/katello/api/v2/repositories_controller.rb +10 -17
- data/app/controllers/katello/concerns/api/v2/hosts_controller_extensions.rb +1 -1
- data/app/controllers/katello/concerns/hosts_controller_extensions.rb +1 -1
- data/app/helpers/katello/providers_helper.rb +7 -0
- data/app/jobs/create_pulp_disk_space_notifications.rb +9 -0
- data/app/lib/actions/katello/host/destroy.rb +15 -39
- data/app/lib/actions/katello/host/upload_package_profile.rb +16 -4
- data/app/lib/actions/pulp/consumer/generate_applicability.rb +5 -1
- data/app/models/katello/concerns/host_managed_extensions.rb +1 -1
- data/app/models/katello/concerns/hostgroup_extensions.rb +3 -3
- data/app/models/katello/content_view.rb +2 -1
- data/app/models/katello/host_installed_package.rb +1 -0
- data/app/services/katello/candlepin/message_handler.rb +3 -0
- data/app/services/katello/registration_manager.rb +194 -0
- data/app/services/katello/ui_notifications/pulp/proxy_disk_space.rb +49 -0
- data/db/migrate/20180227094827_use_uuid_for_task_id.rb +26 -0
- data/db/seeds.d/109-katello-notification-blueprints.rb +18 -0
- data/lib/katello/engine.rb +1 -0
- data/lib/katello/scheduled_jobs.rb +12 -0
- data/lib/katello/tasks/clean_backend_objects.rake +3 -3
- data/lib/katello/version.rb +1 -1
- metadata +11 -8
- data/app/lib/actions/candlepin/consumer/destroy.rb +0 -17
- data/app/lib/actions/katello/host/register.rb +0 -133
- data/app/lib/actions/katello/host/unregister.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d376533486b2a2a64e867237c0519e9fd2920578
|
4
|
+
data.tar.gz: 43ce0faa39c88c23ca900ae85d0f986603ba736b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38aea3e72162444cc2d3766e2e610f30fd48dbdd8010683846a107d0c5100faec287b12f90ab1f83e2715d3dd2389e993476b4f557cdb27f826d5c0f2f897aa6
|
7
|
+
data.tar.gz: 47d26d3b9b377c91d0ffd9a13f09ae37fee6296a267d0d6489bb4cb8551b899dc779736dbea07285c128d54cebec7d1e5cd9138ff6760ff51c10c649dfae2bda
|
@@ -17,6 +17,8 @@ module Katello
|
|
17
17
|
before_action :authorize_client, :only => [:consumer_destroy, :consumer_checkin,
|
18
18
|
:enabled_repos, :available_releases]
|
19
19
|
|
20
|
+
before_action :check_registration_services, :only => [:consumer_create, :consumer_destroy, :consumer_activate]
|
21
|
+
|
20
22
|
before_action :add_candlepin_version_header
|
21
23
|
|
22
24
|
before_action :proxy_request_path, :proxy_request_body
|
@@ -207,7 +209,7 @@ module Katello
|
|
207
209
|
content_view_environment = find_content_view_environment
|
208
210
|
host = Katello::Host::SubscriptionFacet.find_or_create_host(content_view_environment.environment.organization, rhsm_params)
|
209
211
|
|
210
|
-
|
212
|
+
Katello::RegistrationManager.register_host(host, rhsm_params, content_view_environment)
|
211
213
|
host.reload
|
212
214
|
|
213
215
|
update_host_registered_through(host, request.headers)
|
@@ -219,11 +221,7 @@ module Katello
|
|
219
221
|
#param :id, String, :desc => N_("UUID of the consumer"), :required => true
|
220
222
|
def consumer_destroy
|
221
223
|
User.as_anonymous_admin do
|
222
|
-
|
223
|
-
sync_task(::Actions::Katello::Host::Destroy, @host)
|
224
|
-
else
|
225
|
-
sync_task(::Actions::Katello::Host::Unregister, @host)
|
226
|
-
end
|
224
|
+
Katello::RegistrationManager.unregister_host(@host, :unregistering => !Setting['unregister_delete_host'])
|
227
225
|
end
|
228
226
|
render :plain => _("Deleted consumer '%s'") % params[:id], :status => 204
|
229
227
|
end
|
@@ -239,7 +237,7 @@ module Katello
|
|
239
237
|
activation_keys = find_activation_keys
|
240
238
|
host = Katello::Host::SubscriptionFacet.find_or_create_host(activation_keys.first.organization, rhsm_params)
|
241
239
|
|
242
|
-
|
240
|
+
Katello::RegistrationManager.register_host(host, rhsm_params, nil, activation_keys)
|
243
241
|
|
244
242
|
update_host_registered_through(host, request.headers)
|
245
243
|
host.reload
|
@@ -465,6 +463,10 @@ module Katello
|
|
465
463
|
host.subscription_facet.update_attribute(:registered_through, parent_host)
|
466
464
|
end
|
467
465
|
|
466
|
+
def check_registration_services
|
467
|
+
fail "Unable to register system, not all services available" unless Katello::RegistrationManager.check_registration_services
|
468
|
+
end
|
469
|
+
|
468
470
|
# rubocop:disable MethodLength
|
469
471
|
# rubocop:disable Metrics/CyclomaticComplexity
|
470
472
|
def authorize_proxy_routes
|
@@ -4,6 +4,7 @@ module Katello
|
|
4
4
|
before_action :find_host, :except => :create
|
5
5
|
before_action :check_subscriptions, :only => [:add_subscriptions, :remove_subscriptions]
|
6
6
|
before_action :find_content_view_environment, :only => :create
|
7
|
+
before_action :check_registration_services, :only => [:destroy, :create]
|
7
8
|
|
8
9
|
def_param_group :subscription_facet_attributes do
|
9
10
|
param :release_version, String, :desc => N_("Release version for this Host to use (7Server, 7.1, etc)")
|
@@ -47,7 +48,7 @@ module Katello
|
|
47
48
|
api :DELETE, "/hosts/:host_id/subscriptions/", N_("Unregister the host as a subscription consumer")
|
48
49
|
param :host_id, Integer, :desc => N_("Id of the host"), :required => true
|
49
50
|
def destroy
|
50
|
-
|
51
|
+
Katello::RegistrationManager.unregister_host(@host, :unregistering => true)
|
51
52
|
@host.reload
|
52
53
|
respond_for_destroy(:resource => @host)
|
53
54
|
end
|
@@ -72,7 +73,7 @@ module Katello
|
|
72
73
|
rhsm_params = params_to_rhsm_params
|
73
74
|
|
74
75
|
host = Katello::Host::SubscriptionFacet.find_or_create_host(@content_view_environment.environment.organization, rhsm_params)
|
75
|
-
|
76
|
+
Katello::RegistrationManager.register_host(host, rhsm_params, @content_view_environment)
|
76
77
|
host.reload
|
77
78
|
::Katello::Host::SubscriptionFacet.update_facts(host, rhsm_params[:facts]) unless rhsm_params[:facts].blank?
|
78
79
|
|
@@ -203,6 +204,10 @@ module Katello
|
|
203
204
|
fail HttpErrors::BadRequest, _("subscriptions not specified") if params[:subscriptions].blank?
|
204
205
|
end
|
205
206
|
|
207
|
+
def check_registration_services
|
208
|
+
fail "Unable to register system, not all services available" unless Katello::RegistrationManager.check_registration_services
|
209
|
+
end
|
210
|
+
|
206
211
|
def find_host
|
207
212
|
find_host_with_subscriptions(params[:host_id], "#{action_permission}_hosts")
|
208
213
|
end
|
@@ -19,13 +19,9 @@ module Katello
|
|
19
19
|
skip_before_action :check_content_type, :only => [:upload_content]
|
20
20
|
|
21
21
|
def_param_group :repo do
|
22
|
-
param :name, String, :required => true
|
23
|
-
param :label, String, :required => false
|
24
|
-
param :product_id, :number, :required => true, :desc => N_("Product the repository belongs to")
|
25
22
|
param :url, String, :desc => N_("repository source url")
|
26
23
|
param :gpg_key_id, :number, :desc => N_("id of the gpg key that will be assigned to the new repository")
|
27
24
|
param :unprotected, :bool, :desc => N_("true if this repository can be published via HTTP")
|
28
|
-
param :content_type, RepositoryTypeManager.creatable_repository_types.keys, :required => true, :desc => N_("type of repo (either 'yum', 'deb', 'puppet', 'docker', or 'ostree')")
|
29
25
|
param :checksum_type, String, :desc => N_("checksum of the repository, currently 'sha1' & 'sha256' are supported.")
|
30
26
|
param :docker_upstream_name, String, :desc => N_("name of the upstream docker repository")
|
31
27
|
param :download_policy, ["immediate", "on_demand", "background"], :desc => N_("download policy for yum repos (either 'immediate', 'on_demand', or 'background')")
|
@@ -41,6 +37,12 @@ module Katello
|
|
41
37
|
param :ignore_global_proxy, :bool, :desc => N_("if true, will ignore the globally configured proxy when syncing.")
|
42
38
|
end
|
43
39
|
|
40
|
+
def_param_group :repo_create do
|
41
|
+
param :label, String, :required => false
|
42
|
+
param :product_id, :number, :required => true, :desc => N_("Product the repository belongs to")
|
43
|
+
param :content_type, RepositoryTypeManager.creatable_repository_types.keys, :required => true, :desc => N_("type of repo (either 'yum', 'deb', 'puppet', 'docker', or 'ostree')")
|
44
|
+
end
|
45
|
+
|
44
46
|
api :GET, "/repositories", N_("List of enabled repositories")
|
45
47
|
api :GET, "/content_views/:id/repositories", N_("List of repositories for a content view")
|
46
48
|
api :GET, "/organizations/:organization_id/repositories", N_("List of repositories in an organization")
|
@@ -137,6 +139,8 @@ module Katello
|
|
137
139
|
end
|
138
140
|
|
139
141
|
api :POST, "/repositories", N_("Create a custom repository")
|
142
|
+
param :name, String, :required => true
|
143
|
+
param_group :repo_create
|
140
144
|
param_group :repo
|
141
145
|
def create # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity
|
142
146
|
repo_params = repository_params
|
@@ -253,20 +257,9 @@ module Katello
|
|
253
257
|
end
|
254
258
|
|
255
259
|
api :PUT, "/repositories/:id", N_("Update a repository")
|
256
|
-
param :name, String, :desc => N_("New name for the repository")
|
257
260
|
param :id, :number, :required => true, :desc => N_("repository ID")
|
258
|
-
param :
|
259
|
-
|
260
|
-
param :checksum_type, String, :desc => N_("checksum of the repository, currently 'sha1' & 'sha256' are supported.'")
|
261
|
-
param :url, String, :desc => N_("the feed url of the original repository ")
|
262
|
-
param :docker_upstream_name, String, :desc => N_("name of the upstream docker repository")
|
263
|
-
param :download_policy, ["immediate", "on_demand", "background"], :desc => N_("download policy for yum repos (either 'immediate', 'on_demand', or 'background')")
|
264
|
-
param :mirror_on_sync, :bool, :desc => N_("true if this repository when synced has to be mirrored from the source and stale rpms removed.")
|
265
|
-
param :verify_ssl_on_sync, :bool, :desc => N_("if true, Katello will verify the upstream url's SSL certifcates are signed by a trusted CA.")
|
266
|
-
param :upstream_username, String, :desc => N_("Username of the upstream repository user for authentication")
|
267
|
-
param :upstream_password, String, :desc => N_("Password of the upstream repository user for authentication")
|
268
|
-
param :ostree_upstream_sync_policy, ::Katello::Repository::OSTREE_UPSTREAM_SYNC_POLICIES, :desc => N_("policies for syncing upstream ostree repositories.")
|
269
|
-
param :ostree_upstream_sync_depth, :number, :desc => N_("if a custom sync policy is chosen for ostree repositories then a 'depth' value must be provided.")
|
261
|
+
param :name, String, :required => false
|
262
|
+
param_group :repo
|
270
263
|
def update
|
271
264
|
repo_params = repository_params
|
272
265
|
sync_task(::Actions::Katello::Repository::Update, @repository, repo_params)
|
@@ -19,7 +19,7 @@ module Katello
|
|
19
19
|
prepend Overrides
|
20
20
|
|
21
21
|
def destroy
|
22
|
-
|
22
|
+
Katello::RegistrationManager.unregister_host(@host, :unregistering => false)
|
23
23
|
process_success
|
24
24
|
rescue StandardError => ex
|
25
25
|
process_error(:object => @host, :error_msg => ex.message, :redirect => saved_redirect_url_or(send("#{controller_name}_url")))
|
@@ -12,10 +12,13 @@ module Katello
|
|
12
12
|
{:id => :beta, :name => _('Beta'), :products => {}},
|
13
13
|
{:id => :isos, :name => _('ISOs'), :products => {}},
|
14
14
|
{:id => :ostree, :name => _('OSTree'), :products => {}},
|
15
|
+
{:id => :images, :name => _('Images'), :products => {}},
|
16
|
+
{:id => :files, :name => _('Files'), :products => {}},
|
15
17
|
{:id => :other, :name => _('Other'), :products => {}}
|
16
18
|
]
|
17
19
|
end
|
18
20
|
|
21
|
+
# rubocop:disable MethodLength
|
19
22
|
def redhat_repo_tab(provider, tab_id)
|
20
23
|
tabs = {}.with_indifferent_access
|
21
24
|
redhat_repo_tabs.each { |tab| tabs[tab[:id]] = tab }
|
@@ -35,6 +38,10 @@ module Katello
|
|
35
38
|
key = :isos
|
36
39
|
elsif name.include?("(RPMs)")
|
37
40
|
key = :rpms
|
41
|
+
elsif name.include?("(Images)")
|
42
|
+
key = :images
|
43
|
+
elsif name.include?("(Files)")
|
44
|
+
key = :files
|
38
45
|
elsif name.include?("(Kickstart)")
|
39
46
|
key = :kickstarts
|
40
47
|
else
|
@@ -5,52 +5,28 @@ module Actions
|
|
5
5
|
middleware.use ::Actions::Middleware::RemoteAction
|
6
6
|
|
7
7
|
def plan(host, options = {})
|
8
|
+
action_subject(host)
|
9
|
+
# normalize options before passing through to run phase
|
8
10
|
organization_destroy = options.fetch(:organization_destroy, false)
|
9
11
|
unregistering = options.fetch(:unregistering, false)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
concurrence do
|
14
|
-
if !organization_destroy && host.subscription_facet.try(:uuid)
|
15
|
-
plan_action(Candlepin::Consumer::Destroy, uuid: host.subscription_facet.uuid)
|
16
|
-
end
|
17
|
-
plan_action(Pulp::Consumer::Destroy, uuid: host.content_facet.uuid) if host.content_facet.try(:uuid)
|
18
|
-
end
|
19
|
-
|
20
|
-
host.subscription_facet.try(:destroy!)
|
21
|
-
|
22
|
-
if unregistering
|
23
|
-
unregister(host)
|
24
|
-
elsif organization_destroy
|
25
|
-
host.content_facet.try(:destroy!)
|
26
|
-
destroy_host_artifacts(host)
|
27
|
-
else
|
28
|
-
host.content_facet.try(:destroy!)
|
29
|
-
unless host.destroy
|
30
|
-
fail host.errors.full_messages.join('; ')
|
31
|
-
end
|
32
|
-
end
|
12
|
+
plan_self(:hostname => host.name, :host_id => host.id, :unregistering => unregistering,
|
13
|
+
:organization_destroy => organization_destroy)
|
33
14
|
end
|
34
15
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
destroy_host_artifacts(host)
|
43
|
-
end
|
44
|
-
|
45
|
-
def destroy_host_artifacts(host)
|
46
|
-
host.get_status(::Katello::ErrataStatus).destroy
|
47
|
-
host.get_status(::Katello::SubscriptionStatus).destroy
|
48
|
-
host.get_status(::Katello::TraceStatus).destroy
|
49
|
-
host.installed_packages.destroy_all
|
16
|
+
def run
|
17
|
+
host = ::Host.find(input[:host_id])
|
18
|
+
::Katello::RegistrationManager.unregister_host(host, :unregistering => input[:unregistering],
|
19
|
+
:organization_destroy => input[:organization_destroy])
|
20
|
+
rescue ActiveRecord::RecordNotFound
|
21
|
+
Rails.logger.warn("Attempted to delete host %s in action, but host is already gone. Continuing." % input[:host_id])
|
50
22
|
end
|
51
23
|
|
52
24
|
def humanized_name
|
53
|
-
|
25
|
+
if input.try(:[], :hostname)
|
26
|
+
_("Destroy Content Host %s") % input[:hostname]
|
27
|
+
else
|
28
|
+
_("Destroy Content Host")
|
29
|
+
end
|
54
30
|
end
|
55
31
|
end
|
56
32
|
end
|
@@ -30,14 +30,26 @@ module Actions
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def run
|
33
|
-
host = ::Host.find(input[:host_id])
|
34
33
|
profile = JSON.parse(input[:profile_string])
|
35
34
|
#free the huge string from the memory
|
36
35
|
input[:profile_string] = 'TRIMMED'.freeze
|
37
36
|
|
38
|
-
::
|
39
|
-
|
40
|
-
|
37
|
+
host = ::Host.find_by(:id => input[:host_id])
|
38
|
+
if host.nil?
|
39
|
+
Rails.logger.warn("Host with ID %s not found, continuing" % input[:host_id])
|
40
|
+
elsif host.content_facet.nil? || host.content_facet.uuid.nil?
|
41
|
+
Rails.logger.warn("Host with ID %s has no content facet, continuing" % input[:host_id])
|
42
|
+
else
|
43
|
+
begin
|
44
|
+
::Katello::Pulp::Consumer.new(host.content_facet.uuid).upload_package_profile(profile)
|
45
|
+
simple_packages = profile.map { |item| ::Katello::Pulp::SimplePackage.new(item) }
|
46
|
+
host.import_package_profile(simple_packages)
|
47
|
+
rescue RestClient::ResourceNotFound
|
48
|
+
Rails.logger.warn("Host with ID %s was not known to Pulp, continuing" % input[:host_id])
|
49
|
+
rescue ActiveRecord::InvalidForeignKey # this happens if the host gets deleted in between the "find_by" and "import_package_profile"
|
50
|
+
Rails.logger.warn("Host installed package list with ID %s was not able to be written to the DB (host likely is deleted), continuing" % input[:host_id])
|
51
|
+
end
|
52
|
+
end
|
41
53
|
end
|
42
54
|
end
|
43
55
|
end
|
@@ -8,7 +8,11 @@ module Actions
|
|
8
8
|
|
9
9
|
def invoke_external_task
|
10
10
|
if input[:uuids].length == 1
|
11
|
-
|
11
|
+
begin
|
12
|
+
pulp_resources.consumer.regenerate_applicability_by_id(input[:uuids].first)
|
13
|
+
rescue RestClient::ResourceNotFound
|
14
|
+
Rails.logger.warn("Pulp consumer %s not found." % input[:uuids].first)
|
15
|
+
end
|
12
16
|
else
|
13
17
|
pulp_extensions.consumer.regenerate_applicability_by_ids(input[:uuids])
|
14
18
|
end
|
@@ -20,7 +20,7 @@ module Katello
|
|
20
20
|
included do
|
21
21
|
prepend Overrides
|
22
22
|
|
23
|
-
has_many :host_installed_packages, :class_name => "::Katello::HostInstalledPackage", :foreign_key => :host_id, :dependent => :
|
23
|
+
has_many :host_installed_packages, :class_name => "::Katello::HostInstalledPackage", :foreign_key => :host_id, :dependent => :delete_all
|
24
24
|
has_many :installed_packages, :class_name => "::Katello::InstalledPackage", :through => :host_installed_packages
|
25
25
|
has_many :host_traces, :class_name => "::Katello::HostTracer", :foreign_key => :host_id, :dependent => :destroy
|
26
26
|
|
@@ -14,9 +14,9 @@ module Katello
|
|
14
14
|
validates_with Katello::Validators::ContentViewEnvironmentValidator
|
15
15
|
validates_with Katello::Validators::HostgroupKickstartRepositoryValidator
|
16
16
|
|
17
|
-
scoped_search :relation => :content_source, :on => :name, :complete_value => true, :rename => :content_source
|
18
|
-
scoped_search :relation => :content_view, :on => :name, :complete_value => true, :rename => :content_view
|
19
|
-
scoped_search :relation => :lifecycle_environment, :on => :name, :complete_value => true, :rename => :lifecycle_environment
|
17
|
+
scoped_search :relation => :content_source, :on => :name, :complete_value => true, :rename => :content_source, :only_explicit => true
|
18
|
+
scoped_search :relation => :content_view, :on => :name, :complete_value => true, :rename => :content_view, :only_explicit => true
|
19
|
+
scoped_search :relation => :lifecycle_environment, :on => :name, :complete_value => true, :rename => :lifecycle_environment, :only_explicit => true
|
20
20
|
end
|
21
21
|
|
22
22
|
def content_view
|
@@ -299,7 +299,8 @@ module Katello
|
|
299
299
|
end
|
300
300
|
|
301
301
|
def duplicate_repositories_to_publish
|
302
|
-
|
302
|
+
return [] unless composite?
|
303
|
+
repositories_to_publish_by_library_instance.select { |key, val| val.count > 1 && key.present? }.keys
|
303
304
|
end
|
304
305
|
|
305
306
|
def components_with_repo(library_instance)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module Katello
|
2
2
|
class HostInstalledPackage < Katello::Model
|
3
|
+
# Do not use active record callbacks in this join model. Direct INSERTs and DELETEs are done
|
3
4
|
belongs_to :host, :inverse_of => :host_installed_packages, :class_name => '::Host::Managed'
|
4
5
|
belongs_to :installed_package, :inverse_of => :host_installed_packages, :class_name => 'Katello::InstalledPackage'
|
5
6
|
end
|
@@ -48,16 +48,19 @@ module Katello
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def subscription_facet
|
51
|
+
return nil if self.consumer_uuid.nil?
|
51
52
|
::Katello::Host::SubscriptionFacet.where(uuid: self.consumer_uuid).first
|
52
53
|
end
|
53
54
|
|
54
55
|
def create_pool_on_host
|
56
|
+
return if self.subscription_facet.nil?
|
55
57
|
pool = self.pool_by_reference_id
|
56
58
|
::Katello::SubscriptionFacetPool.where(subscription_facet_id: self.subscription_facet.id,
|
57
59
|
pool_id: pool.id).first_or_create
|
58
60
|
end
|
59
61
|
|
60
62
|
def remove_pool_from_host
|
63
|
+
return if self.subscription_facet.nil?
|
61
64
|
pool = self.pool_by_reference_id
|
62
65
|
::Katello::SubscriptionFacetPool.where(subscription_facet_id: self.subscription_facet.id,
|
63
66
|
pool_id: pool.id).destroy_all
|
@@ -0,0 +1,194 @@
|
|
1
|
+
module Katello
|
2
|
+
class RegistrationManager
|
3
|
+
class << self
|
4
|
+
private :new
|
5
|
+
|
6
|
+
# options:
|
7
|
+
# * organization_destroy: destroy some data associated with host, but
|
8
|
+
# leave items alone that will be removed later as part of org destroy
|
9
|
+
# * unregistering: unregister the host but don't destroy it
|
10
|
+
def unregister_host(host, options = {})
|
11
|
+
organization_destroy = options.fetch(:organization_destroy, false)
|
12
|
+
unregistering = options.fetch(:unregistering, false)
|
13
|
+
|
14
|
+
# if the first operation fails, just raise the error since there's nothing to clean up yet.
|
15
|
+
candlepin_consumer_destroy(host.subscription_facet.uuid) if !organization_destroy && host.subscription_facet.try(:uuid)
|
16
|
+
|
17
|
+
# if this fails, there is not much to do about it right now. We can't really re-create the candlepin consumer.
|
18
|
+
# This can be cleaned up later via clean_backend_objects.
|
19
|
+
pulp_consumer_destory(host.content_facet.uuid) if host.content_facet.try(:uuid)
|
20
|
+
|
21
|
+
host.subscription_facet.try(:destroy!)
|
22
|
+
|
23
|
+
if unregistering
|
24
|
+
remove_host_artifacts(host)
|
25
|
+
elsif organization_destroy
|
26
|
+
host.content_facet.try(:destroy!)
|
27
|
+
remove_host_artifacts(host, false)
|
28
|
+
else
|
29
|
+
host.content_facet.try(:destroy!)
|
30
|
+
destroy_host_record(host.id)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def register_host(host, consumer_params, content_view_environment, activation_keys = [])
|
35
|
+
new_host = host.new_record?
|
36
|
+
|
37
|
+
unless new_host
|
38
|
+
host.save!
|
39
|
+
unregister_host(host, :unregistering => true)
|
40
|
+
host.reload
|
41
|
+
end
|
42
|
+
|
43
|
+
unless activation_keys.empty?
|
44
|
+
content_view_environment ||= lookup_content_view_environment(activation_keys)
|
45
|
+
set_host_collections(host, activation_keys)
|
46
|
+
end
|
47
|
+
fail _('Content View and Environment not set for registration.') if content_view_environment.nil?
|
48
|
+
|
49
|
+
host.save! #the host is in foreman db at this point
|
50
|
+
|
51
|
+
host_uuid = get_uuid(consumer_params)
|
52
|
+
consumer_params[:uuid] = host_uuid
|
53
|
+
host.content_facet = populate_content_facet(host, content_view_environment, host_uuid)
|
54
|
+
host.subscription_facet = populate_subscription_facet(host, activation_keys, consumer_params, host_uuid)
|
55
|
+
host.save! # the host has content and subscription facets at this point
|
56
|
+
|
57
|
+
User.as_anonymous_admin do
|
58
|
+
begin
|
59
|
+
create_in_cp_and_pulp(host, content_view_environment, consumer_params, activation_keys)
|
60
|
+
rescue StandardError => e
|
61
|
+
# we can't call CP or pulp here since something bad already happened. Just clean up our DB as best as we can.
|
62
|
+
host.subscription_facet.try(:destroy!)
|
63
|
+
new_host ? remove_partially_registered_new_host(host) : remove_host_artifacts(host)
|
64
|
+
raise e
|
65
|
+
end
|
66
|
+
|
67
|
+
finalize_registration(host)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def check_registration_services
|
72
|
+
ping_results = {}
|
73
|
+
User.as_anonymous_admin do
|
74
|
+
ping_results = Katello::Ping.ping
|
75
|
+
end
|
76
|
+
ping_results[:services][:pulp][:status] == "ok" && ping_results[:services][:candlepin][:status] == "ok"
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def destroy_host_record(host_id)
|
82
|
+
host = ::Host.find(host_id)
|
83
|
+
host.destroy
|
84
|
+
rescue ActiveRecord::RecordNotFound
|
85
|
+
Rails.logger.warn("Attempted to destroy host %s but host is already gone." % host_id)
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_uuid(params)
|
89
|
+
params.key?(:uuid) ? params[:uuid] : SecureRandom.uuid
|
90
|
+
end
|
91
|
+
|
92
|
+
def remove_partially_registered_new_host(host)
|
93
|
+
host.content_facet.try(:destroy!)
|
94
|
+
destroy_host_record(host.id)
|
95
|
+
end
|
96
|
+
|
97
|
+
def create_in_cp_and_pulp(host, content_view_environment, consumer_params, activation_keys)
|
98
|
+
# if CP fails, nothing to clean up yet w.r.t. backend services
|
99
|
+
cp_create = ::Katello::Resources::Candlepin::Consumer.create(content_view_environment.cp_id, consumer_params, activation_keys.map(&:cp_name))
|
100
|
+
::Katello::Host::SubscriptionFacet.update_facts(host, consumer_params[:facts]) unless consumer_params[:facts].blank?
|
101
|
+
|
102
|
+
# if pulp fails, remove the CP consumer we just made
|
103
|
+
begin
|
104
|
+
::Katello.pulp_server.extensions.consumer.create(cp_create[:uuid], display_name: host.name)
|
105
|
+
rescue StandardError => e
|
106
|
+
::Katello::Resources::Candlepin::Consumer.destroy(cp_create[:uuid])
|
107
|
+
raise e
|
108
|
+
end
|
109
|
+
cp_create[:uuid]
|
110
|
+
end
|
111
|
+
|
112
|
+
def finalize_registration(host)
|
113
|
+
host = ::Host.find(host.id)
|
114
|
+
host.subscription_facet.update_from_consumer_attributes(host.subscription_facet.candlepin_consumer.
|
115
|
+
consumer_attributes.except(:guestIds, :facts))
|
116
|
+
host.subscription_facet.save!
|
117
|
+
host.subscription_facet.update_subscription_status
|
118
|
+
host.content_facet.update_errata_status
|
119
|
+
host.refresh_global_status!
|
120
|
+
end
|
121
|
+
|
122
|
+
def set_host_collections(host, activation_keys)
|
123
|
+
host_collection_ids = activation_keys.flat_map(&:host_collection_ids).compact.uniq
|
124
|
+
|
125
|
+
host_collection_ids.each do |host_collection_id|
|
126
|
+
host_collection = ::Katello::HostCollection.find(host_collection_id)
|
127
|
+
if !host_collection.unlimited_hosts && host_collection.max_hosts >= 0 &&
|
128
|
+
host_collection.systems.length >= host_collection.max_hosts
|
129
|
+
fail _("Host collection '%{name}' exceeds maximum usage limit of '%{limit}'") %
|
130
|
+
{:limit => host_collection.max_hosts, :name => host_collection.name}
|
131
|
+
end
|
132
|
+
end
|
133
|
+
host.host_collection_ids = host_collection_ids
|
134
|
+
end
|
135
|
+
|
136
|
+
def lookup_content_view_environment(activation_keys)
|
137
|
+
activation_key = activation_keys.reverse.detect do |act_key|
|
138
|
+
act_key.environment && act_key.content_view
|
139
|
+
end
|
140
|
+
if activation_key
|
141
|
+
::Katello::ContentViewEnvironment.where(:content_view_id => activation_key.content_view, :environment_id => activation_key.environment).first
|
142
|
+
else
|
143
|
+
fail _('At least one activation key must have a lifecycle environment and content view assigned to it')
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def candlepin_consumer_destroy(host_uuid)
|
148
|
+
::Katello::Resources::Candlepin::Consumer.destroy(host_uuid)
|
149
|
+
rescue RestClient::Gone
|
150
|
+
Rails.logger.error(_("Consumer %s has already been removed") % host_uuid)
|
151
|
+
end
|
152
|
+
|
153
|
+
def pulp_consumer_destory(host_uuid)
|
154
|
+
::Katello.pulp_server.extensions.consumer.delete(host_uuid)
|
155
|
+
rescue RestClient::ResourceNotFound
|
156
|
+
Rails.logger.error(_("Pulp Consumer %s has already been removed") % host_uuid)
|
157
|
+
end
|
158
|
+
|
159
|
+
def populate_content_facet(host, content_view_environment, uuid)
|
160
|
+
content_facet = host.content_facet || ::Katello::Host::ContentFacet.new(:host => host)
|
161
|
+
content_facet.content_view = content_view_environment.content_view
|
162
|
+
content_facet.lifecycle_environment = content_view_environment.environment
|
163
|
+
content_facet.uuid = uuid
|
164
|
+
content_facet.save!
|
165
|
+
content_facet
|
166
|
+
end
|
167
|
+
|
168
|
+
def populate_subscription_facet(host, activation_keys, consumer_params, uuid)
|
169
|
+
subscription_facet = host.subscription_facet || ::Katello::Host::SubscriptionFacet.new(:host => host)
|
170
|
+
subscription_facet.last_checkin = Time.now
|
171
|
+
subscription_facet.update_from_consumer_attributes(consumer_params.except(:guestIds, :facts))
|
172
|
+
subscription_facet.uuid = uuid
|
173
|
+
subscription_facet.user = User.current unless User.current.nil? || User.current.hidden?
|
174
|
+
subscription_facet.save!
|
175
|
+
subscription_facet.activation_keys = activation_keys
|
176
|
+
subscription_facet
|
177
|
+
end
|
178
|
+
|
179
|
+
def remove_host_artifacts(host, clear_content_facet = true)
|
180
|
+
if host.content_facet && clear_content_facet
|
181
|
+
host.content_facet.bound_repositories = []
|
182
|
+
host.content_facet.applicable_errata = []
|
183
|
+
host.content_facet.uuid = nil
|
184
|
+
host.content_facet.save!
|
185
|
+
end
|
186
|
+
|
187
|
+
host.get_status(::Katello::ErrataStatus).destroy
|
188
|
+
host.get_status(::Katello::SubscriptionStatus).destroy
|
189
|
+
host.get_status(::Katello::TraceStatus).destroy
|
190
|
+
host.installed_packages.delete_all
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Katello
|
2
|
+
module UINotifications
|
3
|
+
module Pulp
|
4
|
+
class ProxyDiskSpace
|
5
|
+
class << self
|
6
|
+
def deliver!
|
7
|
+
SmartProxy.unscoped.with_content.each do |proxy|
|
8
|
+
percentage = proxy.statuses[:pulp].storage['pulp_dir']['percent']
|
9
|
+
if percentage[0..2].to_i < 90 && notification_already_exists?(proxy)
|
10
|
+
blueprint.notifications.where(subject: proxy).destroy_all
|
11
|
+
next
|
12
|
+
end
|
13
|
+
next unless update_notifications(proxy).empty?
|
14
|
+
::Notification.create!(
|
15
|
+
:subject => proxy,
|
16
|
+
:initiator => User.anonymous_admin,
|
17
|
+
:audience => Notification::AUDIENCE_ADMIN,
|
18
|
+
:message => ::UINotifications::StringParser.new(
|
19
|
+
blueprint.message,
|
20
|
+
:subject => proxy,
|
21
|
+
:percentage => percentage
|
22
|
+
),
|
23
|
+
:notification_blueprint => blueprint
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def notification_already_exists?(subject)
|
29
|
+
low_disk_notification = Notification.unscoped.find_by(:subject => subject)
|
30
|
+
return false if low_disk_notification.blank?
|
31
|
+
low_disk_notification.notification_blueprint == blueprint
|
32
|
+
end
|
33
|
+
|
34
|
+
def update_notifications(subject)
|
35
|
+
return if blueprint.notifications.empty?
|
36
|
+
blueprint.notifications.
|
37
|
+
where(subject: subject).
|
38
|
+
update_attributes(expired_at: blueprint.expired_at)
|
39
|
+
end
|
40
|
+
|
41
|
+
def blueprint
|
42
|
+
@blueprint ||= NotificationBlueprint.unscoped.find_by(
|
43
|
+
:name => 'pulp_low_disk_space')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class UseUuidForTaskId < ActiveRecord::Migration[5.0]
|
2
|
+
# PostgreSQL has a special column type for storing UUIDs.
|
3
|
+
# Using this type instead of generic string should lead to having
|
4
|
+
# smaller DB and possibly better overall performance.
|
5
|
+
def up
|
6
|
+
if on_postgresql?
|
7
|
+
change_table :katello_content_view_histories do |t|
|
8
|
+
t.change :task_id, :uuid, :using => 'task_id::uuid'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def down
|
14
|
+
if on_postgresql?
|
15
|
+
change_table :katello_content_view_histories do |t|
|
16
|
+
t.change :task_id, :string, :null => true, :limit => 255
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def on_postgresql?
|
24
|
+
ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
blueprints = [
|
2
|
+
{
|
3
|
+
group: N_('Proxies'),
|
4
|
+
name: 'pulp_low_disk_space',
|
5
|
+
message: _("%{subject}'s disk is %{percentage} full. Since this proxy is running Pulp, it needs disk space to publish content views. Please ensure the disk does not get full."),
|
6
|
+
level: 'warning',
|
7
|
+
actions:
|
8
|
+
{
|
9
|
+
links:
|
10
|
+
[
|
11
|
+
path_method: :smart_proxy_path,
|
12
|
+
title: N_('Details')
|
13
|
+
]
|
14
|
+
}
|
15
|
+
}
|
16
|
+
]
|
17
|
+
|
18
|
+
blueprints.each { |blueprint| UINotifications::Seed.new(blueprint).configure }
|
data/lib/katello/engine.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
# First, we check if there's a job already enqueued for Pulp notifications
|
2
|
+
::Foreman::Application.dynflow.config.on_init do |world|
|
3
|
+
pending_jobs = world.persistence.find_execution_plans(filters: { :state => 'scheduled' })
|
4
|
+
scheduled_job = pending_jobs.select do |job|
|
5
|
+
delayed_plan = world.persistence.load_delayed_plan job.id
|
6
|
+
next if delayed_plan.blank?
|
7
|
+
delayed_plan.to_hash[:serialized_args].first["job_class"] == 'CreatePulpDiskSpaceNotifications'
|
8
|
+
end
|
9
|
+
|
10
|
+
# Only create notifications if there isn't a scheduled job
|
11
|
+
CreatePulpDiskSpaceNotifications.perform_later if scheduled_job.blank?
|
12
|
+
end
|
@@ -42,17 +42,17 @@ namespace :katello do
|
|
42
42
|
def cleanup_hosts(cleaner)
|
43
43
|
cleaner.hosts_with_nil_facets.each do |host|
|
44
44
|
print "Host #{host.id} #{host.name} is partially missing subscription information. Un-registering\n"
|
45
|
-
execute("Failed to delete host") {
|
45
|
+
execute("Failed to delete host") { Katello::RegistrationManager.unregister_host(host) }
|
46
46
|
end
|
47
47
|
|
48
48
|
cleaner.hosts_with_no_subscriptions.each do |host|
|
49
49
|
print "Host #{host.id} #{host.name} #{host.subscription_facet.try(:uuid)} is partially missing subscription information. Un-registering\n"
|
50
|
-
execute("Failed to delete host") {
|
50
|
+
execute("Failed to delete host") { Katello::RegistrationManager.unregister_host(host) }
|
51
51
|
end
|
52
52
|
|
53
53
|
cleaner.hosts_with_no_content.each do |host|
|
54
54
|
print "Host #{host.id} #{host.name} #{host.content_facet.try(:uuid)} is partially missing content information. Un-registering\n"
|
55
|
-
execute("Failed to delete host") {
|
55
|
+
execute("Failed to delete host") { Katello::RegistrationManager.unregister_host(host) }
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
data/lib/katello/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: katello
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.6.0.
|
4
|
+
version: 3.6.0.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- N/A
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02
|
11
|
+
date: 2018-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0.
|
89
|
+
version: '0.12'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0.
|
96
|
+
version: '0.12'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: dynflow
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -544,6 +544,7 @@ files:
|
|
544
544
|
- app/helpers/katello/sync_management_helper.rb
|
545
545
|
- app/helpers/katello/taxonomy_helper.rb
|
546
546
|
- app/helpers/katello/translation_helper.rb
|
547
|
+
- app/jobs/create_pulp_disk_space_notifications.rb
|
547
548
|
- app/lib/actions/abstract_async_task.rb
|
548
549
|
- app/lib/actions/candlepin/abstract.rb
|
549
550
|
- app/lib/actions/candlepin/abstract_async_task.rb
|
@@ -555,7 +556,6 @@ files:
|
|
555
556
|
- app/lib/actions/candlepin/consumer/attach_subscription.rb
|
556
557
|
- app/lib/actions/candlepin/consumer/auto_attach_subscriptions.rb
|
557
558
|
- app/lib/actions/candlepin/consumer/create.rb
|
558
|
-
- app/lib/actions/candlepin/consumer/destroy.rb
|
559
559
|
- app/lib/actions/candlepin/consumer/hypervisors.rb
|
560
560
|
- app/lib/actions/candlepin/consumer/remove_subscription.rb
|
561
561
|
- app/lib/actions/candlepin/consumer/update.rb
|
@@ -644,9 +644,7 @@ files:
|
|
644
644
|
- app/lib/actions/katello/host/package_group/remove.rb
|
645
645
|
- app/lib/actions/katello/host/reassign.rb
|
646
646
|
- app/lib/actions/katello/host/recalculate_errata_status.rb
|
647
|
-
- app/lib/actions/katello/host/register.rb
|
648
647
|
- app/lib/actions/katello/host/remove_subscriptions.rb
|
649
|
-
- app/lib/actions/katello/host/unregister.rb
|
650
648
|
- app/lib/actions/katello/host/update.rb
|
651
649
|
- app/lib/actions/katello/host/update_content_overrides.rb
|
652
650
|
- app/lib/actions/katello/host/update_content_view.rb
|
@@ -1034,8 +1032,10 @@ files:
|
|
1034
1032
|
- app/services/katello/pulp/simple_package.rb
|
1035
1033
|
- app/services/katello/pulp/srpm.rb
|
1036
1034
|
- app/services/katello/puppet_class_importer_extensions.rb
|
1035
|
+
- app/services/katello/registration_manager.rb
|
1037
1036
|
- app/services/katello/repository_type.rb
|
1038
1037
|
- app/services/katello/repository_type_manager.rb
|
1038
|
+
- app/services/katello/ui_notifications/pulp/proxy_disk_space.rb
|
1039
1039
|
- app/views/common/400.html
|
1040
1040
|
- app/views/dashboard/_content_views_widget.html.erb
|
1041
1041
|
- app/views/dashboard/_errata_widget.html.erb
|
@@ -1490,6 +1490,7 @@ files:
|
|
1490
1490
|
- db/migrate/20171120144843_add_repository_ignore_proxy.rb
|
1491
1491
|
- db/migrate/20171211124439_add_uuid_index_to_katello_subscription_facets.rb
|
1492
1492
|
- db/migrate/20180103230812_set_errata_updated_date.rb
|
1493
|
+
- db/migrate/20180227094827_use_uuid_for_task_id.rb
|
1493
1494
|
- db/seeds.d/101-locations.rb
|
1494
1495
|
- db/seeds.d/102-organizations.rb
|
1495
1496
|
- db/seeds.d/103-provisioning_templates.rb
|
@@ -1497,6 +1498,7 @@ files:
|
|
1497
1498
|
- db/seeds.d/106-mail_notifications.rb
|
1498
1499
|
- db/seeds.d/107-enable_dynflow.rb
|
1499
1500
|
- db/seeds.d/108-subcription-bookmarks.rb
|
1501
|
+
- db/seeds.d/109-katello-notification-blueprints.rb
|
1500
1502
|
- db/seeds.d/75-job_templates.rb
|
1501
1503
|
- engines/bastion_katello/README.md
|
1502
1504
|
- engines/bastion_katello/app/assets/javascripts/bastion_katello/activation-keys/activation-key.factory.js
|
@@ -2052,6 +2054,7 @@ files:
|
|
2052
2054
|
- lib/katello/repository_types/ostree.rb
|
2053
2055
|
- lib/katello/repository_types/puppet.rb
|
2054
2056
|
- lib/katello/repository_types/yum.rb
|
2057
|
+
- lib/katello/scheduled_jobs.rb
|
2055
2058
|
- lib/katello/tasks/clean_backend_objects.rake
|
2056
2059
|
- lib/katello/tasks/clean_old_file_repos.rake
|
2057
2060
|
- lib/katello/tasks/clean_published_repo_directories.rake
|
@@ -2193,7 +2196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
2193
2196
|
version: 1.3.1
|
2194
2197
|
requirements: []
|
2195
2198
|
rubyforge_project:
|
2196
|
-
rubygems_version: 2.
|
2199
|
+
rubygems_version: 2.4.6
|
2197
2200
|
signing_key:
|
2198
2201
|
specification_version: 4
|
2199
2202
|
summary: ''
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Actions
|
2
|
-
module Candlepin
|
3
|
-
module Consumer
|
4
|
-
class Destroy < Candlepin::Abstract
|
5
|
-
input_format do
|
6
|
-
param :uuid
|
7
|
-
end
|
8
|
-
|
9
|
-
def run
|
10
|
-
::Katello::Resources::Candlepin::Consumer.destroy(input[:uuid])
|
11
|
-
rescue RestClient::Gone
|
12
|
-
Rails.logger.error(_("Consumer %s has already been removed") % input[:uuid])
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,133 +0,0 @@
|
|
1
|
-
module Actions
|
2
|
-
module Katello
|
3
|
-
module Host
|
4
|
-
class Register < Actions::EntryAction
|
5
|
-
middleware.use ::Actions::Middleware::RemoteAction
|
6
|
-
|
7
|
-
def plan(host, consumer_params, content_view_environment, activation_keys = [])
|
8
|
-
sequence do
|
9
|
-
unless host.new_record?
|
10
|
-
host.save!
|
11
|
-
plan_action(Katello::Host::Unregister, host)
|
12
|
-
host.reload
|
13
|
-
end
|
14
|
-
|
15
|
-
unless activation_keys.empty?
|
16
|
-
content_view_environment ||= lookup_content_view_environment(activation_keys)
|
17
|
-
set_host_collections(host, activation_keys)
|
18
|
-
end
|
19
|
-
fail _('Content View and Environment not set for registration.') if content_view_environment.nil?
|
20
|
-
|
21
|
-
host.save!
|
22
|
-
host.content_facet = plan_content_facet(host, content_view_environment)
|
23
|
-
host.subscription_facet = plan_subscription_facet(host, activation_keys, consumer_params)
|
24
|
-
host.save!
|
25
|
-
|
26
|
-
action_subject host
|
27
|
-
|
28
|
-
cp_create = plan_action(Candlepin::Consumer::Create, cp_environment_id: content_view_environment.cp_id,
|
29
|
-
consumer_parameters: consumer_params, activation_keys: activation_keys.map(&:cp_name))
|
30
|
-
return if cp_create.error
|
31
|
-
|
32
|
-
plan_self(uuid: cp_create.output[:response][:uuid], host_id: host.id, hostname: host.name,
|
33
|
-
user_id: User.current.id, :facts => consumer_params[:facts])
|
34
|
-
plan_action(Pulp::Consumer::Create, uuid: cp_create.output[:response][:uuid], name: host.name)
|
35
|
-
|
36
|
-
begin
|
37
|
-
set_content_and_subscription_uuids(host, cp_create.input[:response][:uuid])
|
38
|
-
rescue => e
|
39
|
-
::Katello::Resources::Candlepin::Consumer.destroy(cp_create.input[:response][:uuid])
|
40
|
-
raise e
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def humanized_name
|
46
|
-
if input.try(:[], :hostname)
|
47
|
-
_('Register Host %s') % (input[:hostname] || _('Unknown'))
|
48
|
-
else
|
49
|
-
_('Register Host')
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def run
|
54
|
-
User.as_anonymous_admin do
|
55
|
-
host = ::Host.find(input[:host_id])
|
56
|
-
unless input[:facts].blank?
|
57
|
-
::Katello::Host::SubscriptionFacet.update_facts(host, input[:facts])
|
58
|
-
input[:facts] = 'TRIMMED'
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def finalize
|
64
|
-
User.as_anonymous_admin do
|
65
|
-
host = ::Host.find(input[:host_id])
|
66
|
-
host.subscription_facet.update_from_consumer_attributes(host.subscription_facet.candlepin_consumer.
|
67
|
-
consumer_attributes.except(:installedProducts, :guestIds, :facts))
|
68
|
-
host.subscription_facet.save!
|
69
|
-
host.subscription_facet.update_subscription_status
|
70
|
-
host.content_facet.update_errata_status
|
71
|
-
host.refresh_global_status!
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def rescue_strategy
|
76
|
-
Dynflow::Action::Rescue::Skip
|
77
|
-
end
|
78
|
-
|
79
|
-
private
|
80
|
-
|
81
|
-
def set_host_collections(host, activation_keys)
|
82
|
-
host_collection_ids = activation_keys.flat_map(&:host_collection_ids).compact.uniq
|
83
|
-
|
84
|
-
host_collection_ids.each do |host_collection_id|
|
85
|
-
host_collection = ::Katello::HostCollection.find(host_collection_id)
|
86
|
-
if !host_collection.unlimited_hosts && host_collection.max_hosts >= 0 &&
|
87
|
-
host_collection.hosts.length >= host_collection.max_hosts
|
88
|
-
fail _("Host collection '%{name}' exceeds maximum usage limit of '%{limit}'") %
|
89
|
-
{:limit => host_collection.max_hosts, :name => host_collection.name}
|
90
|
-
end
|
91
|
-
end
|
92
|
-
host.host_collection_ids = host_collection_ids
|
93
|
-
end
|
94
|
-
|
95
|
-
def lookup_content_view_environment(activation_keys)
|
96
|
-
activation_key = activation_keys.reverse.detect do |act_key|
|
97
|
-
act_key.environment && act_key.content_view
|
98
|
-
end
|
99
|
-
if activation_key
|
100
|
-
::Katello::ContentViewEnvironment.where(:content_view_id => activation_key.content_view, :environment_id => activation_key.environment).first
|
101
|
-
else
|
102
|
-
fail _('At least one activation key must have a lifecycle environment and content view assigned to it')
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def plan_content_facet(host, content_view_environment)
|
107
|
-
content_facet = host.content_facet || ::Katello::Host::ContentFacet.new(:host => host)
|
108
|
-
content_facet.content_view = content_view_environment.content_view
|
109
|
-
content_facet.lifecycle_environment = content_view_environment.environment
|
110
|
-
content_facet.save!
|
111
|
-
content_facet
|
112
|
-
end
|
113
|
-
|
114
|
-
def plan_subscription_facet(host, activation_keys, consumer_params)
|
115
|
-
subscription_facet = host.subscription_facet || ::Katello::Host::SubscriptionFacet.new(:host => host)
|
116
|
-
subscription_facet.last_checkin = Time.now
|
117
|
-
subscription_facet.update_from_consumer_attributes(consumer_params.except(:installedProducts, :guestIds, :facts))
|
118
|
-
subscription_facet.save!
|
119
|
-
subscription_facet.activation_keys = activation_keys
|
120
|
-
subscription_facet
|
121
|
-
end
|
122
|
-
|
123
|
-
def set_content_and_subscription_uuids(host, uuid)
|
124
|
-
host.content_facet.uuid = uuid
|
125
|
-
host.subscription_facet.uuid = uuid
|
126
|
-
host.subscription_facet.user = User.current unless User.current.nil? || User.current.hidden?
|
127
|
-
host.content_facet.save!
|
128
|
-
host.subscription_facet.save!
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Actions
|
2
|
-
module Katello
|
3
|
-
module Host
|
4
|
-
class Unregister < Actions::EntryAction
|
5
|
-
middleware.use ::Actions::Middleware::RemoteAction
|
6
|
-
|
7
|
-
def plan(host, options = {})
|
8
|
-
plan_action(Katello::Host::Destroy, host, options.merge(:unregistering => true))
|
9
|
-
end
|
10
|
-
|
11
|
-
def humanized_name
|
12
|
-
_("Unregister Host")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|