Module: Katello::Concerns::RedhatExtensions

Extended by:
ActiveSupport::Concern
Defined in:
app/models/katello/concerns/redhat_extensions.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#distribution_repositories(host, content_facet: nil) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/models/katello/concerns/redhat_extensions.rb', line 73

def distribution_repositories(host, content_facet: nil)
  content_facet ||= host.content_facet
  case content_facet
  when ::Katello::Host::ContentFacet
    if content_facet.new_record?
      content_views = ::Katello::ContentView.where(id: content_facet.content_view_environments.map(&:content_view_id))
      lifecycle_environments = ::Katello::KTEnvironment.where(id: content_facet.content_view_environments.map(&:environment_id))
    else
      content_views = content_facet.try(:content_views) || host.try(:content_views)
      lifecycle_environments = content_facet.try(:lifecycle_environments) || host.try(:lifecycle_environments)
    end
  when ::Katello::Hostgroup::ContentFacet
    content_views = [content_facet.try(:content_view), host.try(:content_views)].flatten.compact
    lifecycle_environments = [content_facet.try(:lifecycle_environment), host.try(:lifecycle_environments)].flatten.compact
  end
  if content_views.present? && lifecycle_environments.present? && host.os && host.architecture
    Katello::Repository.in_environment(lifecycle_environments).in_content_views(content_views).
        where(:distribution_arch => host.architecture.name).
        where("#{Katello::Repository.table_name}.distribution_version = :release or #{Katello::Repository.table_name}.distribution_version like :match",
                release: host.os.release, match: "#{host.os.release}.%")
  else
    Katello::Repository.none
  end
end

#kickstart_repos(host, content_facet: nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'app/models/katello/concerns/redhat_extensions.rb', line 52

def kickstart_repos(host, content_facet: nil)
  distros = distribution_repositories(host, content_facet: content_facet).where(distribution_bootable: true)
  content_facet ||= host.content_facet
  cs = content_facet&.content_source || host.try(:content_source)
  if distros && cs
    distros.map { |distro| distro.to_hash(cs) }
  else
    []
  end
end

#variant_repos(host, variant) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'app/models/katello/concerns/redhat_extensions.rb', line 63

def variant_repos(host, variant)
  if variant && host.content_source
    product_id = host.try(:content_facet).try(:kickstart_repository).try(:product_id) || host.try(:kickstart_repository).try(:product_id)
    distribution_repositories(host)
      .joins(:product)
      .where("#{Katello::Repository.table_name}.distribution_variant LIKE :variant", { variant: "%#{variant}%" })
      .where("#{Katello::Product.table_name}.id": product_id).collect { |repo| repo.to_hash(host.content_source, true) }
  end
end