-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add vmware fact and update dmidecode resolver
- Loading branch information
BogdanIrimie
committed
Jul 10, 2020
1 parent
353bf71
commit ace9b67
Showing
6 changed files
with
299 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facts | ||
module Linux | ||
module Hypervisors | ||
class Vmware | ||
FACT_NAME = 'hypervisors.vmware' | ||
|
||
def initialize | ||
@log = Facter::Log.new(self) | ||
end | ||
|
||
def call_the_resolver | ||
if vmware? | ||
@log.debug('Vmware hypervisor detected') | ||
fact_value = {} | ||
|
||
fact_value[:version] = Facter::Resolvers::DmiDecode.resolve(:vmware_version) || '' | ||
|
||
return Facter::ResolvedFact.new(FACT_NAME, fact_value) | ||
end | ||
|
||
@log.debug('No Vmware hypervisor detected.') | ||
[] | ||
end | ||
|
||
private | ||
|
||
def vmware? | ||
Facter::Resolvers::VirtWhat.resolve(:vm) == 'vmware' || | ||
Facter::Resolvers::Linux::DmiBios.resolve(:product_name) == 'VMware' || | ||
Facter::Resolvers::Lspci.resolve(:vm) == 'vmware' || | ||
Facter::Resolvers::Linux::DmiBios.resolve(:sys_vendor) == 'VMware, Inc.' | ||
end | ||
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
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,76 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Facts::Linux::Hypervisors::Vmware do | ||
subject(:fact) { Facts::Linux::Hypervisors::Vmware.new } | ||
|
||
describe '#call_the_resolver' do | ||
context 'when vmware is detected' do | ||
context 'when VirtWhat resolver returns vmware' do | ||
before do | ||
allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return('vmware') | ||
allow(Facter::Resolvers::DmiDecode).to receive(:resolve).with(:vmware_version).and_return('ESXi 6.7') | ||
end | ||
|
||
it 'returns vmware' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact) | ||
.and have_attributes(name: 'hypervisors.vmware', value: { 'version' => 'ESXi 6.7' }) | ||
end | ||
end | ||
|
||
context 'when DmiBios resolver with product_name returns VMware' do | ||
before do | ||
allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return('unknown') | ||
allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:product_name).and_return('VMware') | ||
allow(Facter::Resolvers::DmiDecode).to receive(:resolve).with(:vmware_version).and_return('ESXi 6.7') | ||
end | ||
|
||
it 'returns vmware' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact) | ||
.and have_attributes(name: 'hypervisors.vmware', value: { 'version' => 'ESXi 6.7' }) | ||
end | ||
end | ||
|
||
context 'when Lspci resolver returns vmware' do | ||
before do | ||
allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return('unknown') | ||
allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:product_name).and_return('unknown') | ||
allow(Facter::Resolvers::Lspci).to receive(:resolve).with(:vm).and_return('vmware') | ||
allow(Facter::Resolvers::DmiDecode).to receive(:resolve).with(:vmware_version).and_return('ESXi 6.7') | ||
end | ||
|
||
it 'returns vmware' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact) | ||
.and have_attributes(name: 'hypervisors.vmware', value: { 'version' => 'ESXi 6.7' }) | ||
end | ||
end | ||
|
||
context 'when DmiBios resolver with sys_vendor returns VMware, Inc.' do | ||
before do | ||
allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return('unknown') | ||
allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:product_name).and_return('unknown') | ||
allow(Facter::Resolvers::Lspci).to receive(:resolve).with(:vm).and_return('unknown') | ||
allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:sys_vendor).and_return('VMware, Inc.') | ||
allow(Facter::Resolvers::DmiDecode).to receive(:resolve).with(:vmware_version).and_return('ESXi 6.7') | ||
end | ||
|
||
it 'returns vmware' do | ||
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact) | ||
.and have_attributes(name: 'hypervisors.vmware', value: { 'version' => 'ESXi 6.7' }) | ||
end | ||
end | ||
end | ||
|
||
context 'when vmware is not detected' do | ||
before do | ||
allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return('unknown') | ||
allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:product_name).and_return('unknown') | ||
allow(Facter::Resolvers::Lspci).to receive(:resolve).with(:vm).and_return('unknown') | ||
allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:sys_vendor).and_return('unknown') | ||
end | ||
|
||
it 'returns empty list' do | ||
expect(fact.call_the_resolver).to eq([]) | ||
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
File renamed without changes.
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,130 @@ | ||
Getting SMBIOS data from sysfs. | ||
SMBIOS 2.7 present. | ||
242 structures occupying 9908 bytes. | ||
Table at 0x000E0010. | ||
|
||
Handle 0x0000, DMI type 0, 24 bytes | ||
BIOS Information | ||
Vendor: Phoenix Technologies LTD | ||
Version: 6.00 | ||
Release Date: 12/12/2018 | ||
Address: 0xEA490 | ||
Runtime Size: 88944 bytes | ||
ROM Size: 64 kB | ||
Characteristics: | ||
ISA is supported | ||
PCI is supported | ||
PC Card (PCMCIA) is supported | ||
PNP is supported | ||
APM is supported | ||
BIOS is upgradeable | ||
BIOS shadowing is allowed | ||
ESCD support is available | ||
Boot from CD is supported | ||
Selectable boot is supported | ||
EDD is supported | ||
Print screen service is supported (int 5h) | ||
8042 keyboard services are supported (int 9h) | ||
Serial services are supported (int 14h) | ||
Printer services are supported (int 17h) | ||
CGA/mono video services are supported (int 10h) | ||
ACPI is supported | ||
Smart battery is supported | ||
BIOS boot specification is supported | ||
Function key-initiated network boot is supported | ||
Targeted content distribution is supported | ||
BIOS Revision: 4.6 | ||
Firmware Revision: 0.0 | ||
|
||
Handle 0x0001, DMI type 1, 27 bytes | ||
System Information | ||
Manufacturer: VMware, Inc. | ||
Product Name: VMware Virtual Platform | ||
Version: None | ||
Serial Number: VMware-42 1a ee 9a 8e 13 ee e5-fc ec 82 3d cd 74 76 94 | ||
UUID: 9aee1a42-138e-e5ee-fcec-823dcd747694 | ||
Wake-up Type: Power Switch | ||
SKU Number: Not Specified | ||
Family: Not Specified | ||
|
||
Handle 0x0002, DMI type 2, 15 bytes | ||
Base Board Information | ||
Manufacturer: Intel Corporation | ||
Product Name: 440BX Desktop Reference Platform | ||
Version: None | ||
Serial Number: None | ||
Asset Tag: Not Specified | ||
Features: None | ||
Location In Chassis: Not Specified | ||
Chassis Handle: 0x0000 | ||
Type: Unknown | ||
Contained Object Handles: 0 | ||
|
||
Handle 0x0003, DMI type 3, 21 bytes | ||
Chassis Information | ||
Manufacturer: No Enclosure | ||
Type: Other | ||
Lock: Not Present | ||
Version: N/A | ||
Serial Number: None | ||
Asset Tag: No Asset Tag | ||
Boot-up State: Safe | ||
Power Supply State: Safe | ||
Thermal State: Safe | ||
Security Status: None | ||
OEM Information: 0x00001234 | ||
Height: Unspecified | ||
Number Of Power Cords: Unspecified | ||
Contained Elements: 0 | ||
|
||
Handle 0x0004, DMI type 4, 42 bytes | ||
Processor Information | ||
Socket Designation: CPU #000 | ||
Type: Central Processor | ||
Family: Unknown | ||
Manufacturer: GenuineIntel | ||
ID: 54 06 05 00 FF FB 8B 0F | ||
Version: Intel(R) Xeon(R) Gold 6138 CPU @ 2.00GHz | ||
Voltage: 3.3 V | ||
External Clock: Unknown | ||
Max Speed: 30000 MHz | ||
Current Speed: 2000 MHz | ||
Status: Populated, Enabled | ||
Upgrade: ZIF Socket | ||
L1 Cache Handle: 0x0016 | ||
L2 Cache Handle: 0x0018 | ||
L3 Cache Handle: Not Provided | ||
Serial Number: Not Specified | ||
Asset Tag: Not Specified | ||
Part Number: Not Specified | ||
Core Count: 1 | ||
Core Enabled: 1 | ||
Characteristics: | ||
64-bit capable | ||
Execute Protection | ||
|
||
Handle 0x0004, DMI type 4, 42 bytes | ||
Processor Information | ||
Socket Designation: CPU #001 | ||
Type: Central Processor | ||
Family: Unknown | ||
Manufacturer: GenuineIntel | ||
ID: 54 06 00 00 FF FB 8B 0F | ||
Version: Intel(R) Xeon(R) Gold 6138 CPU @ 2.00GHz | ||
Voltage: 3.3 V | ||
External Clock: Unknown | ||
Max Speed: 30000 MHz | ||
Current Speed: 2000 MHz | ||
Status: Populated, Enabled | ||
Upgrade: ZIF Socket | ||
L1 Cache Handle: 0x0016 | ||
L2 Cache Handle: 0x0018 | ||
L3 Cache Handle: Not Provided | ||
Serial Number: Not Specified | ||
Asset Tag: Not Specified | ||
Part Number: Not Specified | ||
Core Count: 1 | ||
Core Enabled: 1 | ||
Characteristics: | ||
64-bit capable | ||
Execute Protection |