facter 4.0.41 → 4.0.47
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/docs/generate.rb +32 -0
- data/lib/docs/template.erb +34 -0
- data/lib/facter.rb +110 -25
- data/lib/facter/config.rb +386 -0
- data/lib/facter/custom_facts/core/aggregate.rb +51 -17
- data/lib/facter/custom_facts/core/execution.rb +54 -38
- data/lib/facter/custom_facts/core/execution/base.rb +46 -40
- data/lib/facter/custom_facts/util/collection.rb +1 -2
- data/lib/facter/custom_facts/util/directory_loader.rb +1 -1
- data/lib/facter/custom_facts/util/fact.rb +19 -2
- data/lib/facter/custom_facts/util/loader.rb +1 -1
- data/lib/facter/custom_facts/util/parser.rb +17 -3
- data/lib/facter/custom_facts/util/resolution.rb +41 -12
- data/lib/facter/facts/aix/interfaces.rb +1 -0
- data/lib/facter/facts/aix/memory/swap/available.rb +1 -1
- data/lib/facter/facts/aix/memory/swap/available_bytes.rb +1 -1
- data/lib/facter/facts/aix/memory/swap/total.rb +1 -1
- data/lib/facter/facts/aix/memory/swap/total_bytes.rb +1 -1
- data/lib/facter/facts/aix/memory/swap/used.rb +1 -1
- data/lib/facter/facts/aix/memory/system/available.rb +1 -1
- data/lib/facter/facts/aix/memory/system/available_bytes.rb +1 -1
- data/lib/facter/facts/aix/memory/system/total.rb +1 -1
- data/lib/facter/facts/aix/memory/system/total_bytes.rb +1 -1
- data/lib/facter/facts/aix/memory/system/used.rb +1 -1
- data/lib/facter/facts/aix/processors/speed.rb +1 -1
- data/lib/facter/facts/bsd/processors/speed.rb +1 -1
- data/lib/facter/facts/freebsd/is_virtual.rb +25 -0
- data/lib/facter/facts/freebsd/memory/swap/available.rb +1 -1
- data/lib/facter/facts/freebsd/memory/swap/available_bytes.rb +1 -1
- data/lib/facter/facts/freebsd/memory/swap/total.rb +1 -1
- data/lib/facter/facts/freebsd/memory/swap/total_bytes.rb +1 -1
- data/lib/facter/facts/freebsd/memory/swap/used.rb +1 -1
- data/lib/facter/facts/freebsd/memory/system/available.rb +1 -1
- data/lib/facter/facts/freebsd/memory/system/available_bytes.rb +1 -1
- data/lib/facter/facts/freebsd/memory/system/total.rb +1 -1
- data/lib/facter/facts/freebsd/memory/system/total_bytes.rb +1 -1
- data/lib/facter/facts/freebsd/memory/system/used.rb +1 -1
- data/lib/facter/facts/freebsd/processors/speed.rb +1 -1
- data/lib/facter/facts/freebsd/virtual.rb +22 -0
- data/lib/facter/facts/linux/dhcp_servers.rb +1 -0
- data/lib/facter/facts/linux/ec2_metadata.rb +1 -1
- data/lib/facter/facts/linux/ec2_userdata.rb +1 -1
- data/lib/facter/facts/linux/hypervisors/kvm.rb +1 -1
- data/lib/facter/facts/linux/hypervisors/xen.rb +1 -1
- data/lib/facter/facts/linux/interfaces.rb +1 -0
- data/lib/facter/facts/linux/is_virtual.rb +2 -2
- data/lib/facter/facts/linux/memory/swap/available.rb +1 -1
- data/lib/facter/facts/linux/memory/swap/available_bytes.rb +1 -1
- data/lib/facter/facts/linux/memory/swap/total.rb +1 -1
- data/lib/facter/facts/linux/memory/swap/total_bytes.rb +1 -1
- data/lib/facter/facts/linux/memory/swap/used.rb +1 -1
- data/lib/facter/facts/linux/memory/system/available.rb +1 -1
- data/lib/facter/facts/linux/memory/system/available_bytes.rb +1 -1
- data/lib/facter/facts/linux/memory/system/total.rb +1 -1
- data/lib/facter/facts/linux/memory/system/total_bytes.rb +1 -1
- data/lib/facter/facts/linux/memory/system/used.rb +1 -1
- data/lib/facter/facts/linux/processors/speed.rb +1 -1
- data/lib/facter/facts/linux/virtual.rb +1 -1
- data/lib/facter/facts/macosx/dhcp_servers.rb +1 -0
- data/lib/facter/facts/macosx/interfaces.rb +1 -0
- data/lib/facter/facts/macosx/memory/swap/available.rb +1 -1
- data/lib/facter/facts/macosx/memory/swap/available_bytes.rb +1 -1
- data/lib/facter/facts/macosx/memory/swap/total.rb +1 -1
- data/lib/facter/facts/macosx/memory/swap/total_bytes.rb +1 -1
- data/lib/facter/facts/macosx/memory/swap/used.rb +1 -1
- data/lib/facter/facts/macosx/memory/system/available.rb +1 -1
- data/lib/facter/facts/macosx/memory/system/available_bytes.rb +1 -1
- data/lib/facter/facts/macosx/memory/system/total.rb +1 -1
- data/lib/facter/facts/macosx/memory/system/total_bytes.rb +1 -1
- data/lib/facter/facts/macosx/memory/system/used.rb +1 -1
- data/lib/facter/facts/macosx/processors/speed.rb +1 -1
- data/lib/facter/facts/rhel/os/release.rb +1 -1
- data/lib/facter/facts/solaris/dhcp_servers.rb +1 -0
- data/lib/facter/facts/solaris/hypervisors/ldom.rb +3 -0
- data/lib/facter/facts/solaris/interfaces.rb +1 -0
- data/lib/facter/facts/solaris/is_virtual.rb +2 -2
- data/lib/facter/facts/solaris/ldom.rb +34 -4
- data/lib/facter/facts/solaris/memory/swap/available.rb +1 -1
- data/lib/facter/facts/solaris/memory/swap/available_bytes.rb +1 -1
- data/lib/facter/facts/solaris/memory/swap/total.rb +1 -1
- data/lib/facter/facts/solaris/memory/swap/total_bytes.rb +1 -1
- data/lib/facter/facts/solaris/memory/swap/used.rb +1 -1
- data/lib/facter/facts/solaris/memory/system/available.rb +1 -1
- data/lib/facter/facts/solaris/memory/system/available_bytes.rb +1 -1
- data/lib/facter/facts/solaris/memory/system/total.rb +1 -1
- data/lib/facter/facts/solaris/memory/system/total_bytes.rb +1 -1
- data/lib/facter/facts/solaris/memory/system/used.rb +1 -1
- data/lib/facter/facts/solaris/processors/speed.rb +1 -1
- data/lib/facter/facts/solaris/virtual.rb +1 -1
- data/lib/facter/facts/solaris/zones.rb +1 -1
- data/lib/facter/facts/windows/dhcp_servers.rb +1 -0
- data/lib/facter/facts/windows/interfaces.rb +1 -0
- data/lib/facter/facts/windows/memory/system/available.rb +1 -1
- data/lib/facter/facts/windows/memory/system/available_bytes.rb +1 -1
- data/lib/facter/facts/windows/memory/system/total.rb +1 -1
- data/lib/facter/facts/windows/memory/system/total_bytes.rb +1 -1
- data/lib/facter/facts/windows/memory/system/used.rb +1 -1
- data/lib/facter/facts/windows/os/release.rb +1 -1
- data/lib/facter/framework/benchmarking/timer.rb +4 -2
- data/lib/facter/framework/cli/cli.rb +20 -6
- data/lib/facter/framework/config/fact_groups.rb +10 -8
- data/lib/facter/framework/core/cache_manager.rb +79 -29
- data/lib/facter/framework/core/fact/internal/core_fact.rb +6 -1
- data/lib/facter/framework/core/fact/internal/internal_fact_manager.rb +38 -4
- data/lib/facter/framework/core/fact_augmenter.rb +1 -1
- data/lib/facter/framework/core/fact_loaders/external_fact_loader.rb +4 -2
- data/lib/facter/framework/core/fact_loaders/fact_loader.rb +17 -1
- data/lib/facter/framework/core/fact_manager.rb +15 -3
- data/lib/facter/framework/core/file_loader.rb +6 -2
- data/lib/facter/framework/core/options/config_file_options.rb +16 -5
- data/lib/facter/framework/core/options/option_store.rb +40 -20
- data/lib/facter/framework/detector/os_hierarchy.rb +5 -9
- data/lib/facter/framework/logging/logger.rb +3 -3
- data/lib/facter/models/fact_collection.rb +11 -1
- data/lib/facter/models/loaded_fact.rb +2 -1
- data/lib/facter/resolvers/aio_agent_version.rb +2 -2
- data/lib/facter/resolvers/aix/architecture_resolver.rb +19 -4
- data/lib/facter/resolvers/aix/disks.rb +6 -5
- data/lib/facter/resolvers/aix/filesystem_resolver.rb +2 -2
- data/lib/facter/resolvers/aix/hardware_resolver.rb +4 -3
- data/lib/facter/resolvers/aix/load_averages_resolver.rb +2 -1
- data/lib/facter/resolvers/aix/memory.rb +4 -3
- data/lib/facter/resolvers/aix/mountpoints.rb +6 -5
- data/lib/facter/resolvers/aix/networking_resolver.rb +4 -3
- data/lib/facter/resolvers/aix/nim.rb +1 -1
- data/lib/facter/resolvers/aix/os_level.rb +2 -2
- data/lib/facter/resolvers/aix/partitions.rb +7 -6
- data/lib/facter/resolvers/aix/processors.rb +5 -4
- data/lib/facter/resolvers/aix/serialnumber.rb +2 -2
- data/lib/facter/resolvers/augeas_resolver.rb +8 -2
- data/lib/facter/resolvers/base_resolver.rb +14 -4
- data/lib/facter/resolvers/bsd/processors.rb +13 -8
- data/lib/facter/resolvers/cloud.rb +2 -2
- data/lib/facter/resolvers/containers.rb +5 -4
- data/lib/facter/resolvers/debian_version.rb +2 -2
- data/lib/facter/resolvers/disk_resolver.rb +17 -6
- data/lib/facter/resolvers/dmi_decode.rb +1 -1
- data/lib/facter/resolvers/dmi_resolver.rb +5 -4
- data/lib/facter/resolvers/ec2.rb +5 -2
- data/lib/facter/resolvers/eos_release_resolver.rb +2 -2
- data/lib/facter/resolvers/facterversion_resolver.rb +1 -1
- data/lib/facter/resolvers/filesystems_resolver.rb +5 -2
- data/lib/facter/resolvers/fips_enabled_resolver.rb +5 -2
- data/lib/facter/resolvers/freebsd/dmi_resolver.rb +1 -1
- data/lib/facter/resolvers/freebsd/freebsd_version_resolver.rb +9 -7
- data/lib/facter/resolvers/freebsd/geom_resolver.rb +15 -22
- data/lib/facter/resolvers/freebsd/processors.rb +13 -8
- data/lib/facter/resolvers/freebsd/swap_memory_resolver.rb +5 -3
- data/lib/facter/resolvers/freebsd/system_memory_resolver.rb +4 -2
- data/lib/facter/resolvers/freebsd/virtual_resolver.rb +45 -0
- data/lib/facter/resolvers/gce.rb +3 -2
- data/lib/facter/resolvers/hostname_resolver.rb +69 -21
- data/lib/facter/resolvers/identity_resolver.rb +2 -1
- data/lib/facter/resolvers/linux/docker_uptime.rb +3 -2
- data/lib/facter/resolvers/linux/load_averages.rb +3 -2
- data/lib/facter/resolvers/load_averages.rb +5 -3
- data/lib/facter/resolvers/lpar_resolver.rb +1 -1
- data/lib/facter/resolvers/lsb_release_resolver.rb +1 -1
- data/lib/facter/resolvers/lspci.rb +1 -1
- data/lib/facter/resolvers/macosx/dmi_resolver.rb +1 -1
- data/lib/facter/resolvers/macosx/filesystems_resolver.rb +1 -1
- data/lib/facter/resolvers/macosx/load_averages_resolver.rb +2 -1
- data/lib/facter/resolvers/macosx/mountpoints_resolver.rb +9 -8
- data/lib/facter/resolvers/macosx/processor_resolver.rb +2 -1
- data/lib/facter/resolvers/macosx/swap_memory_resolver.rb +2 -1
- data/lib/facter/resolvers/macosx/system_memory_resolver.rb +2 -1
- data/lib/facter/resolvers/macosx/system_profiler_resolver.rb +4 -6
- data/lib/facter/resolvers/memory_resolver.rb +16 -16
- data/lib/facter/resolvers/mountpoints_resolver.rb +56 -25
- data/lib/facter/resolvers/networking_linux_resolver.rb +188 -83
- data/lib/facter/resolvers/networking_resolver.rb +9 -6
- data/lib/facter/resolvers/open_vz.rb +2 -4
- data/lib/facter/resolvers/os_release_resolver.rb +2 -2
- data/lib/facter/resolvers/partitions.rb +67 -63
- data/lib/facter/resolvers/path_resolver.rb +1 -1
- data/lib/facter/resolvers/processors_resolver.rb +10 -3
- data/lib/facter/resolvers/redhat_release_resolver.rb +2 -2
- data/lib/facter/resolvers/ruby_resolver.rb +1 -1
- data/lib/facter/resolvers/selinux_resolver.rb +4 -4
- data/lib/facter/resolvers/solaris/disks.rb +2 -2
- data/lib/facter/resolvers/solaris/dmi.rb +3 -1
- data/lib/facter/resolvers/solaris/dmi_sparc.rb +1 -1
- data/lib/facter/resolvers/solaris/filesystems.rb +1 -1
- data/lib/facter/resolvers/solaris/ipaddress.rb +2 -1
- data/lib/facter/resolvers/solaris/ldom.rb +1 -3
- data/lib/facter/resolvers/solaris/memory.rb +4 -3
- data/lib/facter/resolvers/solaris/mountpoints.rb +61 -0
- data/lib/facter/resolvers/solaris/networking.rb +51 -44
- data/lib/facter/resolvers/solaris/os_release.rb +7 -5
- data/lib/facter/resolvers/solaris/processors.rb +2 -1
- data/lib/facter/resolvers/solaris/zone.rb +1 -1
- data/lib/facter/resolvers/solaris/zone_name.rb +1 -1
- data/lib/facter/resolvers/ssh_resolver.rb +11 -7
- data/lib/facter/resolvers/suse_release_resolver.rb +2 -2
- data/lib/facter/resolvers/sw_vers_resolver.rb +2 -2
- data/lib/facter/resolvers/timezone_resolver.rb +1 -1
- data/lib/facter/resolvers/uname_resolver.rb +1 -1
- data/lib/facter/resolvers/uptime_resolver.rb +3 -3
- data/lib/facter/resolvers/virt_what.rb +1 -1
- data/lib/facter/resolvers/vmware.rb +1 -1
- data/lib/facter/resolvers/windows/aio_agent_version.rb +2 -2
- data/lib/facter/resolvers/windows/dmi_bios_resolver.rb +2 -2
- data/lib/facter/resolvers/windows/dmi_computersystem_resolver.rb +2 -2
- data/lib/facter/resolvers/windows/fips_resolver.rb +2 -1
- data/lib/facter/resolvers/windows/hardware_architecture_resolver.rb +2 -1
- data/lib/facter/resolvers/windows/identity_resolver.rb +2 -1
- data/lib/facter/resolvers/windows/kernel_resolver.rb +3 -1
- data/lib/facter/resolvers/windows/memory_resolver.rb +7 -1
- data/lib/facter/resolvers/windows/netkvm_resolver.rb +2 -1
- data/lib/facter/resolvers/windows/networking_resolver.rb +5 -4
- data/lib/facter/resolvers/windows/processors_resolver.rb +3 -2
- data/lib/facter/resolvers/windows/product_release_resolver.rb +2 -1
- data/lib/facter/resolvers/windows/ssh.rb +5 -3
- data/lib/facter/resolvers/windows/system32_resolver.rb +3 -1
- data/lib/facter/resolvers/windows/uptime_resolver.rb +3 -2
- data/lib/facter/resolvers/windows/virtualization_resolver.rb +3 -2
- data/lib/facter/resolvers/windows/win_os_description_resolver.rb +4 -2
- data/lib/facter/resolvers/wpar_resolver.rb +1 -1
- data/lib/facter/resolvers/xen.rb +2 -2
- data/lib/facter/resolvers/zfs.rb +2 -1
- data/lib/facter/resolvers/zpool.rb +2 -1
- data/lib/facter/util/aix/info_extractor.rb +24 -0
- data/lib/facter/util/aix/odm_query.rb +46 -0
- data/lib/facter/util/api_debugger.rb +33 -29
- data/lib/facter/util/facts/facts_utils.rb +14 -0
- data/lib/facter/util/facts/unit_converter.rb +61 -0
- data/lib/facter/util/facts/uptime_parser.rb +128 -0
- data/lib/facter/util/facts/virtual_detector.rb +90 -0
- data/lib/facter/util/facts/windows_release_finder.rb +55 -0
- data/lib/facter/{resolvers/macosx/utils → util/macosx}/system_profile_executor.rb +1 -1
- data/lib/facter/util/resolvers/aws_token.rb +37 -0
- data/lib/facter/{resolvers/utils → util/resolvers}/ffi/load_averages.rb +2 -2
- data/lib/facter/util/resolvers/filesystem_helper.rb +47 -0
- data/lib/facter/util/resolvers/fingerprint.rb +15 -0
- data/lib/facter/{resolvers/utils → util/resolvers}/http.rb +17 -10
- data/lib/facter/util/resolvers/networking.rb +90 -0
- data/lib/facter/util/resolvers/networking/dhcp.rb +21 -0
- data/lib/facter/util/resolvers/networking/networking.rb +109 -0
- data/lib/facter/util/resolvers/networking/primary_interface.rb +82 -0
- data/lib/facter/util/resolvers/ssh.rb +17 -0
- data/lib/facter/util/resolvers/ssh_helper.rb +31 -0
- data/lib/facter/{resolvers/utils → util/resolvers}/uptime_helper.rb +2 -2
- data/lib/facter/{framework/utils → util}/utils.rb +0 -0
- data/lib/facter/util/windows/win32ole.rb +30 -0
- data/lib/facter/version.rb +1 -1
- metadata +33 -44
- data/lib/facter/fact_groups.conf +0 -308
- data/lib/facter/facts/aix/puppet_version.rb +0 -15
- data/lib/facter/facts/freebsd/puppet_version.rb +0 -15
- data/lib/facter/facts/linux/puppet_version.rb +0 -15
- data/lib/facter/facts/macosx/puppet_version.rb +0 -15
- data/lib/facter/facts/solaris/puppet_version.rb +0 -15
- data/lib/facter/facts/windows/puppet_version.rb +0 -15
- data/lib/facter/facts_utils/facts_utils.rb +0 -12
- data/lib/facter/facts_utils/unit_converter.rb +0 -59
- data/lib/facter/facts_utils/uptime_parser.rb +0 -124
- data/lib/facter/facts_utils/virtual_detector.rb +0 -78
- data/lib/facter/facts_utils/windows_release_finder.rb +0 -51
- data/lib/facter/os_hierarchy.json +0 -36
- data/lib/facter/resolvers/aix/utils/info_extractor.rb +0 -20
- data/lib/facter/resolvers/aix/utils/odm_query.rb +0 -42
- data/lib/facter/resolvers/puppet_version_resolver.rb +0 -26
- data/lib/facter/resolvers/utils/filesystem_helper.rb +0 -43
- data/lib/facter/resolvers/utils/fingerprint.rb +0 -11
- data/lib/facter/resolvers/utils/networking.rb +0 -86
- data/lib/facter/resolvers/utils/ssh.rb +0 -13
- data/lib/facter/resolvers/utils/ssh_helper.rb +0 -27
- data/lib/facter/resolvers/windows/utils/win32ole.rb +0 -24
@@ -3,20 +3,37 @@
|
|
3
3
|
module Facter
|
4
4
|
module Resolvers
|
5
5
|
class Mountpoints < BaseResolver
|
6
|
-
include Facter::FilesystemHelper
|
7
|
-
|
6
|
+
include Facter::Util::Resolvers::FilesystemHelper
|
7
|
+
|
8
|
+
init_resolver
|
9
|
+
|
8
10
|
@log = Facter::Log.new(self)
|
11
|
+
|
9
12
|
class << self
|
10
13
|
private
|
11
14
|
|
12
15
|
def post_resolve(fact_name)
|
13
|
-
@fact_list.fetch(fact_name) { read_mounts }
|
16
|
+
@fact_list.fetch(fact_name) { read_mounts(fact_name) }
|
14
17
|
end
|
15
18
|
|
16
19
|
def root_device
|
17
|
-
cmdline = Util::FileHelper.safe_read('/proc/cmdline')
|
20
|
+
cmdline = Facter::Util::FileHelper.safe_read('/proc/cmdline')
|
18
21
|
match = cmdline.match(/root=([^\s]+)/)
|
19
|
-
match&.captures&.first
|
22
|
+
root = match&.captures&.first
|
23
|
+
|
24
|
+
if !root.nil? && root.include?('=')
|
25
|
+
# We are dealing with the PARTUUID of the partition. Need to extract partition path.
|
26
|
+
root_partition_path = convert_partuuid_to_path(root)
|
27
|
+
root = root_partition_path unless root_partition_path.nil?
|
28
|
+
end
|
29
|
+
root
|
30
|
+
end
|
31
|
+
|
32
|
+
def convert_partuuid_to_path(root)
|
33
|
+
blkid_content = Facter::Core::Execution.execute('blkid', logger: log)
|
34
|
+
partuuid = root.split('=').last
|
35
|
+
match = blkid_content.match(/(.+)#{partuuid}/)
|
36
|
+
match&.captures&.first&.split(':')&.first
|
20
37
|
end
|
21
38
|
|
22
39
|
def compute_device(device)
|
@@ -26,32 +43,46 @@ module Facter
|
|
26
43
|
device
|
27
44
|
end
|
28
45
|
|
29
|
-
def read_mounts
|
46
|
+
def read_mounts(fact_name)
|
30
47
|
mounts = []
|
31
|
-
FilesystemHelper.read_mountpoints.each do |
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
48
|
+
Facter::Util::Resolvers::FilesystemHelper.read_mountpoints.each do |file_system|
|
49
|
+
mount = {}
|
50
|
+
get_mount_data(file_system, mount)
|
51
|
+
|
52
|
+
next if mount[:path] =~ %r{^/(proc|sys)} && mount[:filesystem] != 'tmpfs' || mount[:filesystem] == 'autofs'
|
53
|
+
|
54
|
+
get_mount_sizes(mount)
|
55
|
+
mounts << mount
|
56
|
+
end
|
36
57
|
|
37
|
-
|
58
|
+
@fact_list[:mountpoints] = mounts
|
59
|
+
@fact_list[fact_name]
|
60
|
+
end
|
38
61
|
|
39
|
-
|
40
|
-
|
41
|
-
|
62
|
+
def get_mount_data(file_system, mount)
|
63
|
+
mount[:device] = compute_device(file_system.name)
|
64
|
+
mount[:filesystem] = file_system.mount_type
|
65
|
+
mount[:path] = file_system.mount_point
|
66
|
+
mount[:options] = file_system.options.split(',').map(&:strip)
|
67
|
+
end
|
42
68
|
|
43
|
-
|
44
|
-
|
45
|
-
capacity = FilesystemHelper.compute_capacity(used_bytes, total_bytes)
|
69
|
+
def get_mount_sizes(mount)
|
70
|
+
stats = Facter::Util::Resolvers::FilesystemHelper.read_mountpoint_stats(mount[:path])
|
46
71
|
|
47
|
-
|
48
|
-
available = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(available_bytes)
|
49
|
-
used = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(used_bytes)
|
72
|
+
get_bytes_data(mount, stats)
|
50
73
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
74
|
+
total_bytes = mount[:used_bytes] + mount[:available_bytes]
|
75
|
+
mount[:capacity] = Facter::Util::Resolvers::FilesystemHelper.compute_capacity(mount[:used_bytes], total_bytes)
|
76
|
+
|
77
|
+
mount[:size] = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(mount[:size_bytes])
|
78
|
+
mount[:available] = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(mount[:available_bytes])
|
79
|
+
mount[:used] = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(mount[:used_bytes])
|
80
|
+
end
|
81
|
+
|
82
|
+
def get_bytes_data(mount, stats)
|
83
|
+
mount[:size_bytes] = stats.bytes_total.abs
|
84
|
+
mount[:available_bytes] = stats.bytes_available.abs
|
85
|
+
mount[:used_bytes] = stats.bytes_used.abs
|
55
86
|
end
|
56
87
|
end
|
57
88
|
end
|
@@ -3,8 +3,18 @@
|
|
3
3
|
module Facter
|
4
4
|
module Resolvers
|
5
5
|
class NetworkingLinux < BaseResolver
|
6
|
-
|
6
|
+
init_resolver
|
7
|
+
|
7
8
|
DIRS = ['/var/lib/dhclient/', '/var/lib/dhcp/', '/var/lib/dhcp3/', '/var/lib/NetworkManager/', '/var/db/'].freeze
|
9
|
+
ROUTE_TYPES = %w[anycast
|
10
|
+
unicast
|
11
|
+
broadcast
|
12
|
+
local
|
13
|
+
nat
|
14
|
+
unreachable
|
15
|
+
prohibit
|
16
|
+
blackhole
|
17
|
+
throw].freeze
|
8
18
|
|
9
19
|
class << self
|
10
20
|
private
|
@@ -16,52 +26,188 @@ module Facter
|
|
16
26
|
end
|
17
27
|
|
18
28
|
def retrieve_network_info(fact_name)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
::Resolvers::Utils::Networking.expand_main_bindings(@fact_list)
|
29
|
+
mtu_and_indexes = interfaces_mtu_and_index
|
30
|
+
retrieve_interface_info(mtu_and_indexes)
|
31
|
+
add_info_from_routing_table
|
32
|
+
retrieve_primary_interface
|
33
|
+
Facter::Util::Resolvers::Networking.expand_main_bindings(@fact_list)
|
25
34
|
@fact_list[fact_name]
|
26
35
|
end
|
27
36
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
37
|
+
def interfaces_mtu_and_index
|
38
|
+
mtu_and_indexes = {}
|
39
|
+
output = Facter::Core::Execution.execute("ip link show", logger: log)
|
40
|
+
output.each_line do |line|
|
41
|
+
next unless line.include?('mtu')
|
42
|
+
|
43
|
+
mtu = line.match(/mtu (\d+)/)&.captures&.first&.to_i
|
44
|
+
index_tokens = line.split(':')
|
45
|
+
index = index_tokens[0].strip
|
46
|
+
# vlans are displayed as <vlan_name>@<physical_interface>
|
47
|
+
name = index_tokens[1].split('@').first.strip
|
48
|
+
mtu_and_indexes[name] = [index, mtu]
|
34
49
|
end
|
50
|
+
mtu_and_indexes
|
35
51
|
end
|
36
52
|
|
37
|
-
def retrieve_interface_info
|
38
|
-
|
39
|
-
output = Facter::Core::Execution.execute('ip -o address', logger: log)
|
40
|
-
log.debug("ip -o address result is:\n#{output}")
|
41
|
-
|
53
|
+
def retrieve_interface_info(mtu_and_indexes)
|
54
|
+
require 'socket'
|
42
55
|
interfaces = {}
|
56
|
+
Socket.getifaddrs.each do |interface|
|
57
|
+
interfaces[interface.name] = {} if interfaces[interface.name].nil?
|
58
|
+
|
59
|
+
if interfaces[interface.name][:mac].nil?
|
60
|
+
mac = extract_mac_address(interface)
|
61
|
+
interfaces[interface.name][:mac] = mac if mac
|
62
|
+
end
|
43
63
|
|
44
|
-
|
45
|
-
|
64
|
+
if interfaces[interface.name][:mtu].nil?
|
65
|
+
mtu = mtu_and_indexes.dig(interface.name, 1)
|
66
|
+
interfaces[interface.name][:mtu] = mtu unless mtu.nil?
|
67
|
+
end
|
46
68
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
69
|
+
if !interface.addr.nil? && !interface.netmask.nil?
|
70
|
+
begin
|
71
|
+
# ipv6 ips are retrieved as <ip>%<interface_name>
|
72
|
+
ip = interface.addr.ip_address.split('%').first if interface.addr.ip?
|
73
|
+
netmask = interface.netmask.ip_address
|
74
|
+
add_binding(interfaces, interface.name, ip, netmask, interface.addr.ipv4?)
|
75
|
+
rescue SocketError => e
|
76
|
+
end
|
77
|
+
end
|
78
|
+
find_dhcp!(interface.name, mtu_and_indexes, interfaces)
|
52
79
|
end
|
53
80
|
|
54
81
|
@fact_list[:interfaces] = interfaces
|
55
82
|
end
|
56
83
|
|
57
|
-
def
|
58
|
-
|
59
|
-
|
84
|
+
def extract_mac_address(interface)
|
85
|
+
mac = get_bonded_interface_mac(interface.name)
|
86
|
+
begin
|
87
|
+
if mac.nil?
|
88
|
+
if Socket.const_defined? :PF_LINK
|
89
|
+
mac = interface.addr&.getnameinfo&.first #sometimes it returns localhost, ip but mac also
|
90
|
+
elsif Socket.const_defined? :PF_PACKET
|
91
|
+
return if interface.addr.nil? || interface.addr.inspect_sockaddr.nil?
|
92
|
+
|
93
|
+
mac = interface.addr&.inspect_sockaddr[/hwaddr=([\h:]+)/, 1]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
rescue StandardError => e
|
97
|
+
log.debug("Could not read mac, got #{e}")
|
98
|
+
end
|
99
|
+
mac if !mac.nil? && mac != '00:00:00:00:00:00' && mac =~ /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/
|
100
|
+
end
|
101
|
+
|
102
|
+
def get_bonded_interface_mac(interface_name)
|
103
|
+
master = get_bond_master(interface_name)
|
104
|
+
return unless master
|
105
|
+
|
106
|
+
output = Facter::Util::FileHelper.safe_read("/proc/net/bonding/#{master}", nil)
|
107
|
+
return unless output
|
108
|
+
|
109
|
+
right_block = false
|
110
|
+
output.each_line do |line|
|
111
|
+
if line.strip == "Slave Interface: #{interface_name}"
|
112
|
+
right_block = true
|
113
|
+
elsif line.include? 'Slave Interface'
|
114
|
+
right_block = false
|
115
|
+
end
|
116
|
+
return Regexp.last_match(1) if right_block && line =~ /Permanent HW addr: (\S*)/
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def get_bond_master(interface_name)
|
121
|
+
content = Facter::Core::Execution.execute("ip link show #{interface_name}", logger: log)
|
122
|
+
master = content.match(/master (\S*) /)
|
123
|
+
return master[1] if master
|
124
|
+
|
125
|
+
nil
|
126
|
+
end
|
127
|
+
|
128
|
+
def add_binding(interfaces, name, ip, netmask, ip_v4_type)
|
129
|
+
binding = Facter::Util::Resolvers::Networking.build_binding(ip, netmask)
|
130
|
+
return if binding.nil?
|
131
|
+
|
132
|
+
log.debug("Adding to interface #{name}, binding:\n#{binding}")
|
133
|
+
binding_key = ip_v4_type == true ? :bindings : :bindings6
|
134
|
+
interfaces[name][binding_key] = [] if interfaces[name][binding_key].nil?
|
135
|
+
interfaces[name][binding_key] << binding
|
136
|
+
end
|
137
|
+
|
138
|
+
def add_info_from_routing_table
|
139
|
+
routes4, routes6 = read_routing_table
|
140
|
+
compare_ips(routes4, :bindings)
|
141
|
+
compare_ips(routes6, :bindings6)
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
def read_routing_table
|
146
|
+
ipv4_output = Facter::Core::Execution.execute('ip route show', logger: log)
|
147
|
+
ipv6_output = Facter::Core::Execution.execute('ip -6 route show', logger: log)
|
148
|
+
routes4 = parse_routes(ipv4_output, 'ipv4')
|
149
|
+
routes6 = parse_routes(ipv6_output, 'ipv6')
|
150
|
+
[routes4, routes6]
|
151
|
+
end
|
152
|
+
|
153
|
+
def parse_routes(output, family)
|
154
|
+
routes = []
|
155
|
+
output.each_line do |line|
|
156
|
+
parts = line.split(' ').compact
|
157
|
+
next if parts.include?('linkdown')
|
158
|
+
|
159
|
+
route_type = parts[0]
|
160
|
+
parts.delete_at(0) if ROUTE_TYPES.include?(route_type)
|
161
|
+
next if family == 'ipv6' && !parts[0].include?(':')
|
162
|
+
|
163
|
+
route = construct_route(parts)
|
164
|
+
routes << route unless route[:ip].nil?
|
165
|
+
end
|
166
|
+
routes.uniq
|
167
|
+
end
|
168
|
+
|
169
|
+
def construct_route(parts)
|
170
|
+
route = {}
|
171
|
+
dev_index = parts.find_index { |elem| elem == 'dev' }
|
172
|
+
src_index = parts.find_index { |elem| elem == 'src' }
|
173
|
+
route[:interface] = parts[dev_index + 1] if dev_index
|
174
|
+
route[:ip] = parts[src_index + 1] if src_index
|
175
|
+
route
|
176
|
+
end
|
60
177
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
178
|
+
def compare_ips(routes, binding_key)
|
179
|
+
routes.each do |route|
|
180
|
+
# TODO we should simplify this
|
181
|
+
if @fact_list[:interfaces].key?(route[:interface])
|
182
|
+
if @fact_list[:interfaces][route[:interface]][binding_key].nil?
|
183
|
+
@fact_list[:interfaces][route[:interface]][binding_key] = [{ address: route[:ip] }]
|
184
|
+
elsif @fact_list[:interfaces][route[:interface]][binding_key].none? { |binding| binding[:address] == route[:ip] }
|
185
|
+
@fact_list[:interfaces][route[:interface]][binding_key] << { address: route[:ip] }
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def find_dhcp!(interface_name, interface_indexes, interfaces)
|
192
|
+
return if !interfaces[interface_name] || interfaces[interface_name][:dhcp]
|
193
|
+
|
194
|
+
log.debug("Get DHCP for interface #{interface_name}")
|
195
|
+
unless interface_indexes[interface_name].nil?
|
196
|
+
index = interface_indexes[interface_name][0]
|
197
|
+
file_content = Facter::Util::FileHelper.safe_read("/run/systemd/netif/leases/#{index}", nil)
|
198
|
+
dhcp = file_content.match(/SERVER_ADDRESS=(.*)/) if file_content
|
199
|
+
if dhcp
|
200
|
+
interfaces[interface_name][:dhcp] = dhcp[1]
|
201
|
+
else
|
202
|
+
alternate_dhcp = retrieve_from_other_directories(interface_name)
|
203
|
+
interfaces[interface_name][:dhcp] = alternate_dhcp if alternate_dhcp
|
204
|
+
end
|
205
|
+
end
|
206
|
+
return unless interfaces[interface_name][:dhcp].nil?
|
207
|
+
|
208
|
+
output = Facter::Core::Execution.execute("dhcpcd -U #{interface_name}", logger: log)
|
209
|
+
result = output.match(/dhcp_server_identifier='(.*)'/)&.captures&.first
|
210
|
+
interfaces[interface_name][:dhcp] = result if result
|
65
211
|
end
|
66
212
|
|
67
213
|
def retrieve_from_other_directories(interface_name)
|
@@ -72,10 +218,11 @@ module Facter
|
|
72
218
|
next if lease_files.empty?
|
73
219
|
|
74
220
|
lease_files.select do |file|
|
75
|
-
content = Util::FileHelper.safe_read("#{dir}#{file}", nil)
|
221
|
+
content = Facter::Util::FileHelper.safe_read("#{dir}#{file}", nil)
|
76
222
|
next unless content =~ /interface.*#{interface_name}/
|
77
223
|
|
78
|
-
|
224
|
+
dhcp = content.match(/dhcp-server-identifier ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/)
|
225
|
+
return dhcp[1] if dhcp
|
79
226
|
end
|
80
227
|
end
|
81
228
|
return unless File.readable?('/var/lib/NetworkManager/')
|
@@ -88,7 +235,7 @@ module Facter
|
|
88
235
|
lease_file = files.find { |file| file =~ /internal.*#{interface_name}\.lease/ }
|
89
236
|
return unless lease_file
|
90
237
|
|
91
|
-
dhcp = Util::FileHelper.safe_read("/var/lib/NetworkManager/#{lease_file}", nil)
|
238
|
+
dhcp = Facter::Util::FileHelper.safe_read("/var/lib/NetworkManager/#{lease_file}", nil)
|
92
239
|
|
93
240
|
return unless dhcp
|
94
241
|
|
@@ -96,57 +243,15 @@ module Facter
|
|
96
243
|
dhcp[1] if dhcp
|
97
244
|
end
|
98
245
|
|
99
|
-
def
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
log.debug("interface_name = #{interface_name}\n" \
|
106
|
-
"ip4_address = #{ip4_address}\n" \
|
107
|
-
"ip4_mask_length = #{ip4_mask_length}")
|
108
|
-
|
109
|
-
binding = ::Resolvers::Utils::Networking.build_binding(ip4_address, ip4_mask_length)
|
110
|
-
build_network_info_structure!(network_info, interface_name, :bindings)
|
246
|
+
def retrieve_primary_interface
|
247
|
+
primary_helper = Facter::Util::Resolvers::Networking::PrimaryInterface
|
248
|
+
primary_interface = primary_helper.read_from_proc_route
|
249
|
+
primary_interface ||= primary_helper.read_from_ip_route
|
250
|
+
primary_interface ||= primary_helper.find_in_interfaces(@fact_list[:interfaces])
|
111
251
|
|
112
|
-
|
252
|
+
@fact_list[:primary_interface] = primary_interface
|
113
253
|
end
|
114
254
|
|
115
|
-
def retrieve_name_and_ip_info(tokens)
|
116
|
-
interface_name = tokens[1]
|
117
|
-
ip_info = tokens[3].split('/')
|
118
|
-
ip_address = ip_info[0]
|
119
|
-
ip_mask_length = ip_info[1]
|
120
|
-
|
121
|
-
[interface_name, ip_address, ip_mask_length]
|
122
|
-
end
|
123
|
-
|
124
|
-
def fill_io_v6_info!(ip_tokens, network_info)
|
125
|
-
return unless ip_tokens[2].casecmp('inet6').zero?
|
126
|
-
|
127
|
-
interface_name, ip6_address, ip6_mask_length = retrieve_name_and_ip_info(ip_tokens)
|
128
|
-
|
129
|
-
binding = ::Resolvers::Utils::Networking.build_binding(ip6_address, ip6_mask_length)
|
130
|
-
|
131
|
-
build_network_info_structure!(network_info, interface_name, :bindings6)
|
132
|
-
|
133
|
-
network_info[interface_name][:scope6] ||= ip_tokens[5]
|
134
|
-
network_info[interface_name][:bindings6] << binding
|
135
|
-
end
|
136
|
-
|
137
|
-
def retrieve_default_interface
|
138
|
-
output = Facter::Core::Execution.execute('ip route get 1', logger: log)
|
139
|
-
|
140
|
-
ip_route_tokens = output.each_line.first.strip.split(' ')
|
141
|
-
default_interface = ip_route_tokens[4]
|
142
|
-
|
143
|
-
@fact_list[:primary_interface] = default_interface
|
144
|
-
end
|
145
|
-
|
146
|
-
def build_network_info_structure!(network_info, interface_name, binding)
|
147
|
-
network_info[interface_name] = {} unless network_info.dig(interface_name)
|
148
|
-
network_info[interface_name][binding] = [] unless network_info.dig(interface_name, binding)
|
149
|
-
end
|
150
255
|
end
|
151
256
|
end
|
152
257
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Facter
|
4
4
|
module Resolvers
|
5
5
|
class Networking < BaseResolver
|
6
|
-
|
6
|
+
init_resolver
|
7
7
|
|
8
8
|
class << self
|
9
9
|
private
|
@@ -13,16 +13,19 @@ module Facter
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def read_facts(fact_name)
|
16
|
-
primary_interface
|
17
16
|
interfaces_data
|
18
|
-
|
17
|
+
primary_interface
|
18
|
+
Facter::Util::Resolvers::Networking.expand_main_bindings(@fact_list)
|
19
19
|
@fact_list[fact_name]
|
20
20
|
end
|
21
21
|
|
22
22
|
def primary_interface
|
23
|
-
|
23
|
+
primary_helper = Facter::Util::Resolvers::Networking::PrimaryInterface
|
24
|
+
primary_interface ||= primary_helper.read_from_route
|
25
|
+
|
26
|
+
primary_interface ||= primary_helper.find_in_interfaces(@fact_list[:interfaces])
|
24
27
|
|
25
|
-
@fact_list[:primary_interface] =
|
28
|
+
@fact_list[:primary_interface] = primary_interface
|
26
29
|
end
|
27
30
|
|
28
31
|
def interfaces_data
|
@@ -95,7 +98,7 @@ module Facter
|
|
95
98
|
def create_bindings(ips, masks)
|
96
99
|
bindings = []
|
97
100
|
ips.zip(masks).each do |ip, mask|
|
98
|
-
bindings << ::Resolvers::
|
101
|
+
bindings << Facter::Util::Resolvers::Networking.build_binding(ip, mask)
|
99
102
|
end
|
100
103
|
bindings
|
101
104
|
end
|