Skip to content

Commit

Permalink
Finish removing Facter 0.2x
Browse files Browse the repository at this point in the history
  • Loading branch information
lzap committed Dec 9, 2020
1 parent 26f569c commit 68f2446
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 68 deletions.
3 changes: 1 addition & 2 deletions 20-packages.ks
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ elfutils-libs
tar
gzip

# Facter (both CLI and for smart-proxy image plugin)
facter
# Facter
tfm-rubygem-facter
ethtool
net-tools
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ Some extra facts are reported in addition to the standard ones reported by
Facter:

```
FACTERLIB=/usr/share/fdi/facts/ facter | grep discovery
source /etc/default/discovery
export FACTERLIB
facter | grep discovery
discovery_bootif => 52:54:00:94:9e:52
discovery_bootip => 192.168.122.51
```
Expand Down
3 changes: 2 additions & 1 deletion root/usr/bin/discovery-debug
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

source /etc/default/discovery
export FACTERLIB

echo "* LOOPBACK ISO IMAGE CHECK"
checkisomd5 /dev/loop0
Expand Down Expand Up @@ -39,7 +40,7 @@ echo "* IMAGE VERSION"
cat /usr/share/fdi/VERSION /usr/share/fdi/RELEASE

echo "* FACTER *"
FACTERLIB=/usr/share/fdi/facts/ facter --json
facter --json

echo "* JOURNAL (last 500 lines) *"
journalctl -n300 -ocat
74 changes: 15 additions & 59 deletions root/usr/share/fdi/facts/discovery-facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,30 @@
# also available at http://www.gnu.org/copyleft/gpl.html.

require 'resolv'
require 'facter/util/ip'
require '/usr/lib64/ruby/vendor_ruby/discovery.rb'
if File.exist? '/opt/rh/rh-ruby25/root/usr/share/ruby/vendor_ruby/discovery'
require '/opt/rh/rh-ruby25/root/usr/share/ruby/vendor_ruby/discovery'
else
require_relative '../../../../opt/rh/rh-ruby25/root/usr/share/ruby/vendor_ruby/discovery.rb'
end

def discovery_bootif
# PXELinux dash-separated hexadecimal *without* the leading hardware type
cmdline('BOOTIF', cmdline('fdi.pxmac', detect_first_nic_with_link)).gsub(/^[a-fA-F0-9]+-/, '').gsub('-', ':') rescue '00:00:00:00:00:00'
end

Facter.add("discovery_version") do
setcode do
File.open('/usr/share/fdi/VERSION') {|f| f.readline.chomp}
if File.exist? '/usr/share/fdi/VERSION'
Facter.add("discovery_version") do
setcode do
File.open('/usr/share/fdi/VERSION') {|f| f.readline.chomp}
end
end
end

Facter.add("discovery_release") do
setcode do
File.open('/usr/share/fdi/RELEASE') {|f| f.readline.chomp}
if File.exist? '/usr/share/fdi/RELEASE'
Facter.add("discovery_release") do
setcode do
File.open('/usr/share/fdi/RELEASE') {|f| f.readline.chomp}
end
end
end

Expand All @@ -44,18 +51,6 @@ def discovery_bootif
end
end

Facter.add("discovery_bootip", :timeout => 10) do
setcode do
result = Facter.fact("ipaddress").value
required = discovery_bootif
Facter::Util::IP.get_interfaces.each do |iface|
mac = Facter::Util::IP.get_interface_value(iface, "macaddress")
result = Facter::Util::IP.get_interface_value(iface, "ipaddress") if mac == required
end
result
end
end

(1..99).each do |n|
if (fact_name = cmdline("fdi.pxfactname#{n}"))
fact_value = cmdline("fdi.pxfactvalue#{n}")
Expand All @@ -71,45 +66,6 @@ def discovery_bootif
end
end

Facter::Util::IP.get_interfaces.each do |interface|
Facter.debug("Running ethtool on interface #{interface}")
output = (Facter::Util::Resolution.exec("ethtool #{interface} 2>/dev/null"))
if output.nil?
Facter.debug("Execution of ethtool on interface #{interface} failed")
else
attributes = {}
output.each_line do |line|
next if line.nil? or line == ""
case line.strip
when /Speed: (.*)Mb/
attributes[:speed] = $1
when /Duplex: (.*)/
attributes[:duplex] = $1.downcase
when /Port: (.*)/
attributes[:port] = $1
when /Auto-negotiation: (.*)/
attributes[:auto_negotiation] = ($1 == 'on').to_s
when /^Wake-on: (.*)/
attributes[:wol] = $1.include?('g')
when /Link detected: (.*)/
attributes[:link] = ($1 == 'yes').to_s
end
end

if attributes.keys.empty?
Facter.debug("Running ethtool on #{interface} didn't give any information")
end
attributes.each do |fact, value|
Facter.add("#{fact}_#{Facter::Util::IP.alphafy(interface)}", :timeout => 10) do
confine :kernel => "Linux"
setcode do
value
end
end
end
end
end

# IPMI Facts
%x{dmidecode -t 38 2>/dev/null|grep -q "IPMI Device"}
has_ipmi = $?.exitstatus == 0
Expand Down
7 changes: 2 additions & 5 deletions root/usr/share/fdi/facts/openlldp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,13 @@
# Copyright (C) 2012 Mike Arnold, unless otherwise noted.
#

require 'facter/util/macaddress'

# http://www.ruby-forum.com/topic/3418285#1040695
module Enumerable
def grep_v(cond)
select {|x| not cond === x}
end
end

#if Facter::Util::Resolution.which('lldptool')
if File.exists?('/usr/sbin/lldptool')
lldp = {
# LLDP Name Numeric value
Expand All @@ -66,7 +63,7 @@ def grep_v(cond)
}

# Remove interfaces that pollute the list (like lo and bond0).
Facter.value('interfaces').split(/,/).grep_v(/^lo$|^bond[0-9]/).each do |interface|
Dir.glob("/sys/class/net/*").map{|x| File.basename(x).to_s}.grep_v(/^lo$|^bond[0-9]/).each do |interface|
# Loop through the list of LLDP TLVs that we want to present as facts.
lldp.each_pair do |key, value|
Facter.add("lldp_neighbor_#{key}_#{interface}") do
Expand All @@ -82,7 +79,7 @@ def grep_v(cond)
when 'chassisID'
output.split("\n").each do |line|
ether = $1 if line.match(/MAC:\s+(.*)/)
result = Facter::Util::Macaddress.standardize(ether)
result = ether&.tr('-', ':')&.downcase
end
when 'portID'
output.split("\n").each do |line|
Expand Down

0 comments on commit 68f2446

Please sign in to comment.