Module: ForemanPuppet::PuppetFacetCommon
- Extended by:
- ActiveSupport::Concern
- Included in:
- HostPuppetFacet, HostgroupPuppetFacet
- Defined in:
- app/models/foreman_puppet/puppet_facet_common.rb
Overview
Common methods between host and hostgroup mostly for template rendering consistency
Instance Method Summary collapse
- #all_puppetclass_ids ⇒ Object
- #available_puppetclasses ⇒ Object
- #cg_class_ids ⇒ Object
- #classes(env = environment) ⇒ Object
- #classes_in_groups ⇒ Object
- #hg_class_ids ⇒ Object
- #host_class_ids ⇒ Object
-
#individual_puppetclasses ⇒ Object
Returns Puppetclasses of a Host or Hostgroup.
- #parent_name ⇒ Object
- #puppetclass_ids ⇒ Object
Instance Method Details
#all_puppetclass_ids ⇒ Object
49 50 51 |
# File 'app/models/foreman_puppet/puppet_facet_common.rb', line 49 def all_puppetclass_ids cg_class_ids + hg_class_ids + host_class_ids end |
#available_puppetclasses ⇒ Object
85 86 87 88 |
# File 'app/models/foreman_puppet/puppet_facet_common.rb', line 85 def available_puppetclasses return ForemanPuppet::Puppetclass.all.(:view_puppetclasses) if environment.blank? environment.puppetclasses - parent_classes end |
#cg_class_ids ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'app/models/foreman_puppet/puppet_facet_common.rb', line 25 def cg_class_ids cg_ids = if is_a?(ForemanPuppet::HostgroupPuppetFacet) hostgroup.path.each.map { |hg| hg.puppet&.config_group_ids }.compact.flatten.uniq else host.hostgroup ? host.hostgroup.path.each.map { |hg| hg.puppet&.config_group_ids }.compact.flatten.uniq : [] end ForemanPuppet::ConfigGroupClass.where(config_group_id: (config_group_ids + cg_ids)).pluck(:puppetclass_id) end |
#classes(env = environment) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'app/models/foreman_puppet/puppet_facet_common.rb', line 53 def classes(env = environment) conditions = { id: all_puppetclass_ids } if env env.puppetclasses.where(conditions) else ForemanPuppet::Puppetclass.where(conditions) end end |
#classes_in_groups ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'app/models/foreman_puppet/puppet_facet_common.rb', line 66 def classes_in_groups conditions = { id: cg_class_ids } if environment environment.puppetclasses.where(conditions) - parent_classes else ForemanPuppet::Puppetclass.where(conditions) - parent_classes end end |
#hg_class_ids ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/foreman_puppet/puppet_facet_common.rb', line 34 def hg_class_ids hg_ids = if is_a?(HostgroupPuppetFacet) hostgroup.path_ids elsif host.hostgroup host.hostgroup.path_ids end ForemanPuppet::HostgroupClass.joins(:hostgroup_puppet_facet) .where(ForemanPuppet::HostgroupPuppetFacet.arel_table[:hostgroup_id].in(hg_ids)) .pluck(:puppetclass_id) end |
#host_class_ids ⇒ Object
45 46 47 |
# File 'app/models/foreman_puppet/puppet_facet_common.rb', line 45 def host_class_ids (is_a?(ForemanPuppet::HostPuppetFacet) ? host_classes : hostgroup_classes).map(&:puppetclass_id) end |
#individual_puppetclasses ⇒ Object
Returns Puppetclasses of a Host or Hostgroup
It does not include Puppetclasses of it’s ConfigGroupClasses
79 80 81 82 83 |
# File 'app/models/foreman_puppet/puppet_facet_common.rb', line 79 def individual_puppetclasses ids = host_class_ids - cg_class_ids return puppetclasses if ids.blank? && new_record? ForemanPuppet::Puppetclass.includes(:environments).where(id: ids) end |
#parent_name ⇒ Object
17 18 19 20 21 22 23 |
# File 'app/models/foreman_puppet/puppet_facet_common.rb', line 17 def parent_name if is_a?(ForemanPuppet::HostPuppetFacet) host.hostgroup&.name elsif is_a?(ForemanPuppet::HostgroupPuppetFacet) hostgroup.parent&.name end end |
#puppetclass_ids ⇒ Object
62 63 64 |
# File 'app/models/foreman_puppet/puppet_facet_common.rb', line 62 def puppetclass_ids classes.reorder('').pluck('puppetclasses.id') end |