facter 4.0.40 → 4.0.41

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64bb37710d33d522370161fab93516fed5961615ff3fc44609ee6700318efda4
4
- data.tar.gz: 47e222b78a6a4ce13ee4d0fc91cbcca942b4b3c9357e35debbc2ea61d401867c
3
+ metadata.gz: c21fc41638fbbab14ccb415eec2104ed296236c98d7870a341c37742796c8fc1
4
+ data.tar.gz: 7b09bdc7ecc99e1947d9eb5bcacb7873f3b954224904d0930ee69846c47d5e88
5
5
  SHA512:
6
- metadata.gz: 4bb85c358a104d83fde58ad5ce0733736f5e2295324d1041e79d24c5c08cf284f2eb32c30b9024a5f216713b8a12a92a01249aab0346aec016ebeecc1c77d82f
7
- data.tar.gz: 2f079a4fc5788d5e4c5698d0b5ad31cfc7affa352b19d636c077faa3125e342ba14e4d1c3d53a1684112cd9a76c27365fe9f2f9713502ea52b8d4ceffd56eee7
6
+ metadata.gz: 327664693c0725ab4aafc339e6091557dc00d2dee945a9f6d6f3bca5d3a6d1ab8b56809c5d9b7374029fcd277a8bc5107ff76a03522c9104e214f4c967417a04
7
+ data.tar.gz: 2d60b83c461d1bcdaa611322061f844f186951341562b5a3ec83d35512d58059776a5772b41bdf97b2cb77c2fb53abd2a744f9bddc49042b6d421868411c010a
@@ -5,6 +5,10 @@ module Facts
5
5
  class Ec2Metadata
6
6
  FACT_NAME = 'ec2_metadata'
7
7
 
8
+ def initialize
9
+ @virtual = Facter::VirtualDetector.new
10
+ end
11
+
8
12
  def call_the_resolver
9
13
  return Facter::ResolvedFact.new(FACT_NAME, nil) unless aws_hypervisors?
10
14
 
@@ -16,36 +20,7 @@ module Facts
16
20
  private
17
21
 
18
22
  def aws_hypervisors?
19
- virtual =~ /kvm|xen|aws/
20
- end
21
-
22
- def virtual
23
- check_virt_what || check_xen || check_product_name || check_bios_vendor || check_lspci
24
- end
25
-
26
- def check_virt_what
27
- Facter::Resolvers::VirtWhat.resolve(:vm)
28
- end
29
-
30
- def check_xen
31
- Facter::Resolvers::Xen.resolve(:vm)
32
- end
33
-
34
- def check_product_name
35
- product_name = Facter::Resolvers::Linux::DmiBios.resolve(:product_name)
36
- return unless product_name
37
-
38
- _, value = Facter::FactsUtils::HYPERVISORS_HASH.find { |key, _value| product_name.include?(key) }
39
- value
40
- end
41
-
42
- def check_bios_vendor
43
- bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
44
- return 'kvm' if bios_vendor&.include?('Amazon EC2')
45
- end
46
-
47
- def check_lspci
48
- Facter::Resolvers::Lspci.resolve(:vm)
23
+ @virtual.platform =~ /kvm|xen|aws/
49
24
  end
50
25
  end
51
26
  end
@@ -5,6 +5,10 @@ module Facts
5
5
  class Ec2Userdata
6
6
  FACT_NAME = 'ec2_userdata'
7
7
 
8
+ def initialize
9
+ @virtual = Facter::VirtualDetector.new
10
+ end
11
+
8
12
  def call_the_resolver
9
13
  return Facter::ResolvedFact.new(FACT_NAME, nil) unless aws_hypervisors?
10
14
 
@@ -16,34 +20,7 @@ module Facts
16
20
  private
17
21
 
18
22
  def aws_hypervisors?
19
- virtual = check_virt_what || check_xen || check_product_name || check_bios_vendor || check_lspci
20
-
21
- virtual == 'kvm' || virtual =~ /xen/
22
- end
23
-
24
- def check_virt_what
25
- Facter::Resolvers::VirtWhat.resolve(:vm)
26
- end
27
-
28
- def check_xen
29
- Facter::Resolvers::Xen.resolve(:vm)
30
- end
31
-
32
- def check_product_name
33
- product_name = Facter::Resolvers::Linux::DmiBios.resolve(:product_name)
34
- return unless product_name
35
-
36
- _, value = Facter::FactsUtils::HYPERVISORS_HASH.find { |key, _value| product_name.include?(key) }
37
- value
38
- end
39
-
40
- def check_bios_vendor
41
- bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
42
- return 'kvm' if bios_vendor&.include?('Amazon EC2')
43
- end
44
-
45
- def check_lspci
46
- Facter::Resolvers::Lspci.resolve(:vm)
23
+ @virtual.platform =~ /kvm|xen|aws/
47
24
  end
48
25
  end
49
26
  end
@@ -5,59 +5,20 @@ module Facts
5
5
  class IsVirtual
6
6
  FACT_NAME = 'is_virtual'
7
7
 
8
- def call_the_resolver # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
9
- fact_value = check_docker_lxc || check_gce || retrieve_from_virt_what || check_vmware
10
- fact_value ||= check_open_vz || check_vserver || check_xen || check_other_facts || check_lspci || 'physical'
11
-
12
- Facter::ResolvedFact.new(FACT_NAME, check_if_virtual(fact_value))
13
- end
14
-
15
- def check_gce
16
- bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
17
- 'gce' if bios_vendor&.include?('Google')
18
- end
19
-
20
- def check_docker_lxc
21
- Facter::Resolvers::Containers.resolve(:vm)
8
+ def initialize
9
+ @virtual = Facter::VirtualDetector.new
22
10
  end
23
11
 
24
- def check_vmware
25
- Facter::Resolvers::Vmware.resolve(:vm)
26
- end
12
+ def call_the_resolver
13
+ fact_value = @virtual.platform
27
14
 
28
- def retrieve_from_virt_what
29
- Facter::Resolvers::VirtWhat.resolve(:vm)
30
- end
31
-
32
- def check_open_vz
33
- Facter::Resolvers::OpenVz.resolve(:vm)
34
- end
35
-
36
- def check_vserver
37
- Facter::Resolvers::VirtWhat.resolve(:vserver)
38
- end
39
-
40
- def check_xen
41
- Facter::Resolvers::Xen.resolve(:vm)
42
- end
43
-
44
- def check_other_facts
45
- product_name = Facter::Resolvers::Linux::DmiBios.resolve(:product_name)
46
- bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
47
- return 'kvm' if bios_vendor&.include?('Amazon EC2')
48
- return unless product_name
49
-
50
- Facter::FactsUtils::HYPERVISORS_HASH.each { |key, value| return value if product_name.include?(key) }
51
-
52
- nil
15
+ Facter::ResolvedFact.new(FACT_NAME, check_if_virtual(fact_value))
53
16
  end
54
17
 
55
- def check_lspci
56
- Facter::Resolvers::Lspci.resolve(:vm)
57
- end
18
+ private
58
19
 
59
20
  def check_if_virtual(found_vm)
60
- Facter::FactsUtils::PHYSICAL_HYPERVISORS.count(found_vm).zero?
21
+ Facter::FactsUtils::PHYSICAL_HYPERVISORS.count(found_vm).zero?.to_s
61
22
  end
62
23
  end
63
24
  end
@@ -7,71 +7,16 @@ module Facts
7
7
 
8
8
  def initialize
9
9
  @log = Facter::Log.new(self)
10
+ @virtual = Facter::VirtualDetector.new
10
11
  end
11
12
 
12
- def call_the_resolver # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
13
+ def call_the_resolver
13
14
  @log.debug('Linux Virtual Resolver')
14
-
15
- fact_value = check_docker_lxc || check_gce || retrieve_from_virt_what || check_vmware
16
- fact_value ||= check_open_vz || check_vserver || check_xen || check_other_facts || check_lspci || 'physical'
17
-
15
+ fact_value = @virtual.platform
18
16
  @log.debug("Fact value is: #{fact_value}")
19
17
 
20
18
  Facter::ResolvedFact.new(FACT_NAME, fact_value)
21
19
  end
22
-
23
- def check_gce
24
- @log.debug('Checking GCE')
25
- bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
26
- 'gce' if bios_vendor&.include?('Google')
27
- end
28
-
29
- def check_docker_lxc
30
- @log.debug('Checking Docker and LXC')
31
- Facter::Resolvers::Containers.resolve(:vm)
32
- end
33
-
34
- def check_vmware
35
- @log.debug('Checking VMware')
36
- Facter::Resolvers::Vmware.resolve(:vm)
37
- end
38
-
39
- def retrieve_from_virt_what
40
- @log.debug('Checking virtual_what')
41
- Facter::Resolvers::VirtWhat.resolve(:vm)
42
- end
43
-
44
- def check_open_vz
45
- @log.debug('Checking OpenVZ')
46
- Facter::Resolvers::OpenVz.resolve(:vm)
47
- end
48
-
49
- def check_vserver
50
- @log.debug('Checking VServer')
51
- Facter::Resolvers::VirtWhat.resolve(:vserver)
52
- end
53
-
54
- def check_xen
55
- @log.debug('Checking XEN')
56
- Facter::Resolvers::Xen.resolve(:vm)
57
- end
58
-
59
- def check_other_facts
60
- @log.debug('Checking others')
61
- product_name = Facter::Resolvers::Linux::DmiBios.resolve(:product_name)
62
- bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
63
- return 'kvm' if bios_vendor&.include?('Amazon EC2')
64
- return unless product_name
65
-
66
- Facter::FactsUtils::HYPERVISORS_HASH.each { |key, value| return value if product_name.include?(key) }
67
-
68
- nil
69
- end
70
-
71
- def check_lspci
72
- @log.debug('Checking lspci')
73
- Facter::Resolvers::Lspci.resolve(:vm)
74
- end
75
20
  end
76
21
  end
77
22
  end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ class VirtualDetector
5
+ def initialize
6
+ @log = Facter::Log.new(self)
7
+ end
8
+
9
+ def platform # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
10
+ fact_value = check_docker_lxc || check_dmi || check_gce || retrieve_from_virt_what || check_vmware
11
+ fact_value ||= check_open_vz || check_vserver || check_xen || check_other_facts || check_lspci || 'physical'
12
+
13
+ fact_value
14
+ end
15
+
16
+ def check_docker_lxc
17
+ @log.debug('Checking Docker and LXC')
18
+ Facter::Resolvers::Containers.resolve(:vm)
19
+ end
20
+
21
+ def check_dmi
22
+ @log.debug('Checking DMI')
23
+ vendor = Facter::Resolvers::DmiDecode.resolve(:vendor)
24
+ @log.debug("dmi detected vendor: #{vendor}")
25
+ return 'aws' if vendor =~ /Amazon/
26
+
27
+ 'xen' if vendor =~ /Xen/
28
+ end
29
+
30
+ def check_gce
31
+ @log.debug('Checking GCE')
32
+ bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
33
+ 'gce' if bios_vendor&.include?('Google')
34
+ end
35
+
36
+ def check_vmware
37
+ @log.debug('Checking VMware')
38
+ Facter::Resolvers::Vmware.resolve(:vm)
39
+ end
40
+
41
+ def retrieve_from_virt_what
42
+ @log.debug('Checking virtual_what')
43
+ Facter::Resolvers::VirtWhat.resolve(:vm)
44
+ end
45
+
46
+ def check_open_vz
47
+ @log.debug('Checking OpenVZ')
48
+ Facter::Resolvers::OpenVz.resolve(:vm)
49
+ end
50
+
51
+ def check_vserver
52
+ @log.debug('Checking VServer')
53
+ Facter::Resolvers::VirtWhat.resolve(:vserver)
54
+ end
55
+
56
+ def check_xen
57
+ @log.debug('Checking XEN')
58
+ Facter::Resolvers::Xen.resolve(:vm)
59
+ end
60
+
61
+ def check_other_facts
62
+ @log.debug('Checking others')
63
+ product_name = Facter::Resolvers::Linux::DmiBios.resolve(:product_name)
64
+ bios_vendor = Facter::Resolvers::Linux::DmiBios.resolve(:bios_vendor)
65
+ return 'kvm' if bios_vendor&.include?('Amazon EC2')
66
+ return unless product_name
67
+
68
+ Facter::FactsUtils::HYPERVISORS_HASH.each { |key, value| return value if product_name.include?(key) }
69
+
70
+ nil
71
+ end
72
+
73
+ def check_lspci
74
+ @log.debug('Checking lspci')
75
+ Facter::Resolvers::Lspci.resolve(:vm)
76
+ end
77
+ end
78
+ end
@@ -37,6 +37,7 @@ module Facter
37
37
  @fact_list[:virtualbox_version] = output.match(/vboxVer_(\S+)/)&.captures&.first
38
38
  @fact_list[:virtualbox_revision] = output.match(/vboxRev_(\S+)/)&.captures&.first
39
39
  @fact_list[:vmware_version] = extract_vmware_version(output)
40
+ @fact_list[:vendor] = output.match(/Vendor: (\S+)/)&.captures&.first
40
41
 
41
42
  @fact_list[fact_name]
42
43
  end
@@ -10,7 +10,6 @@ module Facter
10
10
  private
11
11
 
12
12
  def post_resolve(fact_name)
13
- log.debug('in networking_linux_resolver')
14
13
  @fact_list.fetch(fact_name) { retrieve_network_info(fact_name) }
15
14
 
16
15
  @fact_list[fact_name]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Facter
4
- VERSION = '4.0.40' unless defined?(VERSION)
4
+ VERSION = '4.0.41' unless defined?(VERSION)
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facter
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.40
4
+ version: 4.0.41
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-30 00:00:00.000000000 Z
11
+ date: 2020-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -814,6 +814,7 @@ files:
814
814
  - lib/facter/facts_utils/facts_utils.rb
815
815
  - lib/facter/facts_utils/unit_converter.rb
816
816
  - lib/facter/facts_utils/uptime_parser.rb
817
+ - lib/facter/facts_utils/virtual_detector.rb
817
818
  - lib/facter/facts_utils/windows_release_finder.rb
818
819
  - lib/facter/framework/benchmarking/timer.rb
819
820
  - lib/facter/framework/cli/cli.rb