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
- #configure_host_for_new_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_installable_errata_filtered(host, filter = '') ⇒ Object
- #host_installable_errata_ids(host) ⇒ Object
- #host_latest_applicable_rpm_version(host, package) ⇒ Object
- #host_latest_installable_rpm_version(host, package) ⇒ Object
- #host_products(host) ⇒ Object
- #host_products_names(host) ⇒ Object
- #host_products_names_and_ids(host) ⇒ Object
- #host_sla(host) ⇒ Object
- #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, expiring_in_days: 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
#configure_host_for_new_content_source(host, ca_cert) ⇒ Object
308 309 310 311 312 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 308 def configure_host_for_new_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
143 144 145 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 143 def host_applicable_errata_filtered(host, filter = '') host.applicable_errata.includes(:cves).search_for(filter) end |
#host_applicable_errata_ids(host) ⇒ Object
125 126 127 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 125 def host_applicable_errata_ids(host) host.applicable_errata.pluck(:errata_id) end |
#host_collections(host) ⇒ Object
75 76 77 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 75 def host_collections(host) host.host_collections end |
#host_collections_names(host) ⇒ Object
83 84 85 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 83 def host_collections_names(host) host.host_collections.map(&:name) end |
#host_content_facet(host) ⇒ Object
25 26 27 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 25 def host_content_facet(host) host.content_facet end |
#host_installable_errata_filtered(host, filter = '') ⇒ Object
152 153 154 155 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 152 def host_installable_errata_filtered(host, filter = '') return [] if host.content_facet.nil? host.installable_errata.includes(:cves).search_for(filter) end |
#host_installable_errata_ids(host) ⇒ Object
133 134 135 136 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 133 def host_installable_errata_ids(host) return [] if host.content_facet.nil? host.installable_errata.pluck(:errata_id) end |
#host_latest_applicable_rpm_version(host, package) ⇒ Object
162 163 164 165 166 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 162 def host_latest_applicable_rpm_version(host, package) return [] if host.content_facet.nil? applicable = ::Katello::Rpm.latest(host.applicable_rpms.where(name: package)) applicable.present? ? applicable.first.nvra : [] end |
#host_latest_installable_rpm_version(host, package) ⇒ Object
173 174 175 176 177 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 173 def host_latest_installable_rpm_version(host, package) return [] if host.content_facet.nil? installable = ::Katello::Rpm.latest(host.installable_rpms.where(name: package)) installable.present? ? installable.first.nvra : [] end |
#host_products(host) ⇒ Object
41 42 43 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 41 def host_products(host) host_subscription_facet(host)&.installed_products end |
#host_products_names(host) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 49 def host_products_names(host) products = host_products(host) if products products.map(&:name) else [] end end |
#host_products_names_and_ids(host) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 62 def host_products_names_and_ids(host) products = host_products(host) if products products.collect { |product| "#{product.name} (#{product.cp_product_id})" } else [] end end |
#host_sla(host) ⇒ Object
33 34 35 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 33 def host_sla(host) host_subscription_facet(host)&.service_level end |
#last_checkin(host) ⇒ Object
200 201 202 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 200 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
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 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 219 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)' 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 ') search = [search_up_to, search_since, search_result, "state = stopped", labels].compact.join(' and ') tasks = load_resource(klass: ForemanTasks::Task, permission: 'view_foreman_tasks', joins: [:template_invocation], preload: [:template_invocation], 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' && !(filter_errata_type == current_erratum_errata_type) next 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, expiring_in_days: nil) ⇒ Object
188 189 190 191 192 193 194 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 188 def load_pools(search: '', includes: nil, expiring_in_days: nil) pools = Pool.readable if expiring_in_days pools = pools.expiring_in_days(expiring_in_days) end load_resource(klass: pools, search: search, permission: nil, includes: includes) end |
#registered_at(host) ⇒ Object
117 118 119 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 117 def registered_at(host) host_subscription_facet(host)&.registered_at end |
#registered_through(host) ⇒ Object
109 110 111 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 109 def registered_through(host) host_subscription_facet(host)&.registered_through end |
#sortable_version(version) ⇒ Object
299 300 301 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 299 def sortable_version(version) Util::Package.sortable_version(version) end |
#sub_name(pool) ⇒ Object
91 92 93 94 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 91 def sub_name(pool) return unless pool pool.subscription&.name end |
#sub_sku(pool) ⇒ Object
100 101 102 103 |
# File 'app/lib/katello/concerns/base_template_scope_extensions.rb', line 100 def sub_sku(pool) return unless pool pool.subscription&.cp_id end |