Top Level Namespace
Constant Summary collapse
- ALLOWED_IPMI =
5
Instance Method Summary collapse
- #_format(key, value) ⇒ Object
- #count_ipmi_instances(cmd) ⇒ Object
- #getcommandline(pid) ⇒ Object
- #ipmi_ok? ⇒ Boolean
- #sz_to_bytes(sz) ⇒ Object
Instance Method Details
#_format(key, value) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/facter/onering_properties_network.rb', line 2 def _format(key, value) rv = [] value = nil if value =~ /Not received/i begin case key when :autoneg v0, v1 = value.split('/') rv << [:autoneg_supported, (v0 == 'supported')] rv << [:autoneg_enabled, (v1 == 'enabled')] when :mgmt_ip rv << [:management_ip, value] when :mau_oper_type rv << [:mau_type, value] when :port_id value = value.split(' ') value = value.select{|i| i =~ /..:..:..:..:..:../ }.first rv << [:port_mac, value.upcase] when :chassis_id value = value.split(' ') value = value.select{|i| i =~ /..:..:..:..:..:../ }.first rv << [:chassis_mac, value.upcase] when :port_descr port = value.split(/[^0-9]([0-9])/, 2) port.shift port = port.join('') rv << [:port_name, value] rv << [:port, port] when :mfs rv << [:mfs, (value.split(' ').first.to_i rescue nil)] when :sys_name rv << [:switch, value] when :lldp_med_device_type, :lldp_med_capabilities, :caps, :sys_descr return [] else rv << [key, value] end rescue nil end return rv end |
#count_ipmi_instances(cmd) ⇒ Object
51 52 53 |
# File 'lib/facter/onering_properties_physical.rb', line 51 def count_ipmi_instances(cmd) Dir['/proc/[0-9]*/cmdline'].select {|p| File.read(p).include?(cmd)}.count end |
#getcommandline(pid) ⇒ Object
24 25 26 27 |
# File 'lib/facter/onering_properties_netstat.rb', line 24 def getcommandline(pid) return nil unless pid.to_i > 0 (File.read("/proc/#{pid}/cmdline").to_s.strip.chomp.squeeze("\u0000").squeeze("\0").gsub("\u0000", ' ').gsub("\0", ' ')) end |
#ipmi_ok? ⇒ Boolean
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/facter/onering_properties_physical.rb', line 57 def ipmi_ok? begin ipmi = IPMI_PATH if defined? IPMI_PATH ipmi ||= 'ipmiutil' if count_ipmi_instances(ipmi) > ALLOWED_IPMI $stderr.puts "More then #{ALLOWED_IPMI} #{ipmi} instances found" return false end Timeout::timeout(30) { 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 |
#sz_to_bytes(sz) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/facter/onering_properties_zfs.rb', line 2 def sz_to_bytes(sz) case sz[-1].chr when 'K' rv = sz[0..-2].to_f * (1024) when 'M' rv = sz[0..-2].to_f * (1024 ** 2) when 'G' rv = sz[0..-2].to_f * (1024 ** 3) when 'T' rv = sz[0..-2].to_f * (1024 ** 4) when 'P' rv = sz[0..-2].to_f * (1024 ** 5) when 'E' rv = sz[0..-2].to_f * (1024 ** 6) when 'Z' rv = sz[0..-2].to_f * (1024 ** 7) when 'Y' rv = sz[0..-2].to_f * (1024 ** 8) else rv = sz[0..-2].to_f end rv.to_i end |