Module: Katello::Concerns::BaseTemplateScopeExtensions
- Extended by:
- ActiveSupport::Concern, ApipieDSL::Module
- Includes:
- Katello::ContentSourceHelper
- Defined in:
- app/lib/katello/concerns/base_template_scope_extensions.rb
Instance Method Summary collapse
- #change_content_source(host, ca_cert) ⇒ Object
- #errata(id) ⇒ Object
- #host_applicable_errata_filtered(host, filter = '') ⇒ Object
- #host_applicable_errata_ids(host) ⇒ Object
- #host_collections(host) ⇒ Object
- #host_collections_names(host) ⇒ Object
- #host_content_facet(host) ⇒ Object
- #host_latest_applicable_rpm_version(host, package) ⇒ Object
- #host_products(host) ⇒ Object
- #host_products_names(host) ⇒ Object
- #host_redhat_subscription_names(host) ⇒ Object
- #host_redhat_subscriptions_consumed(host) ⇒ Object
- #host_sla(host) ⇒ Object
- #host_subscriptions(host) ⇒ Object
- #host_subscriptions_names(host) ⇒ Object
- #katello_agent_enabled? ⇒ Boolean
- #last_checkin(host) ⇒ Object
-
#load_errata_applications(filter_errata_type: nil, include_last_reboot: 'yes', since: nil, up_to: nil, status: nil, host_filter: nil) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity.
- #load_pools(search: '', includes: nil) ⇒ Object
- #registered_at(host) ⇒ Object
- #registered_through(host) ⇒ Object
- #sortable_version(version) ⇒ Object
- #sub_name(pool) ⇒ Object
- #sub_sku(pool) ⇒ Object
Methods included from Katello::ContentSourceHelper
#configure_subman, #missing_content_source, #prepare_ssl_cert, #reconfigure_yggdrasild
Instance Method Details
#change_content_source(host, ca_cert) ⇒ Object
301 302 303 304 305 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 301 def change_content_source(host, ca_cert) return missing_content_source(host) unless host.content_source prepare_ssl_cert(ca_cert) + configure_subman(host.content_source) end |
#errata(id) ⇒ Object
16 17 18 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 16 def errata(id) Katello::Erratum.in_repositories(Katello::Repository.readable).with_identifiers(id).map(&:attributes).first.slice!('created_at', 'updated_at') end |
#host_applicable_errata_filtered(host, filter = '') ⇒ Object
154 155 156 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 154 def host_applicable_errata_filtered(host, filter = '') host.applicable_errata.includes(:cves).search_for(filter) end |
#host_applicable_errata_ids(host) ⇒ Object
145 146 147 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 145 def host_applicable_errata_ids(host) host.applicable_errata.map(&:errata_id) end |
#host_collections(host) ⇒ Object
95 96 97 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 95 def host_collections(host) host.host_collections end |
#host_collections_names(host) ⇒ Object
103 104 105 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 103 def host_collections_names(host) host.host_collections.map(&:name) end |
#host_content_facet(host) ⇒ Object
58 59 60 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 58 def host_content_facet(host) host.content_facet end |
#host_latest_applicable_rpm_version(host, package) ⇒ Object
163 164 165 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 163 def host_latest_applicable_rpm_version(host, package) ::Katello::Rpm.latest(host.applicable_rpms.where(name: package))&.first&.nvra end |
#host_products(host) ⇒ Object
74 75 76 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 74 def host_products(host) host_subscription_facet(host)&.installed_products end |
#host_products_names(host) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 82 def host_products_names(host) products = host_products(host) if products products.map(&:name) else [] end end |
#host_redhat_subscription_names(host) ⇒ Object
40 41 42 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 40 def host_redhat_subscription_names(host) host.subscriptions.redhat.pluck(:name) end |
#host_redhat_subscriptions_consumed(host) ⇒ Object
48 49 50 51 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 48 def host_redhat_subscriptions_consumed(host) presenter = ::Katello::HostSubscriptionsPresenter.new(host) presenter.subscriptions.select(&:redhat?).sum(&:quantity_consumed) end |
#host_sla(host) ⇒ Object
66 67 68 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 66 def host_sla(host) host_subscription_facet(host)&.service_level end |
#host_subscriptions(host) ⇒ Object
24 25 26 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 24 def host_subscriptions(host) host.subscriptions end |
#host_subscriptions_names(host) ⇒ Object
32 33 34 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 32 def host_subscriptions_names(host) host.subscriptions.map(&:name) end |
#katello_agent_enabled? ⇒ Boolean
292 293 294 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 292 def katello_agent_enabled? Katello.with_katello_agent? end |
#last_checkin(host) ⇒ Object
183 184 185 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 183 def last_checkin(host) host&.subscription_facet&.last_checkin end |
#load_errata_applications(filter_errata_type: nil, include_last_reboot: 'yes', since: nil, up_to: nil, status: nil, host_filter: nil) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 202 def load_errata_applications(filter_errata_type: nil, include_last_reboot: 'yes', since: nil, up_to: nil, status: nil, host_filter: nil) result = [] filter_errata_type = filter_errata_type.presence || 'all' search_up_to = up_to.present? ? "ended_at < \"#{up_to}\"" : nil search_since = since.present? ? "ended_at > \"#{since}\"" : nil search_result = status.present? && status != 'all' ? "result = #{status}" : nil labels = 'label ^ (Actions::Katello::Host::Erratum::Install, Actions::Katello::Host::Erratum::ApplicableErrataInstall)' select = 'foreman_tasks_tasks.*' if Katello.with_remote_execution? new_labels = 'label = Actions::RemoteExecution::RunHostJob AND remote_execution_feature.label ^ (katello_errata_install, katello_errata_install_by_search)' labels = [labels, new_labels].map { |label| "(#{label})" }.join(' OR ') select += ',template_invocations.id AS template_invocation_id' else select += ',NULL AS template_invocation_id' end search = [search_up_to, search_since, search_result, "state = stopped", labels].compact.join(' and ') tasks = load_resource(klass: ForemanTasks::Task, permission: 'view_foreman_tasks', select: select, search: search) only_host_ids = ::Host.search_for(host_filter).pluck(:id) if host_filter # batch of 1_000 records tasks.each do |batch| @_tasks_input = {} @_tasks_errata_cache = {} seen_errata_ids = [] seen_host_ids = [] batch.each do |task| next if skip_task?(task) seen_errata_ids = (seen_errata_ids + parse_errata(task)).uniq seen_host_ids << get_task_input(task)['host']['id'].to_i if include_last_reboot == 'yes' end seen_host_ids &= only_host_ids if only_host_ids # preload errata in one query for this batch preloaded_errata = Katello::Erratum.where(:errata_id => seen_errata_ids).pluck(:errata_id, :errata_type, :issued) preloaded_hosts = ::Host.where(:id => seen_host_ids).includes(:reported_data) batch.each do |task| next if skip_task?(task) next unless only_host_ids.nil? || only_host_ids.include?(get_task_input(task)['host']['id'].to_i) parse_errata(task).each do |erratum_id| current_erratum = preloaded_errata.find { |k, _| k == erratum_id } next if current_erratum.nil? current_erratum_errata_type = current_erratum[1] current_erratum_issued = current_erratum.last if filter_errata_type != 'all' next unless filter_errata_type == current_erratum_errata_type end hash = { :date => task.ended_at, :hostname => get_task_input(task)['host']['name'], :erratum_id => erratum_id, :erratum_type => current_erratum_errata_type, :issued => current_erratum_issued, :status => task.result } if include_last_reboot == 'yes' # It is possible that we can't find the host if it has been deleted. hash[:last_reboot_time] = preloaded_hosts.find { |k, _| k.id == get_task_input(task)['host']['id'].to_i }&.uptime_seconds&.seconds&.ago end result << hash end end end result end |
#load_pools(search: '', includes: nil) ⇒ Object
175 176 177 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 175 def load_pools(search: '', includes: nil) load_resource(klass: Pool.readable, search: search, permission: nil, includes: includes) end |
#registered_at(host) ⇒ Object
137 138 139 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 137 def registered_at(host) host_subscription_facet(host)&.registered_at end |
#registered_through(host) ⇒ Object
129 130 131 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 129 def registered_through(host) host_subscription_facet(host)&.registered_through end |
#sortable_version(version) ⇒ Object
287 288 289 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 287 def sortable_version(version) Util::Package.sortable_version(version) end |
#sub_name(pool) ⇒ Object
111 112 113 114 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 111 def sub_name(pool) return unless pool pool.subscription&.name end |
#sub_sku(pool) ⇒ Object
120 121 122 123 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 120 def sub_sku(pool) return unless pool pool.subscription&.cp_id end |