Sha256: ab2e94fd8b49df929bac3151880bd8b683a64baba1e8a9338bb2906af7f975ab

Contents?: true

Size: 1.96 KB

Versions: 1

Compression:

Stored size: 1.96 KB

Contents

require 'timeout'

Facter.add('site') do
  setcode do
    if File.size?('/etc/onering/static/site')
	site = File.read('/etc/onering/static/site').strip.chomp

    else
	if File.exists?('/proc/cmdline')
	  site = (File.read('/proc/cmdline').chomp.split(' ').select{|i| i =~ /^domain=/ }.first rescue nil)
	  site = site.split('=', 2).last if site
	  site = site.split('.').first if site
	end
    end

    site = nil if ['test', 'hw', 'vm'].include?(site)

    if site
	site
    else
	Facter.value('fqdn').split('.')[-3].downcase rescue nil
    end
  end
end

Facter.add('environment') do
  setcode do
    env = (Facter.value('fqdn').split('.').first.split('-')[-2].downcase rescue nil)

    case env
    when 'dev'
	'development'
    when /(stg|stage)/
	'staging'
    when 'prod'
	'production'
    else
	nil
    end
  end
end

Facter.add('slot') do
  setcode do
    slot = Integer(Facter::Util::Resolution.exec("bmc node_number 2> /dev/null")) rescue nil
    slot = nil if slot == 0
    slot
  end
end

def ipmi_ok?
  begin
    ipmi = IPMI_PATH if defined? IPMI_PATH 
    ipmi ||= 'ipmiutil'
    Timeout::timeout(1) {
	Facter::Util::Resolution.exec("#{ipmi} health 2> /dev/null | tail -n1 | grep failed").nil?
    }
  rescue Timeout::Error
    $stderr.puts "timed out while running #{ipmi}"
    false
  end
end

if ipmi_ok?
  ipmi_lan = Facter::Util::Resolution.exec("ipmitool lan print 1 2> /dev/null")

  if ipmi_lan
    ipmi_lan_data = {}

    ipmi_lan.lines.each do |line|
	key, value = line.split(/:/, 2)
	value = value.strip.squeeze(' ').chomp

	case key
	when /^IP Address/i
	  ipmi_lan_data[:ip] = value

	when /^Subnet Mask/i
	  ipmi_lan_data[:netmask] = value

	when /^MAC Address/i
	  ipmi_lan_data[:macaddress] = value.upcase

	when /^Default Gateway IP/i
	  ipmi_lan_data[:gateway] = value

	when /^SNMP Community String/i
	  ipmi_lan_data[:snmp_community] = value

	end
    end

    ipmi_lan_data.each do |key, value|
	Facter.add("ipmi_#{key}") do
	  setcode { value }
	end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
onering-report-0.6.6 lib/facter/onering_properties_physical.rb