Module: ForemanPuppet::Extensions::Hostgroup::PatchedClassMethods

Defined in:
app/models/concerns/foreman_puppet/extensions/hostgroup.rb

Overview

Temporary, can be ordinary class_methods do, when removed from core

Instance Method Summary collapse

Instance Method Details

#search_by_config_group(_key, operator, value) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'app/models/concerns/foreman_puppet/extensions/hostgroup.rb', line 35

def search_by_config_group(_key, operator, value)
  conditions = sanitize_sql_for_conditions(["config_groups.name #{operator} ?", value_to_sql(operator, value)])
  hostgroup_ids = ::Hostgroup.joins(puppet: :config_groups).where(conditions).map(&:subtree_ids).flatten.uniq

  conds = 'hostgroups.id < 0'
  conds = "hostgroups.id IN(#{hostgroup_ids.join(',')})" if hostgroup_ids.present?

  { conditions: conds }
end

#search_by_puppetclass(_key, operator, value) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'app/models/concerns/foreman_puppet/extensions/hostgroup.rb', line 45

def search_by_puppetclass(_key, operator, value)
  conditions = sanitize_sql_for_conditions(["puppetclasses.name #{operator} ?", value_to_sql(operator, value)])
  hostgroup_ids = ::Hostgroup.joins(puppet: :puppetclasses).where(conditions).map(&:subtree_ids)

  conds = []
  conds << "hostgroups.id IN (#{hostgroup_ids.join(',')})" if hostgroup_ids.present?

  { conditions: conds.join(' OR ').presence || 'hostgroups.id < 0' }
end