|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +module Facter |
| 4 | + module Resolvers |
| 5 | + class DMISystemEnclosure < BaseResolver |
| 6 | + @log = Facter::Log.new(self) |
| 7 | + init_resolver |
| 8 | + |
| 9 | + class << self |
| 10 | + # ChassisType |
| 11 | + |
| 12 | + private |
| 13 | + |
| 14 | + def post_resolve(fact_name, _options) |
| 15 | + @fact_list.fetch(fact_name) { read_facts(fact_name) } |
| 16 | + end |
| 17 | + |
| 18 | + def read_facts(fact_name) |
| 19 | + win = Facter::Util::Windows::Win32Ole.new |
| 20 | + systemenclosure = win.return_first('SELECT ChassisTypes FROM Win32_SystemEnclosure') |
| 21 | + unless systemenclosure |
| 22 | + @log.debug 'WMI query returned no results for Win32_SystemEnclosure with values ChassisTypes.' |
| 23 | + return |
| 24 | + end |
| 25 | + |
| 26 | + build_fact_list(systemenclosure) |
| 27 | + |
| 28 | + # ChassisTypes is an Array on Windows - Convert the first one to a name |
| 29 | + chassis_to_name(@fact_list[fact_name][0]) if fact_name == :chassis_type |
| 30 | + |
| 31 | + @fact_list[fact_name] |
| 32 | + end |
| 33 | + |
| 34 | + def build_fact_list(systemenclosure) |
| 35 | + @fact_list[:chassis_type] = systemenclosure.ChassisTypes |
| 36 | + end |
| 37 | + |
| 38 | + def chassis_to_name(chassis_type) |
| 39 | + types = ['Other', nil, 'Desktop', 'Low Profile Desktop', 'Pizza Box', 'Mini Tower', 'Tower', |
| 40 | + 'Portable', 'Laptop', 'Notebook', 'Hand Held', 'Docking Station', 'All in One', 'Sub Notebook', |
| 41 | + 'Space-Saving', 'Lunch Box', 'Main System Chassis', 'Expansion Chassis', 'SubChassis', |
| 42 | + 'Bus Expansion Chassis', 'Peripheral Chassis', 'Storage Chassis', 'Rack Mount Chassis', |
| 43 | + 'Sealed-Case PC', 'Multi-system', 'CompactPCI', 'AdvancedTCA', 'Blade', 'Blade Enclosure', |
| 44 | + 'Tablet', 'Convertible', 'Detachable'] |
| 45 | + @fact_list[:chassis_type] = types[chassis_type.to_i - 1] |
| 46 | + end |
| 47 | + end |
| 48 | + end |
| 49 | + end |
| 50 | +end |
0 commit comments