Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 49 additions & 4 deletions lib/facter/bmc.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,61 @@
#bmc.rb
Facter.add("bmc_ip", :timeout => 2) do
Facter.add("bmc_ip") do
confine :bmc_device_present => [:true, true]
confine :bmc_tools_present => [:true, true]
setcode do
ip
end
end

Facter.add("bmc_mac", :timeout => 2) do
Facter.add("bmc_mac") do
confine :bmc_device_present => [:true, true]
confine :bmc_tools_present => [:true, true]
setcode do
mac
end
end

Facter.add("bmc_subnet", :timeout => 2) do
Facter.add("bmc_subnet") do
confine :bmc_device_present => [:true, true]
confine :bmc_tools_present => [:true, true]
setcode do
subnet
end
end

Facter.add("bmc_gateway", :timeout => 2) do
Facter.add("bmc_gateway") do
confine :bmc_device_present => [:true, true]
confine :bmc_tools_present => [:true, true]
setcode do
gateway
end
end

Facter.add("bmc_ipmi_version") do
confine :bmc_device_present => [:true, true]
confine :bmc_tools_present => [:true, true]
setcode do
ipmi_version
end
end

Facter.add("bmc_firmware_revision") do
confine :bmc_device_present => [:true, true]
confine :bmc_tools_present => [:true, true]
setcode do
firmware_revision
end
end


def lanconfig
@lanconfig ||= parse_laninfo
end

def mcconfig
@mcconfig ||= parse_mcinfo
end

def parse_laninfo
if ipmitool.empty? or ipmitool.nil?
return {}
Expand All @@ -59,6 +80,22 @@ def parse_laninfo
laninfo
end

def parse_mcinfo
if ipmitool.empty? or ipmitool.nil?
return {}
end
mcdata = Facter::Core::Execution.exec("#{ipmitool} mc info 2>/dev/null") || ''
mcinfo = {}
mcdata.lines.each do |line|
# clean up the data from spaces
item = line.split(':', 2)
key = item.first.strip.downcase.gsub(' ','_')
value = item.last.strip
mcinfo[key] = value
end
mcinfo
end

def ipmitool
unless @ipmitool
timeout = Facter::Core::Execution.which('timeout')
Expand Down Expand Up @@ -105,3 +142,11 @@ def static?
def ipsrc
lanconfig["ip_address_source"].downcase!
end

def firmware_revision
mcconfig["firmware_revision"]
end

def ipmi_version
mcconfig["ipmi_version"]
end