Sha256: 467a33e1459c52323a06291eb52c01217765caa98da130bf51e065d79ca2cb07

Contents?: true

Size: 1.76 KB

Versions: 50

Compression:

Stored size: 1.76 KB

Contents

Facter.add('uuid') do
  setcode do
    if not Facter.value('uuid').nil?
      Facter.value('uuid')
    elsif Facter::Util::Resolution.which('dmidecode')
      Facter::Util::Resolution.exec('dmidecode -s system-uuid').strip.chomp
    elsif File.exists?('/sys/hypervisor/uuid')
      File.read('/sys/hypervisor/uuid').lines.first.strip.chomp
    else
      nil
    end
  end
end

Facter.add('signature') do
  setcode do
    parts = []

    if Facter.value('uuid')
      parts << Facter.value('uuid').gsub(/[\W\_]+/,'').upcase
    end

    if Facter.value('macaddress')
      parts << Facter.value('macaddress').gsub(/[\W\_]+/,'').upcase
    end

  # still empty, now we really have to grasp at straws
    if parts.empty?
      if Facter.value('ipaddress')
        parts << Facter.value('ipaddress').split(',').first.strip.chomp.delete('.')
      end
    end


  # final pruning
    parts = parts.reject{|i| i.nil? || i.empty? }

  # still empty?
    if parts.empty?
      nil
    else
      parts.join('-')
    end
  end
end

Facter.add('hardwareid') do
  setcode do
  # 1. contents of /etc/hardware.id takes absolute precedence
    if File.size?('/etc/hardware.id')
      File.read('/etc/hardware.id').strip.chomp rescue nil

  # 2. value of kernel boot argument 'hardwareid' is checked
    elsif Facter.value('kernelarguments').is_a?(Hash) and
    not Facter.value('kernelarguments')['hardwareid'].nil? and
    not Facter.value('kernelarguments')['hardwareid'].to_s.strip.empty?
      Facter.value('kernelarguments')['hardwareid'].to_s.strip

  # 3. calculate a new hardwareid from the system signature
    elsif Facter.value('signature')
      require 'digest'
      Digest::SHA256.new.update(Facter.value('signature')).hexdigest[0..5]

  # 4. i got nothing...
    else
      nil
    end
  end
end

Version data entries

50 entries across 50 versions & 2 rubygems

Version Path
onering-report-0.6.13 lib/facter/onering_properties_id.rb
onering-report-0.6.12 lib/facter/onering_properties_id.rb
onering-report-0.6.11 lib/facter/onering_properties_id.rb
onering-report-0.6.10 lib/facter/onering_properties_id.rb
onering-report-0.6.9 lib/facter/onering_properties_id.rb
onering-report-0.6.8 lib/facter/onering_properties_id.rb
onering-report-0.6.7 lib/facter/onering_properties_id.rb
onering-report-0.6.6 lib/facter/onering_properties_id.rb
onering-report-0.6.5 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.65 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.64 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.63 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.62 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.61 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.60 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.59 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.58 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.57 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.56 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.55 lib/facter/onering_properties_id.rb