Sha256: a42f75c1b46b2a71dd80dea4a61a5f106eed4f138e493b754e86a836715f6505

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

Facter.add('uuid') do
  setcode do
    if Facter.value('uuid')
      Facter.value('uuid')
    elsif Facter::Util::Resolution.which('dmidecode')
      Facter::Util::Resolution.exec('dmidecode -s system-uuid').strip.chomp
    else
      nil
    end
  end
end

Facter.add('signature') do
  setcode do
    if File.size?("/etc/onering/signature")
      parts = File.read("/etc/onering/signature").split("\n").
                reject{|i| i =~ /^\s*#/ }.
                reject{|i| i.strip.chomp.empty? }.
                collect{|i| i.gsub(/\H/,'') }

    elsif Facter.value('macaddress')
      if Facter.value('is_virtual')
        if File.exists?('/sys/hypervisor/uuid')
          parts = [
            File.read('/sys/hypervisor/uuid').strip.chomp.delete('-'),
            Facter.value('macaddress').strip.delete(':')
          ]
        end
      elsif Facter::Util::Resolution.which('dmidecode')
        parts = [
          Facter::Util::Resolution.exec('dmidecode -s system-uuid').strip.chomp.delete('-'),
          Facter.value('macaddress').strip.delete(':')
        ]
      end

    else
      if Facter.value('ipaddress')
        parts = [
          Facter.value('ipaddress').split(',').first.strip.chomp.delete('.')
        ].compact
      end
    end

    (parts && !parts.empty? ? parts.collect{|i| i.upcase }.join('-') : nil)
  end
end

Facter.add('hardwareid') do
  setcode do
    if File.size?('/etc/hardware.id')
      File.read('/etc/hardware.id').strip.chomp rescue nil
    elsif Facter.value('signature')
      require 'digest'
      Digest::SHA256.new.update(Facter.value('signature')).hexdigest[0..5]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
onering-report-plugins-0.0.21 lib/facter/onering_properties_id.rb