From fba32bbd666ee9de144609331f9ebbb6a4c58f6a Mon Sep 17 00:00:00 2001 From: Alexander Olofsson <alexander.olofsson@liu.se> Date: Fri, 20 Jan 2023 13:44:31 +0100 Subject: [PATCH] Add support for foreman_discovery --- .../host_discovered_extensions.rb | 10 ++++++++++ lib/foreman_uuid_boot/engine.rb | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 app/models/concerns/foreman_uuid_boot/host_discovered_extensions.rb 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 0000000..4276957 --- /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 8d4a2e6..4b1c325 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 -- GitLab