diff --git a/app/models/foreman_uuid_boot/uuidboot_host_facet.rb b/app/models/foreman_uuid_boot/uuidboot_host_facet.rb index 49cb8b703fa83c2433ab237e9b056a38afa60474..b5340a004c9cafec8b539fad9a33ca3d4df52858 100644 --- a/app/models/foreman_uuid_boot/uuidboot_host_facet.rb +++ b/app/models/foreman_uuid_boot/uuidboot_host_facet.rb @@ -4,16 +4,19 @@ module ForemanUuidBoot class UuidbootHostFacet < ApplicationRecord include Facets::Base + UUID_REX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.freeze + def self.populate_fields_from_facts(host, parser, _type, _proxy) uuid = parser.facts.dig('dmi', 'product', 'uuid') || parser.facts['uuid'] - if uuid + if uuid && uuid =~ UUID_REX facet = host.uuidboot_facet || host.build_uuidboot_facet facet.uuid = uuid facet.save if facet.changed? || !facet.persisted? facet else host.uuidboot_facet&.destroy + host.uuidboot_facet = nil nil end end