Skip to content
Snippets Groups Projects
Verified Commit b3458698 authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

Add UUID facet

Should keep the UUID around over rebuilds as well, to allow booting
install media based on UUID
parent 1c75a0b3
No related branches found
No related tags found
No related merge requests found
......@@ -7,10 +7,6 @@ Example iPXE boot URLs;
`http://foreman.example.com/unattended/iPXE?uuid=${uuid}`
`http://template-proxy.example.com:8000/unattended/iPXE?mac=${netX/mac}&uuid=${uuid}`
### TODO:
- Support booting machines in build mode (facts are wiped when machines are in build)
## Installation
See the [Plugins install instructions, advanced installation from gems](https://theforeman.org/plugins/#2.3AdvancedInstallationfromGems) for information on how to install this plugins.
......
# frozen_string_literal: true
module ForemanUuidBoot
class UuidbootHostFacet < ApplicationRecord
include Facets::Base
def self.populate_fields_from_facts(host, parser, _type, _proxy)
facet = host.uuidboot_facet || host.build_uuidboot_facet
facet.uuid = parser.facts.dig('dmi', 'product', 'uuid') || parser.facts['uuid']
facet.save if facet.changed?
end
end
end
......@@ -13,6 +13,14 @@ module HostFinderExtensions
def find_host_by_uuid
return unless (uuid = query_params['uuid'])
facet = ForemanUuidBoot::UuidbootHostFacet.where(uuid: uuid).order(:created_at)
if facet.any?
Rails.logger.warn("Multiple hosts found with #{uuid}, picking up the most recent") if facet.count > 1
return facet.last.host.reload
end
# Fallback fact search
fact_name_id = FactName.where(name: 'uuid').map(&:id)
return unless fact_name_id.any?
......
# frozen_string_literal: true
class AddUuidbootFacet < ActiveRecord::Migration[5.1]
def change
create_table :uuidboot_host_facets do |t|
t.references :host, type: :integer, foreign_key: true, index: { unique: true }
t.uuid :uuid, null: false
t.timestamps
end
end
end
......@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
spec.homepage = 'https://github.com/ananace/foreman_uuid_boot'
spec.license = 'GPL-3.0'
spec.files = Dir['{app,lib}/**/*.{rake,rb}'] + %w[LICENSE.txt Rakefile README.md]
spec.files = Dir['{app,db,lib}/**/*.{rake,rb}'] + %w[LICENSE.txt Rakefile README.md]
spec.metadata['rubygems_mfa_required'] = 'true'
......
......@@ -6,9 +6,19 @@ module ForemanUuidBoot
config.autoload_paths += Dir["#{config.root}/app/services/foreman/unattended_installation/concerns"]
initializer 'foreman_uuid_boot.load_app_instance_data' do |app|
ForemanUuidBoot::Engine.paths['db/migrate'].existent.each do |path|
app.config.paths['db/migrate'] << path
end
end
initializer 'foreman_uuid_boot.register_plugin', before: :finisher_hook do |_app|
Foreman::Plugin.register :foreman_uuid_boot do
requires_foreman '>= 1.14'
requires_foreman '>= 2.5'
register_facet ForemanUuidBoot::UuidbootHostFacet, :uuidboot_facet do
set_dependent_action :destroy
end
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment