Module: Katello::Concerns::ContentFacetHostExtensions::ClassMethods

Defined in:
app/models/katello/concerns/content_facet_host_extensions.rb

Instance Method Summary collapse

Instance Method Details

#find_by_applicable_debs(_key, operator, value) ⇒ Object



115
116
117
118
119
120
121
122
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 115

def find_by_applicable_debs(_key, operator, value)
  hosts = find_by_debs(::Host::Managed.joins(:applicable_debs), operator, value)
  if hosts.empty?
    { :conditions => "1=0" }
  else
    { :conditions => "#{::Host::Managed.table_name}.id IN (#{hosts.pluck(:id).join(',')})" }
  end
end

#find_by_applicable_errata(_key, operator, value) ⇒ Object



103
104
105
106
107
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 103

def find_by_applicable_errata(_key, operator, value)
  conditions = sanitize_sql_for_conditions(["#{Katello::Erratum.table_name}.errata_id #{operator} ?", value_to_sql(operator, value)])
  hosts = ::Host::Managed.joins(:applicable_errata).select(:id).where(conditions)
  { :conditions => "#{::Host::Managed.table_name}.id IN (#{hosts.to_sql})" }
end

#find_by_applicable_rpms(_key, operator, value) ⇒ Object



133
134
135
136
137
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 133

def find_by_applicable_rpms(_key, operator, value)
  conditions = sanitize_sql_for_conditions(["#{Katello::Rpm.table_name}.nvra #{operator} ?", value_to_sql(operator, value)])
  hosts = ::Host::Managed.joins(:applicable_rpms).select(:id).where(conditions)
  { :conditions => "#{::Host::Managed.table_name}.id IN (#{hosts.to_sql})" }
end

#find_by_image_mode(_key, _operator, value) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 91

def find_by_image_mode(_key, _operator, value)
  # operator is always '='
  state = ::Foreman::Cast.to_bool(value)
  if state
    hosts = ::Host::Managed.joins(:content_facet).select(:id).where.not("#{::Katello::Host::ContentFacet.table_name}.bootc_booted_image" => nil)
  else
    # left_outer_joins will include hosts without a content facet. We assume such hosts are package-mode hosts.
    hosts = ::Host::Managed.left_outer_joins(:content_facet).select(:id).where("#{::Katello::Host::ContentFacet.table_name}.bootc_booted_image" => nil)
  end
  { :conditions => "#{::Host::Managed.table_name}.id IN (#{hosts.to_sql})" }
end

#find_by_installable_debs(_key, operator, value) ⇒ Object



124
125
126
127
128
129
130
131
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 124

def find_by_installable_debs(_key, operator, value)
  facets = find_by_debs(Katello::Host::ContentFacet.joins_installable_debs, operator, value)
  if facets.empty?
    { :conditions => "1=0" }
  else
    { :conditions => "#{::Host::Managed.table_name}.id IN (#{facets.pluck(:host_id).join(',')})" }
  end
end

#find_by_installable_errata(_key, operator, value) ⇒ Object



109
110
111
112
113
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 109

def find_by_installable_errata(_key, operator, value)
  conditions = sanitize_sql_for_conditions(["#{Katello::Erratum.table_name}.errata_id #{operator} ?", value_to_sql(operator, value)])
  facets = Katello::Host::ContentFacet.joins_installable_errata.select(:host_id).where(conditions)
  { :conditions => "#{::Host::Managed.table_name}.id IN (#{facets.to_sql})" }
end

#find_by_installable_rpms(_key, operator, value) ⇒ Object



139
140
141
142
143
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 139

def find_by_installable_rpms(_key, operator, value)
  conditions = sanitize_sql_for_conditions(["#{Katello::Rpm.table_name}.nvra #{operator} ?", value_to_sql(operator, value)])
  facets = Katello::Host::ContentFacet.joins_installable_rpms.select(:host_id).where(conditions)
  { :conditions => "#{::Host::Managed.table_name}.id IN (#{facets.to_sql})" }
end

#find_by_repository_content_label(_key, operator, value) ⇒ Object



145
146
147
148
149
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 145

def (_key, operator, value)
  conditions = sanitize_sql_for_conditions(["#{Katello::Content.table_name}.label #{operator} ?", value_to_sql(operator, value)])
  facets = Katello::Host::ContentFacet.joins_repositories.select(:host_id).where(conditions)
  { :conditions => "#{::Host::Managed.table_name}.id IN (#{facets.to_sql})" }
end

#find_by_repository_name(_key, operator, value) ⇒ Object



151
152
153
154
155
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 151

def find_by_repository_name(_key, operator, value)
  conditions = sanitize_sql_for_conditions(["#{Katello::RootRepository.table_name}.name #{operator} ?", value_to_sql(operator, value)])
  facets = Katello::Host::ContentFacet.joins_repositories.select(:host_id).where(conditions)
  { :conditions => "#{::Host::Managed.table_name}.id IN (#{facets.to_sql})" }
end

#in_content_view_environment(content_view: nil, lifecycle_environment: nil) ⇒ Object



168
169
170
171
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 168

def in_content_view_environment(content_view: nil, lifecycle_environment: nil)
  Rails.logger.warn "DEPRECATION WARNING: in_content_view_environment is deprecated and will be removed in Katello 4.8.  Please use in_content_view_environments instead."
  in_content_view_environments(:content_views => content_view, :lifecycle_environments => lifecycle_environment)
end

#in_content_view_environments(content_views: nil, lifecycle_environments: nil) ⇒ Object



157
158
159
160
161
162
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 157

def in_content_view_environments(content_views: nil, lifecycle_environments: nil)
  relation = self.joins(:content_facet => {:content_view_environment_content_facets => :content_view_environment })
  relation = relation.where("#{::Katello::ContentViewEnvironment.table_name}.content_view_id" => content_views) if content_views
  relation = relation.where("#{::Katello::ContentViewEnvironment.table_name}.environment_id" => lifecycle_environments) if lifecycle_environments
  relation
end

#in_environment(lifecycle_environment) ⇒ Object



173
174
175
176
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 173

def in_environment(lifecycle_environment)
  Rails.logger.warn "DEPRECATION WARNING: in_environment is deprecated and will be removed in Katello 4.9.  Please use in_environments instead."
  in_environments(lifecycle_environment)
end

#in_environments(lifecycle_environments) ⇒ Object



164
165
166
# File 'app/models/katello/concerns/content_facet_host_extensions.rb', line 164

def in_environments(lifecycle_environments)
  in_content_view_environments(:lifecycle_environments => lifecycle_environments)
end