Skip to content

Commit

Permalink
Fixes #36207 - assign puppet attributes from hostgroup
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernhard committed Jun 28, 2024
1 parent b706bfd commit 72d1b94
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/models/concerns/foreman_puppet/extensions/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ def search_by_config_group(_key, operator, value)
end

module PrependedMethods
def environment_id=(id)
self.environment = ForemanPuppet::Environment.find(id)
save
end

def inherited_attributes
super.concat(%w[environment_id puppet_proxy_id puppet_ca_proxy_id])
end

def provisioning_template(opts = {})
opts[:environment_id] ||= puppet&.environment_id
super(opts)
Expand Down
20 changes: 20 additions & 0 deletions app/models/concerns/foreman_puppet/extensions/hostgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ class << self
ext_method: :search_by_config_group
end

def inherited_puppet_hostgroup_attribute(attribute)
if ancestry.present?
self[attribute] || self.class.sort_by_ancestry(ancestors.where.not(attribute => nil)).last.try(attribute)
else
self.send(attribute)

Check failure on line 37 in app/models/concerns/foreman_puppet/extensions/hostgroup.rb

View workflow job for this annotation

GitHub Actions / rubocop / Rubocop

Style/RedundantSelf: Redundant `self` detected.
end
end

def inherited_environment_id
inherited_puppet_hostgroup_attribute(:environment_id)
end

def inherited_puppet_proxy_id
inherited_puppet_hostgroup_attribute(:puppet_proxy_id)
end

def inherited_puppet_ca_proxy_id
inherited_puppet_hostgroup_attribute(:puppet_ca_proxy_id)
end

# Temporary, can be ordinary class_methods do, when removed from core
module PatchedClassMethods
def search_by_config_group(_key, operator, value)
Expand Down

0 comments on commit 72d1b94

Please sign in to comment.