facter 4.0.34 → 4.0.35

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/lib/facter/facts/aix/ssh.rb +3 -1
  3. data/lib/facter/facts/freebsd/augeas/version.rb +19 -0
  4. data/lib/facter/facts/freebsd/facterversion.rb +14 -0
  5. data/lib/facter/facts/freebsd/identity/gid.rb +16 -0
  6. data/lib/facter/facts/{solaris/solaris_zones/current.rb → freebsd/identity/group.rb} +6 -6
  7. data/lib/facter/facts/freebsd/identity/privileged.rb +16 -0
  8. data/lib/facter/facts/freebsd/identity/uid.rb +16 -0
  9. data/lib/facter/facts/freebsd/identity/user.rb +17 -0
  10. data/lib/facter/facts/freebsd/kernel.rb +14 -0
  11. data/lib/facter/facts/freebsd/kernelrelease.rb +14 -0
  12. data/lib/facter/facts/freebsd/mountpoints.rb +21 -0
  13. data/lib/facter/facts/freebsd/netmask6_interfaces.rb +20 -0
  14. data/lib/facter/facts/freebsd/netmask_interfaces.rb +20 -0
  15. data/lib/facter/facts/freebsd/network6_interfaces.rb +20 -0
  16. data/lib/facter/facts/freebsd/network_interfaces.rb +20 -0
  17. data/lib/facter/facts/freebsd/networking/dhcp.rb +17 -0
  18. data/lib/facter/facts/freebsd/networking/domain.rb +18 -0
  19. data/lib/facter/facts/freebsd/networking/fqdn.rb +18 -0
  20. data/lib/facter/facts/freebsd/networking/hostname.rb +18 -0
  21. data/lib/facter/facts/freebsd/networking/interfaces.rb +17 -0
  22. data/lib/facter/facts/freebsd/networking/ip.rb +18 -0
  23. data/lib/facter/facts/freebsd/networking/ip6.rb +18 -0
  24. data/lib/facter/facts/freebsd/networking/mac.rb +18 -0
  25. data/lib/facter/facts/freebsd/networking/mtu.rb +17 -0
  26. data/lib/facter/facts/freebsd/networking/netmask.rb +18 -0
  27. data/lib/facter/facts/freebsd/networking/netmask6.rb +18 -0
  28. data/lib/facter/facts/freebsd/networking/network.rb +18 -0
  29. data/lib/facter/facts/freebsd/networking/network6.rb +18 -0
  30. data/lib/facter/facts/freebsd/networking/primary.rb +17 -0
  31. data/lib/facter/facts/freebsd/networking/scope6.rb +17 -0
  32. data/lib/facter/facts/freebsd/os/architecture.rb +18 -0
  33. data/lib/facter/facts/freebsd/os/hardware.rb +18 -0
  34. data/lib/facter/facts/freebsd/os/name.rb +18 -0
  35. data/lib/facter/facts/{bsd/bsd_example_fact.rb → freebsd/path.rb} +5 -4
  36. data/lib/facter/facts/freebsd/processors/isa.rb +17 -0
  37. data/lib/facter/facts/freebsd/puppet_version.rb +15 -0
  38. data/lib/facter/facts/freebsd/ruby/platform.rb +18 -0
  39. data/lib/facter/facts/freebsd/ruby/sitedir.rb +18 -0
  40. data/lib/facter/facts/freebsd/ruby/version.rb +18 -0
  41. data/lib/facter/facts/freebsd/ssh.rb +26 -0
  42. data/lib/facter/facts/freebsd/system_uptime/days.rb +18 -0
  43. data/lib/facter/facts/freebsd/system_uptime/hours.rb +18 -0
  44. data/lib/facter/facts/freebsd/system_uptime/seconds.rb +18 -0
  45. data/lib/facter/facts/freebsd/system_uptime/uptime.rb +18 -0
  46. data/lib/facter/facts/freebsd/timezone.rb +15 -0
  47. data/lib/facter/facts/freebsd/zfs_featurenumbers.rb +14 -0
  48. data/lib/facter/facts/freebsd/zfs_version.rb +14 -0
  49. data/lib/facter/facts/freebsd/zpool_featureflags.rb +14 -0
  50. data/lib/facter/facts/freebsd/zpool_featurenumbers.rb +14 -0
  51. data/lib/facter/facts/freebsd/zpool_version.rb +14 -0
  52. data/lib/facter/facts/linux/mountpoints.rb +1 -1
  53. data/lib/facter/facts/linux/partitions.rb +1 -1
  54. data/lib/facter/facts/linux/ssh.rb +19 -9
  55. data/lib/facter/facts/linux/system_uptime/days.rb +7 -1
  56. data/lib/facter/facts/linux/system_uptime/hours.rb +7 -1
  57. data/lib/facter/facts/linux/system_uptime/seconds.rb +7 -1
  58. data/lib/facter/facts/linux/system_uptime/uptime.rb +7 -1
  59. data/lib/facter/facts/macosx/dhcp_servers.rb +2 -2
  60. data/lib/facter/facts/macosx/interfaces.rb +1 -1
  61. data/lib/facter/facts/macosx/ipaddress6_interfaces.rb +1 -1
  62. data/lib/facter/facts/macosx/ipaddress_interfaces.rb +1 -1
  63. data/lib/facter/facts/macosx/macaddress_interfaces.rb +1 -1
  64. data/lib/facter/facts/macosx/mtu_interfaces.rb +1 -1
  65. data/lib/facter/facts/macosx/netmask6_interfaces.rb +1 -1
  66. data/lib/facter/facts/macosx/netmask_interfaces.rb +1 -1
  67. data/lib/facter/facts/macosx/network6_interfaces.rb +1 -1
  68. data/lib/facter/facts/macosx/network_interfaces.rb +1 -1
  69. data/lib/facter/facts/macosx/networking/dhcp.rb +1 -1
  70. data/lib/facter/facts/macosx/networking/interfaces.rb +1 -1
  71. data/lib/facter/facts/macosx/networking/ip.rb +1 -1
  72. data/lib/facter/facts/macosx/networking/ip6.rb +1 -1
  73. data/lib/facter/facts/macosx/networking/mac.rb +1 -1
  74. data/lib/facter/facts/macosx/networking/mtu.rb +1 -1
  75. data/lib/facter/facts/macosx/networking/netmask.rb +1 -1
  76. data/lib/facter/facts/macosx/networking/netmask6.rb +1 -1
  77. data/lib/facter/facts/macosx/networking/network.rb +1 -1
  78. data/lib/facter/facts/macosx/networking/network6.rb +1 -1
  79. data/lib/facter/facts/macosx/networking/primary.rb +1 -1
  80. data/lib/facter/facts/macosx/networking/scope6.rb +1 -1
  81. data/lib/facter/facts/macosx/scope6_interfaces.rb +2 -2
  82. data/lib/facter/facts/macosx/ssh.rb +19 -11
  83. data/lib/facter/facts/solaris/current_zone.rb +16 -0
  84. data/lib/facter/facts/solaris/disks.rb +14 -0
  85. data/lib/facter/facts/solaris/dmi/bios/release_date.rb +24 -0
  86. data/lib/facter/facts/solaris/dmi/bios/vendor.rb +24 -0
  87. data/lib/facter/facts/solaris/dmi/bios/version.rb +24 -0
  88. data/lib/facter/facts/solaris/dmi/chassis/asset_tag.rb +24 -0
  89. data/lib/facter/facts/solaris/dmi/chassis/type.rb +24 -0
  90. data/lib/facter/facts/solaris/dmi/manufacturer.rb +25 -0
  91. data/lib/facter/facts/solaris/dmi/product/name.rb +27 -0
  92. data/lib/facter/facts/solaris/dmi/product/serial_number.rb +27 -0
  93. data/lib/facter/facts/solaris/dmi/product/uuid.rb +24 -0
  94. data/lib/facter/facts/solaris/mountpoints.rb +1 -1
  95. data/lib/facter/facts/solaris/os/release.rb +3 -3
  96. data/lib/facter/facts/solaris/ssh.rb +19 -9
  97. data/lib/facter/facts/solaris/zfs_featurenumbers.rb +1 -1
  98. data/lib/facter/facts/solaris/zfs_version.rb +1 -1
  99. data/lib/facter/facts/solaris/zones.rb +60 -0
  100. data/lib/facter/facts/solaris/zpool_featureflags.rb +1 -1
  101. data/lib/facter/facts/solaris/zpool_featurenumbers.rb +1 -1
  102. data/lib/facter/facts/solaris/zpool_version.rb +1 -1
  103. data/lib/facter/facts/windows/dhcp_servers.rb +2 -2
  104. data/lib/facter/facts/windows/interfaces.rb +1 -1
  105. data/lib/facter/facts/windows/ipaddress6_interfaces.rb +1 -1
  106. data/lib/facter/facts/windows/ipaddress_interfaces.rb +1 -1
  107. data/lib/facter/facts/windows/macaddress_interfaces.rb +1 -1
  108. data/lib/facter/facts/windows/mtu_interfaces.rb +1 -1
  109. data/lib/facter/facts/windows/netmask6_interfaces.rb +1 -1
  110. data/lib/facter/facts/windows/netmask_interfaces.rb +1 -1
  111. data/lib/facter/facts/windows/network6_interfaces.rb +1 -1
  112. data/lib/facter/facts/windows/network_interfaces.rb +1 -1
  113. data/lib/facter/facts/windows/networking/dhcp.rb +1 -1
  114. data/lib/facter/facts/windows/networking/domain.rb +1 -1
  115. data/lib/facter/facts/windows/networking/fqdn.rb +1 -1
  116. data/lib/facter/facts/windows/networking/interfaces.rb +1 -1
  117. data/lib/facter/facts/windows/networking/ip.rb +1 -1
  118. data/lib/facter/facts/windows/networking/ip6.rb +1 -1
  119. data/lib/facter/facts/windows/networking/mac.rb +1 -1
  120. data/lib/facter/facts/windows/networking/mtu.rb +1 -1
  121. data/lib/facter/facts/windows/networking/netmask.rb +1 -1
  122. data/lib/facter/facts/windows/networking/netmask6.rb +1 -1
  123. data/lib/facter/facts/windows/networking/network.rb +1 -1
  124. data/lib/facter/facts/windows/networking/network6.rb +1 -1
  125. data/lib/facter/facts/windows/networking/primary.rb +1 -1
  126. data/lib/facter/facts/windows/networking/scope6.rb +1 -1
  127. data/lib/facter/facts/windows/scope6_interfaces.rb +1 -1
  128. data/lib/facter/framework/cli/cli.rb +16 -4
  129. data/lib/facter/framework/config/fact_groups.rb +13 -0
  130. data/lib/facter/os_hierarchy.json +3 -6
  131. data/lib/facter/resolvers/base_resolver.rb +1 -1
  132. data/lib/facter/resolvers/ec2.rb +2 -2
  133. data/lib/facter/resolvers/filesystems_resolver.rb +1 -1
  134. data/lib/facter/resolvers/linux/docker_uptime.rb +45 -0
  135. data/lib/facter/resolvers/linux/load_averages.rb +0 -1
  136. data/lib/facter/resolvers/load_averages.rb +2 -0
  137. data/lib/facter/resolvers/mountpoints_resolver.rb +42 -44
  138. data/lib/facter/resolvers/networking_resolver.rb +106 -0
  139. data/lib/facter/resolvers/solaris/disks.rb +51 -0
  140. data/lib/facter/resolvers/solaris/dmi.rb +57 -0
  141. data/lib/facter/resolvers/solaris/dmi_sparc.rb +47 -0
  142. data/lib/facter/resolvers/solaris/{filesystems_resolver.rb → filesystems.rb} +0 -0
  143. data/lib/facter/resolvers/solaris/{ipaddress_resolver.rb → ipaddress.rb} +0 -0
  144. data/lib/facter/resolvers/solaris/{networking_resolver.rb → networking.rb} +0 -0
  145. data/lib/facter/resolvers/solaris/os_release.rb +44 -0
  146. data/lib/facter/resolvers/solaris/zone.rb +51 -0
  147. data/lib/facter/resolvers/solaris/zone_name.rb +31 -0
  148. data/lib/facter/resolvers/uptime_resolver.rb +1 -27
  149. data/lib/facter/resolvers/utils/uptime_helper.rb +32 -0
  150. data/lib/facter/resolvers/windows/networking_resolver.rb +100 -98
  151. data/lib/facter/resolvers/zfs.rb +32 -0
  152. data/lib/facter/resolvers/zpool.rb +34 -0
  153. data/lib/facter/version.rb +1 -1
  154. metadata +77 -16
  155. data/lib/facter/facts/freebsd/solaris_zones/current.rb +0 -15
  156. data/lib/facter/facts/freebsd/solaris_zones/zone.rb +0 -15
  157. data/lib/facter/facts/solaris/solaris_zones/zone.rb +0 -62
  158. data/lib/facter/resolvers/macosx/networking_resolver.rb +0 -108
  159. data/lib/facter/resolvers/solaris/solaris_os_release_resolver.rb +0 -42
  160. data/lib/facter/resolvers/solaris/solaris_zone_name.rb +0 -28
  161. data/lib/facter/resolvers/solaris/zfs_resolver.rb +0 -34
  162. data/lib/facter/resolvers/solaris/zone_resolver.rb +0 -48
  163. data/lib/facter/resolvers/solaris/zpool_resolver.rb +0 -36
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ class Networking < BaseResolver
6
+ @semaphore = Mutex.new
7
+ @fact_list ||= {}
8
+
9
+ class << self
10
+ private
11
+
12
+ def post_resolve(fact_name)
13
+ @fact_list.fetch(fact_name) { read_facts(fact_name) }
14
+ end
15
+
16
+ def read_facts(fact_name)
17
+ primary_interface
18
+ interfaces_data
19
+ ::Resolvers::Utils::Networking.expand_main_bindings(@fact_list)
20
+ @fact_list[fact_name]
21
+ end
22
+
23
+ def primary_interface
24
+ result = Facter::Core::Execution.execute('route -n get default', logger: log)
25
+
26
+ @fact_list[:primary_interface] = result.match(/interface: (.+)/)&.captures&.first
27
+ end
28
+
29
+ def interfaces_data
30
+ command_response = Facter::Core::Execution.execute('ifconfig -a', logger: log)
31
+
32
+ clean_up_interfaces_response(command_response)
33
+ parse_interfaces_response(command_response)
34
+ end
35
+
36
+ def clean_up_interfaces_response(response)
37
+ # convert ip ranges into single ip. eg. 10.16.132.213 --> 10.16.132.213 is converted to 10.16.132.213
38
+ response.gsub!(/(\d+(\.\d+)*)\s+-->\s+\d+(\.\d+)*/, '\\1')
39
+ end
40
+
41
+ def parse_interfaces_response(response)
42
+ parsed_interfaces_data = {}
43
+ interfaces_data = Hash[*response.split(/^([A-Za-z0-9_]+): /)[1..-1]]
44
+
45
+ interfaces_data.each do |interface_name, raw_data|
46
+ parsed_interface_data = {}
47
+
48
+ extract_mtu(raw_data, parsed_interface_data)
49
+ extract_mac(raw_data, parsed_interface_data)
50
+ extract_dhcp(interface_name, raw_data, parsed_interface_data)
51
+ extract_ip_data(raw_data, parsed_interface_data)
52
+
53
+ parsed_interfaces_data[interface_name] = parsed_interface_data
54
+ end
55
+ @fact_list[:interfaces] = parsed_interfaces_data unless parsed_interfaces_data.empty?
56
+ end
57
+
58
+ def extract_mtu(raw_data, parsed_interface_data)
59
+ mtu = raw_data.match(/mtu\s+(\d+)/)&.captures&.first&.to_i
60
+ parsed_interface_data[:mtu] = mtu unless mtu.nil?
61
+ end
62
+
63
+ def extract_mac(raw_data, parsed_interface_data)
64
+ mac = raw_data.match(/(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/)&.captures&.first
65
+ parsed_interface_data[:mac] = mac unless mac.nil?
66
+ end
67
+
68
+ def extract_dhcp(interface_name, raw_data, parsed_interface_data)
69
+ return unless raw_data =~ /status:\s+active/
70
+
71
+ result = Facter::Core::Execution.execute("ipconfig getoption #{interface_name} " \
72
+ 'server_identifier', logger: log)
73
+
74
+ parsed_interface_data[:dhcp] = result.match(/^[\d.a-f:\s]+$/)&.to_s&.strip unless result.empty?
75
+ end
76
+
77
+ def extract_ip_data(raw_data, parsed_interface_data)
78
+ ip = extract_values(raw_data, /inet (\S+)/)
79
+ mask = extract_values(raw_data, /netmask (\S+)/).map { |val| val.hex.to_s(2).count('1') }
80
+
81
+ ip6 = extract_values(raw_data, /inet6 (\S+)/).map { |val| val.gsub(/%.+/, '') }
82
+ mask6 = extract_values(raw_data, /prefixlen (\S+)/)
83
+
84
+ parsed_interface_data[:bindings] = create_bindings(ip, mask) unless ip.empty?
85
+ parsed_interface_data[:bindings6] = create_bindings(ip6, mask6) unless ip6.empty?
86
+ end
87
+
88
+ def extract_values(data, regex)
89
+ results = []
90
+ data.scan(regex).flatten.each do |val|
91
+ results << val
92
+ end
93
+ results
94
+ end
95
+
96
+ def create_bindings(ips, masks)
97
+ bindings = []
98
+ ips.zip(masks).each do |ip, mask|
99
+ bindings << ::Resolvers::Utils::Networking.build_binding(ip, mask)
100
+ end
101
+ bindings
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Solaris
6
+ class Disks < BaseResolver
7
+ @semaphore = Mutex.new
8
+ @fact_list ||= {}
9
+
10
+ class << self
11
+ private
12
+
13
+ def post_resolve(fact_name)
14
+ @fact_list.fetch(fact_name) { read_disks_info(fact_name) }
15
+ end
16
+
17
+ def read_disks_info(fact_name)
18
+ return unless File.executable?('/usr/bin/kstat')
19
+
20
+ log.debug('loading disks info')
21
+
22
+ kstat_output = Facter::Core::Execution.execute('/usr/bin/kstat sderr', logger: log)
23
+ return if kstat_output.empty?
24
+
25
+ @fact_list[fact_name] = parse(kstat_output)
26
+ end
27
+
28
+ def parse(kstat_output)
29
+ disks = {}
30
+
31
+ names = kstat_output.scan(/name:\s+(\w+)/).flatten
32
+ products = kstat_output.scan(/Product\s+(.+)/).flatten
33
+ vendors = kstat_output.scan(/Vendor\s+(\w+)/).flatten
34
+ sizes = kstat_output.scan(/Size\s+(\w+)/).flatten
35
+
36
+ names.each_with_index do |name, index|
37
+ disk_size = sizes[index].to_i
38
+ disks[name] = {
39
+ product: products[index],
40
+ size: Facter::FactsUtils::UnitConverter.bytes_to_human_readable(disk_size),
41
+ size_bytes: disk_size,
42
+ vendor: vendors[index]
43
+ }
44
+ end
45
+ disks
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Solaris
6
+ class Dmi < BaseResolver
7
+ @semaphore = Mutex.new
8
+ @fact_list ||= {}
9
+
10
+ class << self
11
+ private
12
+
13
+ def post_resolve(fact_name)
14
+ @fact_list.fetch(fact_name) { read_facts(fact_name) }
15
+ end
16
+
17
+ SMBIOS_PARAMS = {
18
+ 'SMB_TYPE_BIOS' => {
19
+ bios_version: 'Version String: (.+)',
20
+ bios_vendor: 'Vendor: (.+)',
21
+ bios_release_date: 'Release Date: (.+)'
22
+ },
23
+ 'SMB_TYPE_SYSTEM' => {
24
+ manufacturer: 'Manufacturer: (.+)',
25
+ product_name: 'Product: (.+)',
26
+ serial_number: 'Serial Number: (.+)',
27
+ product_uuid: 'UUID: (.+)'
28
+ },
29
+ 'SMB_TYPE_CHASSIS' => {
30
+ chassis_asset_tag: 'Asset Tag: (.+)',
31
+ chassis_type: '(?:Chassis )?Type: (.+)'
32
+ }
33
+ }.freeze
34
+
35
+ def read_facts(fact_name)
36
+ param = SMBIOS_PARAMS.find { |_key, hash| hash[fact_name] }
37
+ return nil unless param
38
+
39
+ output = exec_smbios(param[0])
40
+ facts = param[1]
41
+ facts.each do |name, regx|
42
+ @fact_list[name] = output.match(/#{regx}/)&.captures&.first
43
+ end
44
+
45
+ @fact_list[fact_name]
46
+ end
47
+
48
+ def exec_smbios(args)
49
+ return unless File.executable?('/usr/sbin/smbios')
50
+
51
+ Facter::Core::Execution.execute("/usr/sbin/smbios -t #{args}", logger: log)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Solaris
6
+ class DmiSparc < BaseResolver
7
+ @semaphore = Mutex.new
8
+ @fact_list ||= {}
9
+
10
+ class << self
11
+ private
12
+
13
+ def post_resolve(fact_name)
14
+ @fact_list.fetch(fact_name) { read_facts(fact_name) }
15
+ end
16
+
17
+ def read_facts(fact_name)
18
+ output = exec_prtdiag
19
+ return unless output
20
+
21
+ matches = output.match(/System Configuration:\s+(.+?)\s+sun\d+\S+\s+(.+)/)&.captures
22
+
23
+ @fact_list[:manufacturer] = matches[0]&.strip
24
+ @fact_list[:product_name] = matches[1]&.strip
25
+
26
+ sneep = exec_sneep&.strip
27
+ @fact_list[:serial_number] = sneep
28
+
29
+ @fact_list[fact_name]
30
+ end
31
+
32
+ def exec_prtdiag
33
+ return unless File.executable?('/usr/sbin/prtdiag')
34
+
35
+ Facter::Core::Execution.execute('/usr/sbin/prtdiag', logger: log)
36
+ end
37
+
38
+ def exec_sneep
39
+ return unless File.executable?('/usr/sbin/sneep')
40
+
41
+ Facter::Core::Execution.execute('/usr/sbin/sneep', logger: log)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Solaris
6
+ class OsRelease < BaseResolver
7
+ @semaphore = Mutex.new
8
+ @fact_list ||= {}
9
+ @os_version_regex_patterns = ['Solaris \d+ \d+/\d+ s(\d+)[sx]?_u(\d+)wos_',
10
+ 'Solaris (\d+)[.](\d+)', 'Solaris (\d+)']
11
+ class << self
12
+ private
13
+
14
+ def post_resolve(fact_name)
15
+ @fact_list.fetch(fact_name) { build_release_facts(fact_name) }
16
+ end
17
+
18
+ def build_release_facts(fact_name)
19
+ result = Util::FileHelper.safe_read('/etc/release', nil)
20
+ return @fact_list[fact_name] = nil if result.nil?
21
+
22
+ @os_version_regex_patterns.each do |os_version_regex|
23
+ major, minor = search_for_os_version(/#{os_version_regex}/, result)
24
+ next unless major || minor
25
+
26
+ @fact_list[:major] = major
27
+ @fact_list[:minor] = minor
28
+ @fact_list[:full] = major == '10' ? major + '_u' + minor : major + '.' + minor
29
+ break
30
+ end
31
+ @fact_list[fact_name]
32
+ end
33
+
34
+ def search_for_os_version(regex_pattern, text)
35
+ result = text.match(regex_pattern)
36
+ major, minor = result.captures if result
37
+ minor = regex_pattern == /Solaris (\d+)/ ? '0' : minor
38
+ return [major, minor] if major && minor
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Solaris
6
+ class Zone < BaseResolver
7
+ @semaphore = Mutex.new
8
+ @fact_list ||= {}
9
+
10
+ class << self
11
+ private
12
+
13
+ def post_resolve(fact_name)
14
+ @fact_list.fetch(fact_name) { build_zone_fact(fact_name) }
15
+ end
16
+
17
+ def build_zone_fact(fact_name)
18
+ command = '/usr/sbin/zoneadm list -cp'
19
+ zone_adm_output = Facter::Core::Execution.execute(command, logger: log)
20
+
21
+ if zone_adm_output.empty?
22
+ log.debug("Command #{command} returned an empty result")
23
+ return
24
+ end
25
+ @fact_list[:zone] = create_zone_facts(zone_adm_output)
26
+
27
+ @fact_list[fact_name]
28
+ end
29
+
30
+ def create_zone_facts(zones_result)
31
+ zones_fact = []
32
+ zones_result.each_line do |zone_line|
33
+ id, name, status, path, uuid, brand, ip_type = zone_line.split(':')
34
+ zones_fact << {
35
+ brand: brand,
36
+ id: id,
37
+ iptype: ip_type.chomp,
38
+ name: name,
39
+ uuid: uuid,
40
+ status: status,
41
+ path: path
42
+
43
+ }
44
+ end
45
+ zones_fact
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Solaris
6
+ class ZoneName < BaseResolver
7
+ @semaphore = Mutex.new
8
+ @fact_list ||= {}
9
+
10
+ class << self
11
+ private
12
+
13
+ def post_resolve(fact_name)
14
+ @fact_list.fetch(fact_name) { build_current_zone_name_fact(fact_name) }
15
+ end
16
+
17
+ def build_current_zone_name_fact(fact_name)
18
+ zone_name_output = Facter::Core::Execution.execute('/bin/zonename', logger: log)
19
+
20
+ if zone_name_output.empty?
21
+ log.debug("Command #{command} returned an empty result")
22
+ return
23
+ end
24
+ @fact_list[:current_zone_name] = zone_name_output.chomp
25
+ @fact_list[fact_name]
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -23,33 +23,7 @@ module Facter
23
23
  def build_fact_list(seconds)
24
24
  return @fact_list[:uptime] = 'unknown' unless seconds
25
25
 
26
- uptime_hash = create_uptime_hash(seconds)
27
-
28
- @fact_list[:seconds] = uptime_hash[:seconds]
29
- @fact_list[:hours] = uptime_hash[:hours]
30
- @fact_list[:days] = uptime_hash[:days]
31
- @fact_list[:uptime] = uptime_hash[:uptime]
32
- end
33
-
34
- def create_uptime_hash(seconds)
35
- results = {}
36
- minutes = (seconds / 60) % 60
37
-
38
- results[:seconds] = seconds
39
- results[:hours] = seconds / (60 * 60)
40
- results[:days] = results[:hours] / 24
41
- results[:uptime] = build_uptime_text(results[:days], results[:hours], minutes)
42
-
43
- results
44
- end
45
-
46
- def build_uptime_text(days, hours, minutes)
47
- case days
48
- when 0 then "#{hours}:#{format('%<minutes>02d', minutes: minutes)} hours"
49
- when 1 then '1 day'
50
- else
51
- "#{days} days"
52
- end
26
+ @fact_list = Utils::UptimeHelper.create_uptime_hash(seconds)
53
27
  end
54
28
  end
55
29
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Utils
6
+ module UptimeHelper
7
+ class << self
8
+ def create_uptime_hash(seconds)
9
+ results = {}
10
+ minutes = (seconds / 60) % 60
11
+
12
+ results[:seconds] = seconds
13
+ results[:hours] = seconds / (60 * 60)
14
+ results[:days] = results[:hours] / 24
15
+ results[:uptime] = build_uptime_text(results[:days], results[:hours], minutes)
16
+
17
+ results
18
+ end
19
+
20
+ def build_uptime_text(days, hours, minutes)
21
+ case days
22
+ when 0 then "#{hours}:#{format('%<minutes>02d', minutes: minutes)} hours"
23
+ when 1 then '1 day'
24
+ else
25
+ "#{days} days"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end