diff --git a/app/models/concerns/foreman_puppet/extensions/host.rb b/app/models/concerns/foreman_puppet/extensions/host.rb index 56177faa..20ec978d 100644 --- a/app/models/concerns/foreman_puppet/extensions/host.rb +++ b/app/models/concerns/foreman_puppet/extensions/host.rb @@ -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) diff --git a/app/models/concerns/foreman_puppet/extensions/hostgroup.rb b/app/models/concerns/foreman_puppet/extensions/hostgroup.rb index a311b087..225ff691 100644 --- a/app/models/concerns/foreman_puppet/extensions/hostgroup.rb +++ b/app/models/concerns/foreman_puppet/extensions/hostgroup.rb @@ -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) + 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)