Module: ForemanSalt::Concerns::HostgroupExtensions

Extended by:
ActiveSupport::Concern
Defined in:
app/models/foreman_salt/concerns/hostgroup_extensions.rb

Instance Method Summary collapse

Instance Method Details

#inherited_salt_environment_idObject



52
53
54
55
56
57
58
# File 'app/models/foreman_salt/concerns/hostgroup_extensions.rb', line 52

def inherited_salt_environment_id
  if ancestry.present?
    read_attribute(:salt_environment_id) || self.class.sort_by_ancestry(ancestors.where("salt_environment_id is not NULL")).last.try(:salt_environment_id)
  else
    self.salt_environment_id
  end
end

#inherited_salt_module_idsObject



26
27
28
29
30
31
32
# File 'app/models/foreman_salt/concerns/hostgroup_extensions.rb', line 26

def inherited_salt_module_ids
  if ancestry.present?
    self.class.sort_by_ancestry(ancestors.reject { |ancestor| ancestor.salt_module_ids.empty? }).last.try(:salt_modules)
  else
    []
  end
end

#inherited_salt_modulesObject



22
23
24
# File 'app/models/foreman_salt/concerns/hostgroup_extensions.rb', line 22

def inherited_salt_modules
  ForemanSalt::SaltModule.where(:id => inherited_salt_module_ids)
end

#inherited_salt_proxy_idObject



39
40
41
42
43
44
45
# File 'app/models/foreman_salt/concerns/hostgroup_extensions.rb', line 39

def inherited_salt_proxy_id
  if ancestry.present?
    read_attribute(:salt_proxy_id) || self.class.sort_by_ancestry(ancestors.where("salt_proxy_id is not NULL")).last.try(:salt_proxy_id)
  else
    self.salt_proxy_id
  end
end

#salt_environmentObject



47
48
49
50
# File 'app/models/foreman_salt/concerns/hostgroup_extensions.rb', line 47

def salt_environment
  return super unless ancestry.present?
  ForemanSalt::SaltEnvironment.find_by_id(inherited_salt_environment_id)
end

#salt_masterObject



60
61
62
# File 'app/models/foreman_salt/concerns/hostgroup_extensions.rb', line 60

def salt_master
  salt_proxy.to_s
end

#salt_module_idsObject



17
18
19
20
# File 'app/models/foreman_salt/concerns/hostgroup_extensions.rb', line 17

def salt_module_ids
  return super unless ancestry.present?
  ([super] + [inherited_salt_module_ids]).flatten.uniq.compact
end

#salt_modulesObject



12
13
14
15
# File 'app/models/foreman_salt/concerns/hostgroup_extensions.rb', line 12

def salt_modules
  return super unless ancestry.present?
  ([super] + [inherited_salt_modules]).flatten.uniq.compact
end

#salt_proxyObject



34
35
36
37
# File 'app/models/foreman_salt/concerns/hostgroup_extensions.rb', line 34

def salt_proxy
  return super unless ancestry.present?
  SmartProxy.find_by_id(inherited_salt_proxy_id)
end