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-plugins-0.0.54 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.53 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.52 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.51 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.50 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.49 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.48 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.47 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.46 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.45 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.44 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.43 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.42 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.41 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.40 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.39 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.38 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.37 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.36 lib/facter/onering_properties_id.rb
onering-report-plugins-0.0.35 lib/facter/onering_properties_id.rb