Module: Katello::Concerns::RedhatExtensions::ClassMethods
- Defined in:
- app/models/katello/concerns/redhat_extensions.rb
Instance Method Summary collapse
- #construct_name(family) ⇒ Object
- #create_operating_system(name, major, minor) ⇒ Object
- #find_or_create_operating_system(repo) ⇒ Object
Instance Method Details
#construct_name(family) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'app/models/katello/concerns/redhat_extensions.rb', line 41 def construct_name(family) if family == ::Operatingsystem::REDHAT_ATOMIC_HOST_DISTRO_NAME return ::Operatingsystem::REDHAT_ATOMIC_HOST_OS elsif family.include? 'Red Hat' return 'RedHat' else return family.tr(' ', '_') end end |
#create_operating_system(name, major, minor) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/katello/concerns/redhat_extensions.rb', line 30 def (name, major, minor) params = { 'name' => name, 'major' => major.to_s, 'minor' => minor.to_s, 'family' => 'Redhat' } return ::Redhat.create!(params) end |
#find_or_create_operating_system(repo) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/katello/concerns/redhat_extensions.rb', line 7 def (repo) os_name = construct_name(repo.distribution_family) major, minor = repo.distribution_version.split('.') minor ||= '' # treat minor versions as empty string to not confuse with nil os = ::Redhat.where(:name => os_name, :major => major, :minor => minor).try(:first) return os if os if ::Redhat.where(:title => "#{os_name} #{repo.distribution_version}").present? description = "#{os_name} #{repo.distribution_version} #{SecureRandom.uuid}" create_os = lambda do ::Redhat.create!(:name => os_name, :major => major, :minor => minor, :description => description) end else create_os = lambda { ::Redhat.create!(:name => os_name, :major => major, :minor => minor) } end begin create_os.call rescue ActiveRecord::RecordInvalid create_os.call end end |