lib/ohai/plugins/kernel.rb in ohai-13.12.6 vs lib/ohai/plugins/kernel.rb in ohai-14.0.28
- old
+ new
@@ -2,11 +2,11 @@
# Author:: Adam Jacob (<adam@chef.io>)
# Author:: Benjamin Black (<nostromo@gmail.com>)
# Author:: Bryan McLellan (<btm@loftninjas.org>)
# Author:: Claire McQuin (<claire@chef.io>)
# Author:: James Gartrell (<jgartrel@gmail.com>)
-# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) 2008-2018 Chef Software, Inc.
# Copyright:: Copyright (c) 2009 Bryan McLellan
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -24,10 +24,11 @@
Ohai.plugin(:Kernel) do
provides "kernel", "kernel/modules"
# common initial kernel attribute values
+ # @return [Mash] basic kernel properties from uname
def init_kernel
kernel Mash.new
[["uname -s", :name], ["uname -r", :release],
["uname -v", :version], ["uname -m", :machine],
["uname -p", :processor]].each do |cmd, property|
@@ -36,10 +37,11 @@
end
kernel
end
# common *bsd code for collecting modules data
+ # @return [Mash]
def bsd_modules(path)
modules = Mash.new
so = shell_out("#{Ohai.abs_path(path)}")
so.stdout.lines do |line|
# 1 7 0xc0400000 97f830 kernel
@@ -48,30 +50,110 @@
end
end
modules
end
- # windows
- def machine_lookup(sys_type)
- return "i386" if sys_type.eql?("X86-based PC")
- return "x86_64" if sys_type.eql?("x64-based PC")
+ # given the OperatingSystemSKU value from WMI's Win32_OperatingSystem class
+ # https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
+ # return if we're on a Server Core installation
+ # @param [String] sku OperatingSystemSKU value from Win32_OperatingSystem
+ # @return [boolean]
+ def server_core?(sku)
+ return true if [
+ 12, # Server Datacenter Core
+ 39, # Server Datacenter without Hyper-V Core
+ 14, # Server Enterprise Core
+ 41, # Server Enterprise without Hyper-V Core
+ 13, # Server Standard Core
+ 40, # Server Standard without Hyper-V Core
+ 63, # Small Business Server Premium Core
+ 53, # Server Solutions Premium Core
+ 46, # Storage Server Enterprise Core
+ 43, # Storage Server Express Core
+ 44, # Storage Server Standard Core
+ 45, # Storage Server Workgroup Core
+ 29 # Web Server Core
+ ].include?(sku)
+ false
+ end
+
+ # given the SystemType value from WMI's Win32_ComputerSystem class
+ # https://msdn.microsoft.com/en-us/library/aa394102(v=vs.85).aspx
+ # return the architecture type
+ # @param [String] sys_type SystemType value from Win32_ComputerSystem
+ # @return [String] x86_64 or i386
+ def arch_lookup(sys_type)
+ return "x86_64" if sys_type == "x64-based PC"
+ return "i386" if sys_type == "X86-based PC"
sys_type
end
- # windows
- def os_lookup(sys_type)
- return "Unknown" if sys_type.to_s.eql?("0")
- return "Other" if sys_type.to_s.eql?("1")
- return "MSDOS" if sys_type.to_s.eql?("14")
- return "WIN3x" if sys_type.to_s.eql?("15")
- return "WIN95" if sys_type.to_s.eql?("16")
- return "WIN98" if sys_type.to_s.eql?("17")
- return "WINNT" if sys_type.to_s.eql?("18")
- return "WINCE" if sys_type.to_s.eql?("19")
- nil
+ # given the ProductType value from WMI's Win32_OperatingSystem class
+ # https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
+ # return either workstation or server
+ # @param [Integer] type ProductType value from Win32_OperatingSystem
+ # @return [String] Workstation or Server
+ def product_type_decode(type)
+ return "Workstation" if type == 1
+ "Server"
end
+ # decode the OSType field from WMI Win32_OperatingSystem class
+ # https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
+ # @param [Integer] sys_type OSType value from Win32_OperatingSystem
+ # @return [String] the human consumable OS type value
+ def os_type_decode(sys_type)
+ case sys_type
+ when 18 then "WINNT" # most likely so first
+ when 0 then "Unknown"
+ when 1 then "Other"
+ when 14 then "MSDOS"
+ when 15 then "WIN3x"
+ when 16 then "WIN95"
+ when 17 then "WIN98"
+ when 19 then "WINCE"
+ else nil
+ end
+ end
+
+ # decode the PCSystemType field from WMI Win32_OperatingSystem class
+ # https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
+ # @param [Integer] type the integer value from PCSystemType
+ # @return [String] the human consumable OS type value
+ def pc_system_type_decode(type)
+ case type
+ when 4 then "Enterprise Server" # most likely so first
+ when 0 then "Unspecified"
+ when 1 then "Desktop"
+ when 2 then "Mobile"
+ when 3 then "Workstation"
+ when 5 then "SOHO Server"
+ when 6 then "Appliance PC"
+ when 7 then "Performance Server"
+ when 8 then "Maximum"
+ else nil
+ end
+ end
+
+ # see if a WMI name is blacklisted so we can avoid writing out
+ # useless data to ohai
+ # @param [String] name the wmi name to check
+ # @return [Boolean] is the wmi name blacklisted
+ def blacklisted_wmi_name?(name)
+ [
+ "creation_class_name", # this is just the wmi name
+ "cs_creation_class_name", # this is just the wmi name
+ "oem_logo_bitmap", # this is the entire OEM bitmap file
+ "total_swap_space_size", # already in memory plugin
+ "total_virtual_memory_size", # already in memory plugin
+ "total_virtual_memory_size", # already in memory plugin
+ "free_physical_memory", # already in memory plugin
+ "free_space_in_paging_files", # already in memory plugin
+ "free_virtual_memory", # already in memory plugin
+ ].include?(name)
+ end
+
collect_data(:default) do
kernel init_kernel
end
collect_data(:darwin) do
@@ -92,11 +174,11 @@
end
kernel[:modules] = modules
end
- collect_data(:freebsd) do
+ collect_data(:freebsd, :dragonflybsd) do
kernel init_kernel
kernel[:os] = kernel[:name]
so = shell_out("uname -i")
kernel[:ident] = so.stdout.split($/)[0]
@@ -136,22 +218,10 @@
kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel:\ (.+)$/ }
kernel[:modules] = bsd_modules("/usr/bin/modstat")
end
- collect_data(:dragonflybsd) do
- kernel init_kernel
- kernel[:os] = kernel[:name]
-
- so = shell_out("uname -i")
- kernel[:ident] = so.stdout.split($/)[0]
- so = shell_out("sysctl kern.securelevel")
- kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel: (.+)$/ }
-
- kernel[:modules] = bsd_modules("/sbin/kldstat")
- end
-
collect_data(:solaris2) do
kernel init_kernel
so = shell_out("uname -s")
kernel[:os] = so.stdout.split($/)[0]
@@ -166,11 +236,11 @@
# EXAMPLE:
# Id Loadaddr Size Info Rev Module Name
# 6 1180000 4623 1 1 specfs (filesystem for specfs)
module_description = /[\s]*([\d]+)[\s]+([a-f\d]+)[\s]+([a-f\d]+)[\s]+(?:[\-\d]+)[\s]+(?:[\d]+)[\s]+([\S]+)[\s]+\((.+)\)$/
so.stdout.lines do |line|
- if mod = module_description.match(line)
+ if ( mod = module_description.match(line) )
modules[mod[4]] = { :id => mod[1].to_i, :loadaddr => mod[2], :size => mod[3].to_i(16), :description => mod[5] }
end
end
kernel[:modules] = modules
@@ -187,28 +257,27 @@
kernel Mash.new
host = wmi.first_of("Win32_OperatingSystem")
kernel[:os_info] = Mash.new
host.wmi_ole_object.properties_.each do |p|
+ next if blacklisted_wmi_name?(p.name.wmi_underscore)
kernel[:os_info][p.name.wmi_underscore.to_sym] = host[p.name.downcase]
end
kernel[:name] = "#{kernel[:os_info][:caption]}"
kernel[:release] = "#{kernel[:os_info][:version]}"
kernel[:version] = "#{kernel[:os_info][:version]} #{kernel[:os_info][:csd_version]} Build #{kernel[:os_info][:build_number]}"
- kernel[:os] = os_lookup(kernel[:os_info][:os_type]) || languages[:ruby][:host_os]
+ kernel[:os] = os_type_decode(kernel[:os_info][:os_type]) || languages[:ruby][:host_os]
+ kernel[:product_type] = product_type_decode(kernel[:os_info][:product_type])
+ kernel[:server_core] = server_core?(kernel[:os_info][:operating_system_sku])
- host = wmi.first_of("Win32_ComputerSystem")
kernel[:cs_info] = Mash.new
- cs_info_blacklist = [
- "oem_logo_bitmap",
- ]
+ host = wmi.first_of("Win32_ComputerSystem")
host.wmi_ole_object.properties_.each do |p|
- if !cs_info_blacklist.include?(p.name.wmi_underscore)
- kernel[:cs_info][p.name.wmi_underscore.to_sym] = host[p.name.downcase]
- end
+ next if blacklisted_wmi_name?(p.name.wmi_underscore)
+ kernel[:cs_info][p.name.wmi_underscore.to_sym] = host[p.name.downcase]
end
- kernel[:machine] = machine_lookup("#{kernel[:cs_info][:system_type]}")
-
+ kernel[:machine] = arch_lookup("#{kernel[:cs_info][:system_type]}")
+ kernel[:system_type] = pc_system_type_decode(kernel[:cs_info][:pc_system_type])
end
end