Module: Katello::Concerns::HostgroupExtensions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/katello/concerns/hostgroup_extensions.rb
Instance Method Summary collapse
- #add_organization_for_environment ⇒ Object
-
#content_source ⇒ Object
instead of calling nested_attribute_for(:content_source_id) in Foreman, define the methods explictedly.
- #content_view ⇒ Object
- #correct_kickstart_repository ⇒ Object
- #equivalent_kickstart_repository ⇒ Object
- #inherited_content_source_id ⇒ Object
- #inherited_content_view_id ⇒ Object
- #inherited_kickstart_repository_id ⇒ Object
- #inherited_lifecycle_environment_id ⇒ Object
- #kickstart_repository ⇒ Object
- #lifecycle_environment ⇒ Object
- #matching_kickstart_repository?(content_facet) ⇒ Boolean
- #rhsm_organization_label ⇒ Object
Instance Method Details
#add_organization_for_environment ⇒ Object
89 90 91 92 93 94 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 89 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_source ⇒ Object
instead of calling nested_attribute_for(:content_source_id) in Foreman, define the methods explictedly
63 64 65 66 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 63 def content_source return super if ancestry.nil? || self.content_source_id.present? SmartProxy.unscoped.find_by(:id => inherited_content_source_id) end |
#content_view ⇒ Object
47 48 49 50 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 47 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_repository ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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) && (equivalent = equivalent_kickstart_repository) self.content_facet.kickstart_repository_id = equivalent[:id] end end |
#equivalent_kickstart_repository ⇒ Object
96 97 98 99 100 101 102 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 96 def equivalent_kickstart_repository return unless && content_facet.kickstart_repository && .respond_to?(:kickstart_repos) ks_repos = .kickstart_repos(self, content_facet: content_facet) ks_repos.find { |repo| repo[:name] == content_facet.kickstart_repository.label } end |
#inherited_content_source_id ⇒ Object
68 69 70 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 68 def inherited_content_source_id inherited_ancestry_attribute(:content_source_id, :content_facet) end |
#inherited_content_view_id ⇒ Object
72 73 74 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 72 def inherited_content_view_id inherited_ancestry_attribute(:content_view_id, :content_facet) end |
#inherited_kickstart_repository_id ⇒ Object
80 81 82 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 80 def inherited_kickstart_repository_id inherited_ancestry_attribute(:kickstart_repository_id, :content_facet) end |
#inherited_lifecycle_environment_id ⇒ Object
76 77 78 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 76 def inherited_lifecycle_environment_id inherited_ancestry_attribute(:lifecycle_environment_id, :content_facet) end |
#kickstart_repository ⇒ Object
57 58 59 60 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 57 def kickstart_repository return super if ancestry.nil? || self.kickstart_repository_id.present? Katello::Repository.find_by(:id => inherited_kickstart_repository_id) end |
#lifecycle_environment ⇒ Object
52 53 54 55 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 52 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
104 105 106 107 108 109 110 111 112 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 104 def matching_kickstart_repository?(content_facet) return true unless if .respond_to? :kickstart_repos .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_label ⇒ Object
84 85 86 87 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 84 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 |