Class: Katello::Host::ContentFacet

Inherits:
Model
  • Object
show all
Defined in:
app/models/katello/host/content_facet.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#destroy!

Class Method Details

.in_content_view_version_environments(version_environments) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'app/models/katello/host/content_facet.rb', line 76

def self.in_content_view_version_environments(version_environments)
  #takes a structure of [{:content_view_version => ContentViewVersion, :environments => [KTEnvironment]}]
  queries = version_environments.map do |version_environment|
    version = version_environment[:content_view_version]
    env_ids = version_environment[:environments].map(&:id)
    "(#{table_name}.content_view_id = #{version.content_view_id} AND #{table_name}.lifecycle_environment_id IN (#{env_ids.join(',')}))"
  end
  where(queries.join(" OR "))
end

.joins_installable_errataObject



100
101
102
103
104
105
106
107
108
109
110
# File 'app/models/katello/host/content_facet.rb', line 100

def self.joins_installable_errata
  facet_repository = Katello::ContentFacetRepository.table_name
  facet_errata = Katello::ContentFacetErratum.table_name
  repository_erratum = Katello::RepositoryErratum.table_name
  erratum = Katello::Erratum.table_name

  self.joins("INNER JOIN #{facet_repository} on #{facet_repository}.content_facet_id = #{table_name}.id",
             "INNER JOIN #{repository_erratum} on #{repository_erratum}.repository_id = #{facet_repository}.repository_id",
             "INNER JOIN #{erratum} on #{erratum}.id = #{repository_erratum}.erratum_id",
             "INNER JOIN #{facet_errata} on #{facet_errata}.erratum_id = #{erratum}.id")
end

.with_applicable_errata(errata) ⇒ Object



92
93
94
# File 'app/models/katello/host/content_facet.rb', line 92

def self.with_applicable_errata(errata)
  self.joins(:applicable_errata).where("#{Katello::Erratum.table_name}.id" => errata)
end

.with_installable_errata(errata) ⇒ Object



96
97
98
# File 'app/models/katello/host/content_facet.rb', line 96

def self.with_installable_errata(errata)
  joins_installable_errata.where("#{Katello::Erratum.table_name}.id" => errata)
end

.with_non_installable_errata(errata) ⇒ Object



86
87
88
89
90
# File 'app/models/katello/host/content_facet.rb', line 86

def self.with_non_installable_errata(errata)
  subquery = Katello::Erratum.select("#{Katello::Erratum.table_name}.id").installable_for_hosts
  .where("#{Katello::ContentFacetRepository.table_name}.content_facet_id = #{Katello::Host::ContentFacet.table_name}.id").to_sql
  self.joins(:applicable_errata).where("#{Katello::Erratum.table_name}.id" => errata).where("#{Katello::Erratum.table_name}.id NOT IN (#{subquery})").uniq
end

Instance Method Details

#available_releasesObject



116
117
118
# File 'app/models/katello/host/content_facet.rb', line 116

def available_releases
  self.content_view.version(self.lifecycle_environment).available_releases
end

#content_view_versionObject



112
113
114
# File 'app/models/katello/host/content_facet.rb', line 112

def content_view_version
  content_view.version(lifecycle_environment)
end

#import_applicability(partial = false) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/models/katello/host/content_facet.rb', line 54

def import_applicability(partial = false)
  facet = self
  errata_uuids = ::Katello::Pulp::Consumer.new(self.uuid).applicable_errata_ids
  ::Katello::Util::Support.active_record_retry do
    if partial
      consumer_uuids = applicable_errata.pluck("#{Erratum.table_name}.uuid")
      to_remove = consumer_uuids - errata_uuids
      to_add = errata_uuids - consumer_uuids
    else
      to_add = errata_uuids
      to_remove = nil
      Katello::ContentFacetErratum.where(:content_facet_id => facet.id).delete_all
    end

    ActiveRecord::Base.transaction do
      insert_errata_applicability(to_add) unless to_add.blank?
      remove_errata_applicability(to_remove) unless to_remove.blank?
    end
  end
  host.get_status(::Katello::ErrataStatus).refresh!
end

#installable_errata(env = nil, content_view = nil) ⇒ Object



45
46
47
48
49
50
51
52
# File 'app/models/katello/host/content_facet.rb', line 45

def installable_errata(env = nil, content_view = nil)
  repos = if env && content_view
            Katello::Repository.in_environment(env).in_content_views([content_view])
          else
            self.bound_repositories.pluck(:id)
          end
  self.applicable_errata.in_repositories(repos).uniq
end

#katello_agent_installed?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'app/models/katello/host/content_facet.rb', line 120

def katello_agent_installed?
  self.host.installed_packages.where("#{Katello::InstalledPackage.table_name}.name" => 'katello-agent').any?
end

#propagate_yum_reposObject



40
41
42
43
# File 'app/models/katello/host/content_facet.rb', line 40

def propagate_yum_repos
  pulp_ids = self.bound_repositories.includes(:library_instance).map { |repo| repo.library_instance.try(:pulp_id) || repo.pulp_id }
  Katello::Pulp::Consumer.new(self.uuid).bind_yum_repositories(pulp_ids)
end

#update_repositories_by_paths(paths) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/katello/host/content_facet.rb', line 24

def update_repositories_by_paths(paths)
  paths = paths.map { |path| path.gsub('/pulp/repos/', '') }
  repos = Repository.where(:relative_path => paths)

  missing = paths - repos.pluck(:relative_path)
  missing.each do |repo_path|
    Rails.logger.warn("System #{self.host.name} (#{self.host.id}) requested binding to unknown repo #{repo_path}")
  end

  self.bound_repositories = repos
  self.save!
  self.propagate_yum_repos
  ForemanTasks.async_task(Actions::Katello::Host::GenerateApplicability, [self.host])
  self.bound_repositories.pluck(:relative_path)
end