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



121
122
123
124
125
126
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 121

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



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

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



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

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

#content_view_environmentObject



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

def content_view_environment
  return super if ancestry.nil? || self.content_view_environment_id.present?
  cvenv_id = inherited_ancestry_attribute(:content_view_environment_id, :content_facet)
  Katello::ContentViewEnvironment.find_by(:id => cvenv_id)
end

#content_view_nameObject



108
109
110
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 108

def content_view_name
  content_view&.name
end

#correct_kickstart_repositoryObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 41

def correct_kickstart_repository
  ensure_single_installation_source
  return unless content_facet&.kickstart_repository_id

  effective_content_facet = content_facet_with_inheritance(content_facet)
  ks_repos = operatingsystem_kickstart_repos(effective_content_facet)
  return unless kickstart_repository_stale?(ks_repos: ks_repos, effective_content_facet: effective_content_facet)

  equivalent = equivalent_kickstart_repository(ks_repos: ks_repos, effective_content_facet: effective_content_facet)
  return if equivalent.blank? || equivalent[:id] == content_facet.kickstart_repository_id

  self.content_facet.kickstart_repository_id = equivalent[:id]
end

#equivalent_kickstart_repository(ks_repos: nil, effective_content_facet: nil) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 128

def equivalent_kickstart_repository(ks_repos: nil, effective_content_facet: nil)
  return unless operatingsystem &&
                content_facet&.kickstart_repository &&
                operatingsystem.respond_to?(:kickstart_repos)
  effective_content_facet ||= content_facet_with_inheritance(content_facet)
  ks_repos ||= operatingsystem_kickstart_repos(effective_content_facet)
  return if ks_repos.blank?

  if operatingsystem_id_changing? || kickstart_repository_incompatible_with_os?
    release_match = find_kickstart_repository_by_release(ks_repos)
    return release_match if release_match

    # When the OS changes and we cannot detect a strict release match,
    # prefer non-label heuristics to avoid sticking to a stale repo label.
    return find_best_matching_kickstart_repository(ks_repos)
  end

  by_label = ks_repos.find { |repo| repo[:name] == content_facet.kickstart_repository.label }
  return by_label if by_label

  find_best_matching_kickstart_repository(ks_repos)
end

#inherited_content_source_idObject



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

def inherited_content_source_id
  inherited_ancestry_attribute(:content_source_id, :content_facet)
end

#inherited_content_view_environment_idObject



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

def inherited_content_view_environment_id
  inherited_ancestry_attribute(:content_view_environment_id, :content_facet)
end

#inherited_content_view_idObject



90
91
92
93
94
95
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 90

def inherited_content_view_id
  cvenv_id = inherited_ancestry_attribute(:content_view_environment_id, :content_facet)
  return nil unless cvenv_id

  Katello::ContentViewEnvironment.find_by(id: cvenv_id)&.content_view_id
end

#inherited_kickstart_repository_idObject



104
105
106
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 104

def inherited_kickstart_repository_id
  inherited_ancestry_attribute(:kickstart_repository_id, :content_facet)
end

#inherited_lifecycle_environment_idObject



97
98
99
100
101
102
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 97

def inherited_lifecycle_environment_id
  cvenv_id = inherited_ancestry_attribute(:content_view_environment_id, :content_facet)
  return nil unless cvenv_id

  Katello::ContentViewEnvironment.find_by(id: cvenv_id)&.environment_id
end

#kickstart_repositoryObject



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

def kickstart_repository
  return super if ancestry.nil? || self.kickstart_repository_id.present?
  Katello::Repository.find_by(:id => inherited_kickstart_repository_id)
end

#lifecycle_environmentObject



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

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

#lifecycle_environment_nameObject



112
113
114
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 112

def lifecycle_environment_name
  lifecycle_environment&.name
end

#matching_kickstart_repository?(content_facet, ks_repos: nil, effective_content_facet: nil) ⇒ Boolean

Returns:

  • (Boolean)


151
152
153
154
155
156
157
158
159
160
161
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 151

def matching_kickstart_repository?(content_facet, ks_repos: nil, effective_content_facet: nil)
  return true unless operatingsystem

  if operatingsystem.respond_to? :kickstart_repos
    effective_content_facet ||= content_facet_with_inheritance(content_facet)
    ks_repos ||= operatingsystem_kickstart_repos(effective_content_facet)
    ks_repos.any? do |repo|
      repo[:id] == (content_facet&.kickstart_repository_id || content_facet&.kickstart_repository&.id)
    end
  end
end

#rhsm_organization_labelObject



116
117
118
119
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 116

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