Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #37465 - Support Zeitwerk loader #162

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/services/foreman_bootdisk/iso_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
5 changes: 5 additions & 0 deletions config/initializers/inflections.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Rails.autoloaders.each do |autoloader|
autoloader.inflector.inflect(
'iso_generator' => 'ISOGenerator'
)
end
Original file line number Diff line number Diff line change
@@ -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
Expand Down
209 changes: 101 additions & 108 deletions lib/foreman_bootdisk/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,120 +23,118 @@ 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
end

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?
Expand Down
Loading