From 456bff83c61d91746198dbbb2fe0ce9c47b04868 Mon Sep 17 00:00:00 2001 From: Oleh Fedorenko Date: Wed, 15 May 2024 14:01:46 +0000 Subject: [PATCH] Fixes #37465 - Support Zeitwerk loader --- .../foreman_bootdisk/iso_generator.rb | 2 +- config/initializers/inflections.rb | 5 + ...it_host_bootdisk_template_dns_secondary.rb | 2 +- lib/foreman_bootdisk/engine.rb | 209 +++++++++--------- 4 files changed, 108 insertions(+), 110 deletions(-) create mode 100644 config/initializers/inflections.rb diff --git a/app/services/foreman_bootdisk/iso_generator.rb b/app/services/foreman_bootdisk/iso_generator.rb index f2960876..5fb03627 100644 --- a/app/services/foreman_bootdisk/iso_generator.rb +++ b/app/services/foreman_bootdisk/iso_generator.rb @@ -10,7 +10,7 @@ # requires syslinux, ipxe/ipxe-bootimgs, genisoimage, isohybrid module ForemanBootdisk class ISOGenerator - extend Foreman::HTTPProxy + extend Foreman::HttpProxy def self.generate_full_host(host, opts = {}, &block) raise Foreman::Exception.new(N_('Host is not in build mode, so the template cannot be rendered')) unless host.build? diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 00000000..9f4248ad --- /dev/null +++ b/config/initializers/inflections.rb @@ -0,0 +1,5 @@ +Rails.autoloaders.each do |autoloader| + autoloader.inflector.inflect( + 'iso_generator' => 'ISOGenerator' + ) +end diff --git a/db/migrate/20131021095100_edit_host_bootdisk_template_dns_secondary.rb b/db/migrate/20131021095100_edit_host_bootdisk_template_dns_secondary.rb index 3ff2a799..f0d46000 100644 --- a/db/migrate/20131021095100_edit_host_bootdisk_template_dns_secondary.rb +++ b/db/migrate/20131021095100_edit_host_bootdisk_template_dns_secondary.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class EditHostBootdiskTemplateDnsSecondary < ActiveRecord::Migration[4.2] +class EditHostBootdiskTemplateDNSSecondary < ActiveRecord::Migration[4.2] def self.up; end def self.down; end diff --git a/lib/foreman_bootdisk/engine.rb b/lib/foreman_bootdisk/engine.rb index 8eda7c11..191533a6 100644 --- a/lib/foreman_bootdisk/engine.rb +++ b/lib/foreman_bootdisk/engine.rb @@ -9,11 +9,6 @@ class Engine < ::Rails::Engine engine_name 'foreman_bootdisk' isolate_namespace ForemanBootdisk - config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"] - config.autoload_paths += Dir["#{config.root}/app/helpers"] - config.autoload_paths += Dir["#{config.root}/app/models/concerns"] - config.autoload_paths += Dir["#{config.root}/app/lib"] - initializer 'foreman_bootdisk.mount_engine' do |app| app.routes_reloader.paths << "#{ForemanBootdisk::Engine.root}/config/routes/mount_engine.rb" end @@ -28,113 +23,109 @@ class Engine < ::Rails::Engine Apipie.configuration.checksum_path += ['/bootdisk/api/'] end - # Temporary workaround fix for helpers - initializer 'foreman_bootdisk.rails_loading_workaround' do - HostsHelper.prepend ForemanBootdisk::HostsHelperExt - SubnetsHelper.include ForemanBootdisk::SubnetsHelperExt - end - - initializer 'foreman_bootdisk.register_plugin', before: :finisher_hook do |_app| - Foreman::Plugin.register :foreman_bootdisk do - requires_foreman '>= 3.7' - # Add Global files for extending foreman-core components and routes - register_global_js_file 'global' - register_gettext - - security_block :bootdisk do |_map| - permission :download_bootdisk, 'foreman_bootdisk/disks': %i[generic host full_host help bootdisk_options], - 'foreman_bootdisk/subnet_disks': [:subnet], - 'foreman_bootdisk/api/v2/disks': %i[generic host], - 'foreman_bootdisk/api/v2/subnet_disks': [:subnet] - end + initializer 'foreman_bootdisk.register_plugin', before: :finisher_hook do |app| + app.reloader.to_prepare do + Foreman::Plugin.register :foreman_bootdisk do + requires_foreman '>= 3.13' + # Add Global files for extending foreman-core components and routes + register_global_js_file 'global' + register_gettext + + security_block :bootdisk do |_map| + permission :download_bootdisk, 'foreman_bootdisk/disks': %i[generic host full_host help bootdisk_options], + 'foreman_bootdisk/subnet_disks': [:subnet], + 'foreman_bootdisk/api/v2/disks': %i[generic host], + 'foreman_bootdisk/api/v2/subnet_disks': [:subnet] + end - role 'Boot disk access', [:download_bootdisk], 'Role granting permissions to download bootdisks' - add_all_permissions_to_default_roles + role 'Boot disk access', [:download_bootdisk], 'Role granting permissions to download bootdisks' + add_all_permissions_to_default_roles - apipie_documented_controllers ["#{ForemanBootdisk::Engine.root}/app/controllers/foreman_bootdisk/api/v2/*.rb"] - ApipieDSL.configuration.dsl_classes_matchers += [ - "#{ForemanBootdisk::Engine.root}/app/lib/foreman_bootdisk/scope/*.rb" - ] - provision_method 'bootdisk', N_('Boot disk based') - allowed_template_helpers :bootdisk_chain_url, :bootdisk_raise + apipie_documented_controllers ["#{ForemanBootdisk::Engine.root}/app/controllers/foreman_bootdisk/api/v2/*.rb"] + ApipieDSL.configuration.dsl_classes_matchers += [ + "#{ForemanBootdisk::Engine.root}/app/lib/foreman_bootdisk/scope/*.rb" + ] + provision_method 'bootdisk', N_('Boot disk based') + allowed_template_helpers :bootdisk_chain_url, :bootdisk_raise - extend_page "subnets/index" do |cx| - cx.add_pagelet :subnet_index_action_buttons, name: 'Bootdisk', partial: 'subnets/bootdisk_action_buttons' - cx.add_pagelet :subnet_index_title_buttons, name: 'Bootdisk', partial: 'subnets/bootdisk_title_buttons' - end + extend_page "subnets/index" do |cx| + cx.add_pagelet :subnet_index_action_buttons, name: 'Bootdisk', partial: 'subnets/bootdisk_action_buttons' + cx.add_pagelet :subnet_index_title_buttons, name: 'Bootdisk', partial: 'subnets/bootdisk_title_buttons' + end - settings do - category :bootdisk, N_("Boot disk") do - ipxe = ['/usr/lib/ipxe'].find { |p| File.exist?(p) } || '/usr/share/ipxe' - isolinux = ['/usr/lib/ISOLINUX'].find { |p| File.exist?(p) } || '/usr/share/syslinux' - syslinux = ['/usr/lib/syslinux/modules/bios', '/usr/lib/syslinux'].find { |p| File.exist?(p) } || '/usr/share/syslinux' - grub2 = ['/var/lib/tftpboot/grub2'].find { |p| File.exist?(p) } || '/var/lib/foreman/bootdisk' - templates = -> { - Hash[ProvisioningTemplate.where(template_kind: TemplateKind.where(name: 'Bootdisk')).map { |temp| [temp[:name], temp[:name]] }] - } - - setting "bootdisk_ipxe_dir", - type: :string, - default: ipxe, - full_name: N_("iPXE directory"), - description: N_("Path to directory containing iPXE images") - - setting "bootdisk_isolinux_dir", - type: :string, - default: isolinux, - full_name: N_("ISOLINUX directory"), - description: N_("Path to directory containing isolinux images") - - setting "bootdisk_syslinux_dir", - type: :string, - default: syslinux, - full_name: N_("SYSLINUX directory"), - description: N_("Path to directory containing syslinux images") - - setting "bootdisk_grub2_dir", - type: :string, - default: grub2, - full_name: N_("Grub2 directory"), - description: N_("Path to directory containing grubx64.efi and shimx64.efi") - - setting "bootdisk_host_template", - type: :string, - collection: templates, - default: "Boot disk iPXE - host", - full_name: N_("Host image template"), - description: N_("iPXE template to use for host-specific boot disks") - - setting "bootdisk_generic_host_template", - type: :string, - collection: templates, - default: "Boot disk iPXE - generic host", - full_name: N_("Generic image template"), - description: N_("iPXE template to use for generic host boot disks") - - setting "bootdisk_generic_efi_host_template", - type: :string, - collection: templates, - default: "Boot disk Grub2 EFI - generic host", - full_name: N_("Generic Grub2 EFI image template"), - description: N_("iPXE template to use for generic EFI host boot disks") - - setting "bootdisk_mkiso_command", - type: :string, - default: "genisoimage", - full_name: N_("ISO generation command"), - description: N_("Command to generate ISO image, use genisoimage or mkisofs") - - setting "bootdisk_cache_media", - type: :boolean, - default: true, - full_name: N_("Installation media caching"), - description: N_("Installation media files will be cached for full host images") - - setting "bootdisk_allowed_types", - type: :array, - default: Setting::Bootdisk.bootdisk_types, - full_name: N_("Allowed bootdisk types"), - description: N_("List of allowed bootdisk types, remove type to disable it") + settings do + category :bootdisk, N_("Boot disk") do + ipxe = ['/usr/lib/ipxe'].find { |p| File.exist?(p) } || '/usr/share/ipxe' + isolinux = ['/usr/lib/ISOLINUX'].find { |p| File.exist?(p) } || '/usr/share/syslinux' + syslinux = ['/usr/lib/syslinux/modules/bios', '/usr/lib/syslinux'].find { |p| File.exist?(p) } || '/usr/share/syslinux' + grub2 = ['/var/lib/tftpboot/grub2'].find { |p| File.exist?(p) } || '/var/lib/foreman/bootdisk' + templates = -> { + Hash[ProvisioningTemplate.where(template_kind: TemplateKind.where(name: 'Bootdisk')).map { |temp| [temp[:name], temp[:name]] }] + } + + setting "bootdisk_ipxe_dir", + type: :string, + default: ipxe, + full_name: N_("iPXE directory"), + description: N_("Path to directory containing iPXE images") + + setting "bootdisk_isolinux_dir", + type: :string, + default: isolinux, + full_name: N_("ISOLINUX directory"), + description: N_("Path to directory containing isolinux images") + + setting "bootdisk_syslinux_dir", + type: :string, + default: syslinux, + full_name: N_("SYSLINUX directory"), + description: N_("Path to directory containing syslinux images") + + setting "bootdisk_grub2_dir", + type: :string, + default: grub2, + full_name: N_("Grub2 directory"), + description: N_("Path to directory containing grubx64.efi and shimx64.efi") + + setting "bootdisk_host_template", + type: :string, + collection: templates, + default: "Boot disk iPXE - host", + full_name: N_("Host image template"), + description: N_("iPXE template to use for host-specific boot disks") + + setting "bootdisk_generic_host_template", + type: :string, + collection: templates, + default: "Boot disk iPXE - generic host", + full_name: N_("Generic image template"), + description: N_("iPXE template to use for generic host boot disks") + + setting "bootdisk_generic_efi_host_template", + type: :string, + collection: templates, + default: "Boot disk Grub2 EFI - generic host", + full_name: N_("Generic Grub2 EFI image template"), + description: N_("iPXE template to use for generic EFI host boot disks") + + setting "bootdisk_mkiso_command", + type: :string, + default: "genisoimage", + full_name: N_("ISO generation command"), + description: N_("Command to generate ISO image, use genisoimage or mkisofs") + + setting "bootdisk_cache_media", + type: :boolean, + default: true, + full_name: N_("Installation media caching"), + description: N_("Installation media files will be cached for full host images") + + setting "bootdisk_allowed_types", + type: :array, + default: Setting::Bootdisk.bootdisk_types, + full_name: N_("Allowed bootdisk types"), + description: N_("List of allowed bootdisk types, remove type to disable it") + end end end end @@ -142,6 +133,8 @@ class Engine < ::Rails::Engine config.to_prepare do begin + ::HostsHelper.prepend ForemanBootdisk::HostsHelperExt + ::SubnetsHelper.include ForemanBootdisk::SubnetsHelperExt Host::Managed.prepend ForemanBootdisk::HostExt Host::Managed.include ForemanBootdisk::Orchestration::Compute Foreman::Model::Vmware.prepend ForemanBootdisk::ComputeResources::Vmware if Foreman::Model::Vmware.available?