Module: Katello::Concerns::HostgroupExtensions

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

Instance Method Summary collapse

Instance Method Details

#add_organization_for_environmentObject



86
87
88
89
90
91
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 86

def add_organization_for_environment
  #ensures that the group's orgs include whatever lifecycle environment is assigned
  if self.lifecycle_environment && !self.organizations.include?(self.lifecycle_environment.organization)
    self.organizations << self.lifecycle_environment.organization
  end
end

#content_sourceObject

instead of calling nested_attribute_for(:content_source_id) in Foreman, define the methods explictedly



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

def content_source
  return super if ancestry.nil? || self.content_source_id.present?
  SmartProxy.unscoped.find_by(:id => inherited_content_source_id)
end

#content_viewObject



49
50
51
52
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 49

def content_view
  return super if ancestry.nil? || self.content_view_id.present?
  Katello::ContentView.find_by(:id => inherited_content_view_id)
end

#correct_kickstart_repositoryObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 31

def correct_kickstart_repository
  # If switched from ks repo to install media:
  if medium_id_changed? && medium && content_facet&.kickstart_repository_id
    # since it's :through association, nullify both the actual data source and delegate
    self.content_facet.kickstart_repository = nil
    self.kickstart_repository = nil
  # If switched from install media to ks repo:
  elsif content_facet&.kickstart_repository && medium
    self.medium = nil
  end

  if content_facet&.kickstart_repository_id && !matching_kickstart_repository?(content_facet)
    if (equivalent = equivalent_kickstart_repository)
      self.content_facet.kickstart_repository_id = equivalent[:id]
    end
  end
end

#equivalent_kickstart_repositoryObject



93
94
95
96
97
98
99
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 93

def equivalent_kickstart_repository
  return unless operatingsystem &&
                content_facet.kickstart_repository &&
                operatingsystem.respond_to?(:kickstart_repos)
  ks_repos = operatingsystem.kickstart_repos(self, content_facet: content_facet)
  ks_repos.find { |repo| repo[:name] == content_facet.kickstart_repository.label }
end

#inherited_content_source_idObject



65
66
67
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 65

def inherited_content_source_id
  inherited_ancestry_attribute(:content_source_id, :content_facet)
end

#inherited_content_view_idObject



69
70
71
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 69

def inherited_content_view_id
  inherited_ancestry_attribute(:content_view_id, :content_facet)
end

#inherited_kickstart_repository_idObject



77
78
79
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 77

def inherited_kickstart_repository_id
  inherited_ancestry_attribute(:kickstart_repository_id, :content_facet)
end

#inherited_lifecycle_environment_idObject



73
74
75
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 73

def inherited_lifecycle_environment_id
  inherited_ancestry_attribute(:lifecycle_environment_id, :content_facet)
end

#lifecycle_environmentObject



54
55
56
57
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 54

def lifecycle_environment
  return super if ancestry.nil? || self.lifecycle_environment_id.present?
  Katello::KTEnvironment.find_by(:id => inherited_lifecycle_environment_id)
end

#matching_kickstart_repository?(content_facet) ⇒ Boolean

Returns:

  • (Boolean)


101
102
103
104
105
106
107
108
109
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 101

def matching_kickstart_repository?(content_facet)
  return true unless operatingsystem

  if operatingsystem.respond_to? :kickstart_repos
    operatingsystem.kickstart_repos(self, content_facet: content_facet).any? do |repo|
      repo[:id] == (content_facet&.kickstart_repository_id || content_facet&.kickstart_repository&.id)
    end
  end
end

#rhsm_organization_labelObject



81
82
83
84
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 81

def rhsm_organization_label
  #used for rhsm registration snippet, since hostgroup can belong to muliple organizations, use lifecycle environment or cv
  (self.lifecycle_environment || self.content_view).try(:organization).try(:label)
end