diff --git a/app/models/concerns/foreman_uuid_boot/host_discovered_extensions.rb b/app/models/concerns/foreman_uuid_boot/host_discovered_extensions.rb new file mode 100644 index 0000000000000000000000000000000000000000..42769573569e34ef5be1902a81e596ee6d26e670 --- /dev/null +++ b/app/models/concerns/foreman_uuid_boot/host_discovered_extensions.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module ForemanUuidBoot + module HostDiscoveredExtensions + def populate_fields_from_facts(parser, type, source_proxy) + super + populate_facet_fields(parser, type, source_proxy) + end + end +end diff --git a/lib/foreman_uuid_boot/engine.rb b/lib/foreman_uuid_boot/engine.rb index 8d4a2e6aaca289a4ac57d8b6dab6c71d9bcfe4f2..4b1c3255e5f6911ace0ecaad50d4a4017067b047 100644 --- a/lib/foreman_uuid_boot/engine.rb +++ b/lib/foreman_uuid_boot/engine.rb @@ -4,6 +4,7 @@ module ForemanUuidBoot class Engine < ::Rails::Engine engine_name 'foreman_uuid_boot' + config.autoload_paths += Dir["#{config.root}/app/models/concerns"] config.autoload_paths += Dir["#{config.root}/app/services/foreman/unattended_installation/concerns"] initializer 'foreman_uuid_boot.load_app_instance_data' do |app| @@ -17,13 +18,27 @@ module ForemanUuidBoot requires_foreman '>= 2.5' register_facet ForemanUuidBoot::UuidbootHostFacet, :uuidboot_facet do - set_dependent_action :destroy + configure_host do + set_dependent_action :destroy + end end end end config.to_prepare do ::Foreman::UnattendedInstallation::HostFinder.prepend ForemanUuidBoot::HostFinderExtensions + + # Slight hack for foreman_discovery - to store UUID for provision + begin + # Ensure that Host::Discovered applies host facets + unless ::Host::Discovered.include? Facets::ModelExtensionsBase + ::Host::Discovered.include SelectiveClone + ::Host::Discovered.include Facets::ManagedHostExtensions + ::Host::Discovered.prepend ForemanUuidBoot::HostDiscoveredExtensions + end + rescue NameError => e + Rails.logger.warn "ForemanUuidBoot: Discovery not installed(#{e}), skipping discovery extensions" + end rescue StandardError => e Rails.logger.warn "ForemanUuidBoot: skipping engine hook(#{e})" end