This repository has been archived by the owner on Jun 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
656 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facter | ||
module Windows | ||
class DmiManufacturer | ||
FACT_NAME = 'dmi.manufacturer' | ||
|
||
def call_the_resolver | ||
fact_value = DMIBiosResolver.resolve(:manufacturer) | ||
|
||
Fact.new(FACT_NAME, fact_value) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facter | ||
module Windows | ||
class DmiProductName | ||
FACT_NAME = 'dmi.product.name' | ||
|
||
def call_the_resolver | ||
fact_value = DMIComputerSystemResolver.resolve(:name) | ||
|
||
Fact.new(FACT_NAME, fact_value) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facter | ||
module Windows | ||
class DmiProductSerialNumber | ||
FACT_NAME = 'dmi.product.serial_number' | ||
|
||
def call_the_resolver | ||
fact_value = DMIBiosResolver.resolve(:serial_number) | ||
|
||
Fact.new(FACT_NAME, fact_value) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facter | ||
module Windows | ||
class DmiProductUUID | ||
FACT_NAME = 'dmi.product.uuid' | ||
|
||
def call_the_resolver | ||
fact_value = DMIComputerSystemResolver.resolve(:uuid) | ||
|
||
Fact.new(FACT_NAME, fact_value) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facter | ||
module Windows | ||
class ProcessorsCount | ||
FACT_NAME = 'processors.count' | ||
|
||
def call_the_resolver | ||
fact_value = ProcessorsResolver.resolve(:count) | ||
|
||
Fact.new(FACT_NAME, fact_value) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facter | ||
module Windows | ||
class ProcessorsIsa | ||
FACT_NAME = 'processors.isa' | ||
|
||
def call_the_resolver | ||
fact_value = ProcessorsResolver.resolve(:isa) | ||
|
||
Fact.new(FACT_NAME, fact_value) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facter | ||
module Windows | ||
class ProcessorsModels | ||
FACT_NAME = 'processors.models' | ||
|
||
def call_the_resolver | ||
fact_value = ProcessorsResolver.resolve(:models) | ||
|
||
Fact.new(FACT_NAME, fact_value) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facter | ||
module Windows | ||
class ProcessorsPhysicalcount | ||
FACT_NAME = 'processors.physicalcount' | ||
|
||
def call_the_resolver | ||
fact_value = ProcessorsResolver.resolve(:physicalcount) | ||
|
||
Fact.new(FACT_NAME, fact_value) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facter | ||
module Windows | ||
class IsVirtual | ||
FACT_NAME = 'is_virtual' | ||
|
||
def call_the_resolver | ||
fact_value = VirtualizationResolver.resolve(:is_virtual) | ||
|
||
Fact.new(FACT_NAME, fact_value) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facter | ||
module Windows | ||
class Virtual | ||
FACT_NAME = 'virtual' | ||
|
||
def call_the_resolver | ||
fact_value = VirtualizationResolver.resolve(:virtual) | ||
|
||
Fact.new(FACT_NAME, fact_value) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
class DMIBiosResolver < BaseResolver | ||
class << self | ||
# Manufacturer | ||
# SerialNumber | ||
@@semaphore = Mutex.new | ||
@@fact_list ||= {} | ||
|
||
def resolve(fact_name) | ||
@@semaphore.synchronize do | ||
result ||= @@fact_list[fact_name] | ||
|
||
return result if result | ||
|
||
win = Win32Ole.new | ||
bios = win.exec_query('SELECT Manufacturer,SerialNumber from Win32_BIOS').to_enum.first | ||
|
||
build_fact_list(bios) | ||
|
||
@@fact_list[fact_name] | ||
end | ||
end | ||
|
||
private | ||
|
||
def build_fact_list(bios) | ||
@@fact_list[:manufacturer] = bios.Manufacturer | ||
@@fact_list[:serial_number] = bios.SerialNumber | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
class DMIComputerSystemResolver < BaseResolver | ||
class << self | ||
# Name | ||
# UUID | ||
@@semaphore = Mutex.new | ||
@@fact_list ||= {} | ||
|
||
def resolve(fact_name) | ||
@@semaphore.synchronize do | ||
result ||= @@fact_list[fact_name] | ||
|
||
return result if result | ||
|
||
win = Win32Ole.new | ||
computersystem = win.exec_query('SELECT Name,UUID FROM Win32_ComputerSystemProduct').to_enum.first | ||
|
||
build_fact_list(computersystem) | ||
|
||
@@fact_list[fact_name] | ||
end | ||
end | ||
|
||
private | ||
|
||
def build_fact_list(computersys) | ||
@@fact_list[:name] = computersys.Name | ||
@@fact_list[:uuid] = computersys.UUID | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# frozen_string_literal: true | ||
|
||
class ProcessorsResolver < BaseResolver | ||
class << self | ||
# Count | ||
# Isa | ||
# Models | ||
# PhysicalCount | ||
@@semaphore = Mutex.new | ||
@@fact_list ||= {} | ||
|
||
def resolve(fact_name) | ||
@@semaphore.synchronize do | ||
result ||= @@fact_list[fact_name] | ||
|
||
return result if result | ||
|
||
win = Win32Ole.new | ||
proc = win.exec_query('SELECT Name,Architecture,NumberOfLogicalProcessors FROM Win32_Processor') | ||
|
||
result = iterate_proc(proc) | ||
build_fact_list(result) | ||
|
||
@@fact_list[fact_name] | ||
end | ||
end | ||
|
||
def invalidate_cache | ||
@@fact_list = {} | ||
end | ||
|
||
private | ||
|
||
def iterate_proc(result) | ||
models = [] | ||
isa = nil | ||
logical_count = 0 | ||
|
||
result.each do |proc| | ||
models << proc.Name | ||
logical_count += proc.NumberOfLogicalProcessors | ||
|
||
next if isa | ||
|
||
isa = find_isa(proc.Architecture) | ||
end | ||
|
||
logical_count = models.count if logical_count.zero? | ||
{ models: models, isa: isa, logical_count: logical_count } | ||
end | ||
|
||
def find_isa(arch) | ||
architecture_array = %w[x86 MIPS Alpha PowerPC ARM Itanium x64] | ||
isa = architecture_array[arch] | ||
|
||
return isa if isa | ||
|
||
raise 'Unable to determine processor type: unknown architecture' | ||
end | ||
|
||
def build_fact_list(result) | ||
@@fact_list[:count] = result[:logical_count] | ||
@@fact_list[:isa] = result[:isa] | ||
@@fact_list[:models] = result[:models] | ||
@@fact_list[:physicalcount] = result[:models].size | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
class VirtualizationResolver < BaseResolver | ||
class << self | ||
# Manufacturer | ||
# Name | ||
# SerialNumber | ||
# UUID | ||
@@semaphore = Mutex.new | ||
@@fact_list ||= {} | ||
|
||
def resolve(fact_name) | ||
@@semaphore.synchronize do | ||
result ||= @@fact_list[fact_name] | ||
|
||
return result if result | ||
|
||
win = Win32Ole.new | ||
comp = win.exec_query('SELECT Manufacturer,Model FROM Win32_ComputerSystem').to_enum.first | ||
hypervisor = determine_hypervisor_by_model(comp) || determine_hypervisor_by_manufacturer(comp) | ||
build_fact_list(hypervisor) | ||
|
||
@@fact_list[fact_name] | ||
end | ||
end | ||
|
||
def invalidate_cache | ||
@@fact_list = {} | ||
end | ||
|
||
private | ||
|
||
def determine_hypervisor_by_model(comp) | ||
model_hash = { 'VirtualBox' => 'virtualbox', 'VMware' => 'vmware', 'KVM' => 'kvm', | ||
'Bochs' => 'bochs', 'Google' => 'gce', 'OpenStack' => 'openstack' } | ||
model_hash[model_hash.keys.find { |key| comp.Model =~ /^#{key}/ }] | ||
end | ||
|
||
def determine_hypervisor_by_manufacturer(comp) | ||
manufacturer = comp.Manufacturer | ||
if comp.Model =~ /^Virtual Machine/ && manufacturer =~ /^Microsoft/ | ||
'hyperv' | ||
elsif manufacturer =~ /^Xen/ | ||
'xen' | ||
elsif manufacturer =~ /^Amazon EC2/ | ||
'kvm' | ||
else | ||
'physical' | ||
end | ||
end | ||
|
||
def build_fact_list(hypervisor) | ||
@@fact_list[:virtual] = hypervisor | ||
@@fact_list[:is_virtual] = 'false' | ||
@@fact_list[:is_virtual] = 'true' unless hypervisor =~ /physical/ | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'win32ole' | ||
|
||
class Win32Ole | ||
RPC_C_IMP_LEVEL_IMPERSONATE = 3 | ||
|
||
def initialize | ||
locator = WIN32OLE.new('WbemScripting.SWbemLocator') | ||
@conn = locator.ConnectServer('.', 'root\\cimv2') | ||
@conn.Security_.ImpersonationLevel = RPC_C_IMP_LEVEL_IMPERSONATE | ||
end | ||
|
||
def exec_query(query) | ||
@conn.execquery(query) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.