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
- #content_view_name ⇒ 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
- #lifecycle_environment_name ⇒ Object
- #matching_kickstart_repository?(content_facet) ⇒ Boolean
- #rhsm_organization_label ⇒ Object
Instance Method Details
#add_organization_for_environment ⇒ Object
114 115 116 117 118 119 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 114 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
74 75 76 77 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 74 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
58 59 60 61 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 58 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_name ⇒ Object
101 102 103 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 101 def content_view_name content_view&.name end |
#correct_kickstart_repository ⇒ Object
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_repository ⇒ Object
121 122 123 124 125 126 127 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 121 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
79 80 81 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 79 def inherited_content_source_id inherited_ancestry_attribute(:content_source_id, :content_facet) end |
#inherited_content_view_id ⇒ Object
83 84 85 86 87 88 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 83 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_id ⇒ Object
97 98 99 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 97 def inherited_kickstart_repository_id inherited_ancestry_attribute(:kickstart_repository_id, :content_facet) end |
#inherited_lifecycle_environment_id ⇒ Object
90 91 92 93 94 95 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 90 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_repository ⇒ Object
68 69 70 71 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 68 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
63 64 65 66 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 63 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_name ⇒ Object
105 106 107 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 105 def lifecycle_environment_name lifecycle_environment&.name end |
#matching_kickstart_repository?(content_facet) ⇒ Boolean
129 130 131 132 133 134 135 136 137 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 129 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
109 110 111 112 |
# File 'app/models/katello/concerns/hostgroup_extensions.rb', line 109 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 |