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



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

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



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

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



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

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



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

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

#content_view_nameObject



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

def content_view_name
  content_view&.name
end

#correct_kickstart_repositoryObject



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

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) && (equivalent = equivalent_kickstart_repository)
    self.content_facet.kickstart_repository_id = equivalent[:id]
  end
end

#equivalent_kickstart_repositoryObject



127
128
129
130
131
132
133
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 127

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



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

def inherited_content_source_id
  inherited_ancestry_attribute(:content_source_id, :content_facet)
end

#inherited_content_view_idObject



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

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

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

#inherited_kickstart_repository_idObject



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

def inherited_kickstart_repository_id
  inherited_ancestry_attribute(:kickstart_repository_id, :content_facet)
end

#inherited_lifecycle_environment_idObject



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

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

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

#kickstart_repositoryObject



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

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



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

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



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

def lifecycle_environment_name
  lifecycle_environment&.name
end

#matching_kickstart_repository?(content_facet) ⇒ Boolean

Returns:

  • (Boolean)


135
136
137
138
139
140
141
142
143
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 135

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



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

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