facter 2.1.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of facter might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/COMMITTERS.md +194 -0
- data/CONTRIBUTING.md +65 -0
- data/Gemfile +53 -0
- data/LICENSE +15 -0
- data/README.md +33 -0
- data/Rakefile +79 -0
- data/bin/facter +20 -0
- data/etc/facter.conf +5 -0
- data/ext/build_defaults.yaml +24 -0
- data/ext/debian/changelog.erb +59 -0
- data/ext/debian/compat +1 -0
- data/ext/debian/control +14 -0
- data/ext/debian/copyright +19 -0
- data/ext/debian/docs +1 -0
- data/ext/debian/lintian-overrides +0 -0
- data/ext/debian/rules +10 -0
- data/ext/debian/source/format +1 -0
- data/ext/facter-diff +74 -0
- data/ext/ips/facter.p5m.erb +10 -0
- data/ext/ips/rules +7 -0
- data/ext/ips/transforms +18 -0
- data/ext/osx/file_mapping.yaml +27 -0
- data/ext/osx/preflight.erb +33 -0
- data/ext/osx/prototype.plist.erb +38 -0
- data/ext/project_data.yaml +36 -0
- data/ext/redhat/facter.spec.erb +220 -0
- data/ext/solaris/pkginfo +7 -0
- data/install.rb +380 -0
- data/lib/facter.rb +261 -0
- data/lib/facter/Cfkey.rb +42 -0
- data/lib/facter/application.rb +204 -0
- data/lib/facter/architecture.rb +50 -0
- data/lib/facter/augeasversion.rb +28 -0
- data/lib/facter/blockdevices.rb +105 -0
- data/lib/facter/core/aggregate.rb +220 -0
- data/lib/facter/core/directed_graph.rb +46 -0
- data/lib/facter/core/execution.rb +123 -0
- data/lib/facter/core/execution/base.rb +81 -0
- data/lib/facter/core/execution/posix.rb +50 -0
- data/lib/facter/core/execution/windows.rb +57 -0
- data/lib/facter/core/logging.rb +169 -0
- data/lib/facter/core/resolvable.rb +94 -0
- data/lib/facter/core/suitable.rb +113 -0
- data/lib/facter/dhcp_servers.rb +39 -0
- data/lib/facter/domain.rb +99 -0
- data/lib/facter/ec2.rb +44 -0
- data/lib/facter/ec2/rest.rb +130 -0
- data/lib/facter/facterversion.rb +15 -0
- data/lib/facter/filesystems.rb +38 -0
- data/lib/facter/fqdn.rb +24 -0
- data/lib/facter/gce.rb +16 -0
- data/lib/facter/gce/metadata.rb +87 -0
- data/lib/facter/hardwareisa.rb +20 -0
- data/lib/facter/hardwaremodel.rb +67 -0
- data/lib/facter/hostname.rb +31 -0
- data/lib/facter/id.rb +21 -0
- data/lib/facter/interfaces.rb +46 -0
- data/lib/facter/ipaddress.rb +171 -0
- data/lib/facter/ipaddress6.rb +82 -0
- data/lib/facter/iphostnumber.rb +29 -0
- data/lib/facter/kernel.rb +22 -0
- data/lib/facter/kernelmajversion.rb +23 -0
- data/lib/facter/kernelrelease.rb +50 -0
- data/lib/facter/kernelversion.rb +22 -0
- data/lib/facter/ldom.rb +47 -0
- data/lib/facter/lsbdistcodename.rb +16 -0
- data/lib/facter/lsbdistdescription.rb +25 -0
- data/lib/facter/lsbdistid.rb +16 -0
- data/lib/facter/lsbdistrelease.rb +16 -0
- data/lib/facter/lsbmajdistrelease.rb +27 -0
- data/lib/facter/lsbrelease.rb +16 -0
- data/lib/facter/macaddress.rb +97 -0
- data/lib/facter/macosx.rb +56 -0
- data/lib/facter/manufacturer.rb +68 -0
- data/lib/facter/memory.rb +168 -0
- data/lib/facter/netmask.rb +42 -0
- data/lib/facter/network.rb +20 -0
- data/lib/facter/operatingsystem.rb +141 -0
- data/lib/facter/operatingsystemmajrelease.rb +47 -0
- data/lib/facter/operatingsystemrelease.rb +250 -0
- data/lib/facter/osfamily.rb +37 -0
- data/lib/facter/partitions.rb +35 -0
- data/lib/facter/path.rb +14 -0
- data/lib/facter/physicalprocessorcount.rb +91 -0
- data/lib/facter/processor.rb +168 -0
- data/lib/facter/ps.rb +30 -0
- data/lib/facter/puppetversion.rb +20 -0
- data/lib/facter/rubysitedir.rb +12 -0
- data/lib/facter/rubyversion.rb +12 -0
- data/lib/facter/selinux.rb +99 -0
- data/lib/facter/ssh.rb +72 -0
- data/lib/facter/timezone.rb +14 -0
- data/lib/facter/uniqueid.rb +4 -0
- data/lib/facter/uptime.rb +34 -0
- data/lib/facter/uptime_days.rb +15 -0
- data/lib/facter/uptime_hours.rb +15 -0
- data/lib/facter/uptime_seconds.rb +24 -0
- data/lib/facter/util/architecture.rb +19 -0
- data/lib/facter/util/collection.rb +161 -0
- data/lib/facter/util/composite_loader.rb +12 -0
- data/lib/facter/util/config.rb +63 -0
- data/lib/facter/util/confine.rb +66 -0
- data/lib/facter/util/dhcp_servers.rb +43 -0
- data/lib/facter/util/directory_loader.rb +83 -0
- data/lib/facter/util/ec2.rb +106 -0
- data/lib/facter/util/fact.rb +204 -0
- data/lib/facter/util/file_read.rb +37 -0
- data/lib/facter/util/formatter.rb +39 -0
- data/lib/facter/util/ip.rb +285 -0
- data/lib/facter/util/ip/windows.rb +215 -0
- data/lib/facter/util/loader.rb +155 -0
- data/lib/facter/util/macaddress.rb +43 -0
- data/lib/facter/util/macosx.rb +73 -0
- data/lib/facter/util/manufacturer.rb +99 -0
- data/lib/facter/util/memory.rb +228 -0
- data/lib/facter/util/netmask.rb +40 -0
- data/lib/facter/util/normalization.rb +94 -0
- data/lib/facter/util/nothing_loader.rb +12 -0
- data/lib/facter/util/operatingsystem.rb +21 -0
- data/lib/facter/util/parser.rb +158 -0
- data/lib/facter/util/partitions.rb +41 -0
- data/lib/facter/util/partitions/linux.rb +65 -0
- data/lib/facter/util/plist.rb +24 -0
- data/lib/facter/util/plist/generator.rb +228 -0
- data/lib/facter/util/plist/parser.rb +226 -0
- data/lib/facter/util/posix.rb +16 -0
- data/lib/facter/util/processor.rb +289 -0
- data/lib/facter/util/registry.rb +11 -0
- data/lib/facter/util/resolution.rb +160 -0
- data/lib/facter/util/solaris_zones.rb +158 -0
- data/lib/facter/util/unix_root.rb +5 -0
- data/lib/facter/util/uptime.rb +81 -0
- data/lib/facter/util/values.rb +109 -0
- data/lib/facter/util/virtual.rb +180 -0
- data/lib/facter/util/vlans.rb +21 -0
- data/lib/facter/util/windows_root.rb +7 -0
- data/lib/facter/util/wmi.rb +16 -0
- data/lib/facter/util/xendomains.rb +10 -0
- data/lib/facter/version.rb +86 -0
- data/lib/facter/virtual.rb +311 -0
- data/lib/facter/vlans.rb +17 -0
- data/lib/facter/xendomains.rb +20 -0
- data/lib/facter/zfs_version.rb +10 -0
- data/lib/facter/zonename.rb +6 -0
- data/lib/facter/zones.rb +17 -0
- data/lib/facter/zpool_version.rb +10 -0
- data/spec/fixtures/cpuinfo/amd64dual +57 -0
- data/spec/fixtures/cpuinfo/amd64quad +79 -0
- data/spec/fixtures/cpuinfo/amd64solo +23 -0
- data/spec/fixtures/cpuinfo/amd64tri +86 -0
- data/spec/fixtures/cpuinfo/amd64twentyfour +600 -0
- data/spec/fixtures/cpuinfo/bbg3-armel +12 -0
- data/spec/fixtures/cpuinfo/beaglexm-armel +12 -0
- data/spec/fixtures/cpuinfo/panda-armel +17 -0
- data/spec/fixtures/cpuinfo/ppc64 +19 -0
- data/spec/fixtures/cpuinfo/sparc +10 -0
- data/spec/fixtures/hpux/machinfo/hppa-rp4440 +26 -0
- data/spec/fixtures/hpux/machinfo/ia64-rx2620 +49 -0
- data/spec/fixtures/hpux/machinfo/ia64-rx6600 +26 -0
- data/spec/fixtures/hpux/machinfo/ia64-rx8640 +53 -0
- data/spec/fixtures/hpux/machinfo/superdome-server-SD32B +53 -0
- data/spec/fixtures/hpux/machinfo/superdome2-16s +31 -0
- data/spec/fixtures/hpux/sched.models +174 -0
- data/spec/fixtures/hpux/unistd.h +1534 -0
- data/spec/fixtures/ifconfig/bsd_ifconfig_all_with_multiple_interfaces +18 -0
- data/spec/fixtures/ifconfig/centos_5_5 +17 -0
- data/spec/fixtures/ifconfig/centos_5_5_eth0 +8 -0
- data/spec/fixtures/ifconfig/darwin_10_3_0 +26 -0
- data/spec/fixtures/ifconfig/darwin_10_3_0_en0 +6 -0
- data/spec/fixtures/ifconfig/darwin_10_6_4 +28 -0
- data/spec/fixtures/ifconfig/darwin_10_6_4_en1 +6 -0
- data/spec/fixtures/ifconfig/darwin_10_6_6_dualstack +8 -0
- data/spec/fixtures/ifconfig/darwin_10_6_6_dualstack_en1 +7 -0
- data/spec/fixtures/ifconfig/darwin_9_8_0 +26 -0
- data/spec/fixtures/ifconfig/darwin_9_8_0_en0 +6 -0
- data/spec/fixtures/ifconfig/darwin_ifconfig_all_with_multiple_interfaces +23 -0
- data/spec/fixtures/ifconfig/fedora_10 +36 -0
- data/spec/fixtures/ifconfig/fedora_10_eth0 +9 -0
- data/spec/fixtures/ifconfig/fedora_13 +18 -0
- data/spec/fixtures/ifconfig/fedora_13_eth0 +9 -0
- data/spec/fixtures/ifconfig/fedora_8 +38 -0
- data/spec/fixtures/ifconfig/fedora_8_eth0 +9 -0
- data/spec/fixtures/ifconfig/freebsd_6_0 +12 -0
- data/spec/fixtures/ifconfig/ifconfig_net_tools_1.60.txt +19 -0
- data/spec/fixtures/ifconfig/ifconfig_ubuntu_1204.txt +16 -0
- data/spec/fixtures/ifconfig/linux_ifconfig_all_with_multiple_interfaces +19 -0
- data/spec/fixtures/ifconfig/linux_ifconfig_no_addr +19 -0
- data/spec/fixtures/ifconfig/linux_ifconfig_no_mac +8 -0
- data/spec/fixtures/ifconfig/linux_ifconfig_venet +24 -0
- data/spec/fixtures/ifconfig/open_solaris_10 +12 -0
- data/spec/fixtures/ifconfig/open_solaris_b132 +20 -0
- data/spec/fixtures/ifconfig/openbsd_bridge_rules +11 -0
- data/spec/fixtures/ifconfig/sunos_ifconfig_all_with_multiple_interfaces +10 -0
- data/spec/fixtures/ifconfig/ubuntu_7_04 +38 -0
- data/spec/fixtures/ifconfig/ubuntu_7_04_eth0 +9 -0
- data/spec/fixtures/ldom/ldom_v1 +6 -0
- data/spec/fixtures/netstat/centos_5_5 +5 -0
- data/spec/fixtures/netstat/darwin_10_3_0 +35 -0
- data/spec/fixtures/netstat/darwin_10_6_4 +29 -0
- data/spec/fixtures/netstat/darwin_10_6_6_dualstack +34 -0
- data/spec/fixtures/netstat/darwin_9_8_0 +28 -0
- data/spec/fixtures/netstat/fedora_10 +7 -0
- data/spec/fixtures/netstat/open_solaris_10 +16 -0
- data/spec/fixtures/netstat/open_solaris_b132 +17 -0
- data/spec/fixtures/netstat/ubuntu_7_04 +7 -0
- data/spec/fixtures/processorcount/solaris-psrinfo +24 -0
- data/spec/fixtures/processorcount/solaris-sparc-kstat-cpu-info +1216 -0
- data/spec/fixtures/processorcount/solaris-x86_64-kstat-cpu-info +225 -0
- data/spec/fixtures/unit/dhcp_servers/nmcli_devices +4 -0
- data/spec/fixtures/unit/dhcp_servers/nmcli_devices_disconnected +4 -0
- data/spec/fixtures/unit/dhcp_servers/nmcli_eth0_dhcp +36 -0
- data/spec/fixtures/unit/dhcp_servers/nmcli_eth0_static +24 -0
- data/spec/fixtures/unit/dhcp_servers/nmcli_wlan0_dhcp +49 -0
- data/spec/fixtures/unit/dhcp_servers/nmcli_wlan0_static +37 -0
- data/spec/fixtures/unit/dhcp_servers/route +3 -0
- data/spec/fixtures/unit/dhcp_servers/route_nogw +1 -0
- data/spec/fixtures/unit/ec2/rest/meta-data/root +20 -0
- data/spec/fixtures/unit/filesystems/linux +28 -0
- data/spec/fixtures/unit/gce/metadata/metadata.json +69 -0
- data/spec/fixtures/unit/interfaces/ifconfig_net_tools_1.60.txt +19 -0
- data/spec/fixtures/unit/interfaces/ifconfig_net_tools_1.60.txt.em1 +10 -0
- data/spec/fixtures/unit/interfaces/ifconfig_net_tools_1.60.txt.lo +8 -0
- data/spec/fixtures/unit/ipaddress/ifconfig_multiple_127_addresses.txt +20 -0
- data/spec/fixtures/unit/ipaddress/ifconfig_net_tools_1.60.txt +19 -0
- data/spec/fixtures/unit/ipaddress/ifconfig_non_english_locale.txt +18 -0
- data/spec/fixtures/unit/ipaddress/ifconfig_ubuntu_1204.txt +16 -0
- data/spec/fixtures/unit/kernelrelease/openbsd-5.3 +2 -0
- data/spec/fixtures/unit/kernelrelease/openbsd-5.3-current +3 -0
- data/spec/fixtures/unit/memory/aix-svmon +9 -0
- data/spec/fixtures/unit/memory/aix-swap_l +2 -0
- data/spec/fixtures/unit/memory/darwin-swapinfo-multiple +3 -0
- data/spec/fixtures/unit/memory/darwin-swapinfo-single +2 -0
- data/spec/fixtures/unit/memory/darwin-vm_stat +13 -0
- data/spec/fixtures/unit/memory/dragonfly-vmstat +3 -0
- data/spec/fixtures/unit/memory/freebsd-vmstat +3 -0
- data/spec/fixtures/unit/memory/linux-proc_meminfo +10 -0
- data/spec/fixtures/unit/memory/openbsd-vmstat +3 -0
- data/spec/fixtures/unit/memory/smartos_zone_swap_l-single +2 -0
- data/spec/fixtures/unit/memory/solaris-prtconf +4 -0
- data/spec/fixtures/unit/memory/solaris-swap_l-multiple +3 -0
- data/spec/fixtures/unit/memory/solaris-swap_l-single +2 -0
- data/spec/fixtures/unit/memory/solaris-vmstat +3 -0
- data/spec/fixtures/unit/netmask/darwin_10_8_5.txt +30 -0
- data/spec/fixtures/unit/netmask/ifconfig_aix_7.txt +3 -0
- data/spec/fixtures/unit/netmask/ifconfig_net_tools_1.60.txt +19 -0
- data/spec/fixtures/unit/netmask/ifconfig_ubuntu_1204.txt +16 -0
- data/spec/fixtures/unit/selinux/selinux_sestatus +6 -0
- data/spec/fixtures/unit/util/dhcp_servers/route +3 -0
- data/spec/fixtures/unit/util/dhcp_servers/route_nogw +1 -0
- data/spec/fixtures/unit/util/ec2/centos-arp-ec2.out +1 -0
- data/spec/fixtures/unit/util/ec2/linux-arp-ec2.out +1 -0
- data/spec/fixtures/unit/util/ec2/linux-arp-not-ec2.out +5 -0
- data/spec/fixtures/unit/util/ec2/solaris8_arp_a_not_ec2.out +7 -0
- data/spec/fixtures/unit/util/ec2/windows-2008-arp-a-not-ec2.out +6 -0
- data/spec/fixtures/unit/util/ec2/windows-2008-arp-a.out +10 -0
- data/spec/fixtures/unit/util/ip/6.0-STABLE_FreeBSD_ifconfig +12 -0
- data/spec/fixtures/unit/util/ip/Mac_OS_X_10.5.5_ifconfig +26 -0
- data/spec/fixtures/unit/util/ip/darwin_ifconfig_all_with_multiple_interfaces +10 -0
- data/spec/fixtures/unit/util/ip/darwin_ifconfig_single_interface +6 -0
- data/spec/fixtures/unit/util/ip/debian_kfreebsd_ifconfig +40 -0
- data/spec/fixtures/unit/util/ip/hpux_1111_ifconfig_lan0 +2 -0
- data/spec/fixtures/unit/util/ip/hpux_1111_ifconfig_lan1 +2 -0
- data/spec/fixtures/unit/util/ip/hpux_1111_ifconfig_lo0 +2 -0
- data/spec/fixtures/unit/util/ip/hpux_1111_lanscan +5 -0
- data/spec/fixtures/unit/util/ip/hpux_1111_netstat_in +4 -0
- data/spec/fixtures/unit/util/ip/hpux_1131_asterisk_ifconfig_lan0 +2 -0
- data/spec/fixtures/unit/util/ip/hpux_1131_asterisk_ifconfig_lan1 +2 -0
- data/spec/fixtures/unit/util/ip/hpux_1131_asterisk_ifconfig_lo0 +2 -0
- data/spec/fixtures/unit/util/ip/hpux_1131_asterisk_lanscan +5 -0
- data/spec/fixtures/unit/util/ip/hpux_1131_asterisk_netstat_in +4 -0
- data/spec/fixtures/unit/util/ip/hpux_1131_ifconfig_lan0 +2 -0
- data/spec/fixtures/unit/util/ip/hpux_1131_ifconfig_lan1 +2 -0
- data/spec/fixtures/unit/util/ip/hpux_1131_ifconfig_lo0 +2 -0
- data/spec/fixtures/unit/util/ip/hpux_1131_lanscan +4 -0
- data/spec/fixtures/unit/util/ip/hpux_1131_netstat_in +4 -0
- data/spec/fixtures/unit/util/ip/hpux_1131_nic_bonding_ifconfig_lan1 +2 -0
- data/spec/fixtures/unit/util/ip/hpux_1131_nic_bonding_ifconfig_lan4 +2 -0
- data/spec/fixtures/unit/util/ip/hpux_1131_nic_bonding_ifconfig_lan4_1 +2 -0
- data/spec/fixtures/unit/util/ip/hpux_1131_nic_bonding_ifconfig_lo0 +2 -0
- data/spec/fixtures/unit/util/ip/hpux_1131_nic_bonding_lanscan +9 -0
- data/spec/fixtures/unit/util/ip/hpux_1131_nic_bonding_netstat_in +6 -0
- data/spec/fixtures/unit/util/ip/linux_2_6_35_proc_net_bonding_bond0 +19 -0
- data/spec/fixtures/unit/util/ip/linux_get_single_interface_eth0 +10 -0
- data/spec/fixtures/unit/util/ip/linux_get_single_interface_ib0 +8 -0
- data/spec/fixtures/unit/util/ip/linux_get_single_interface_lo +9 -0
- data/spec/fixtures/unit/util/ip/linux_ifconfig_all_with_single_interface +18 -0
- data/spec/fixtures/unit/util/ip/linux_ifconfig_ib0 +8 -0
- data/spec/fixtures/unit/util/ip/solaris_ifconfig_all_with_multiple_interfaces +8 -0
- data/spec/fixtures/unit/util/ip/solaris_ifconfig_single_interface +3 -0
- data/spec/fixtures/unit/util/ip/windows_netsh_all_interfaces +12 -0
- data/spec/fixtures/unit/util/ip/windows_netsh_single_interface +7 -0
- data/spec/fixtures/unit/util/ip/windows_netsh_single_interface6 +18 -0
- data/spec/fixtures/unit/util/manufacturer/freebsd_dmidecode +42 -0
- data/spec/fixtures/unit/util/manufacturer/intel_linux_dmidecode +549 -0
- data/spec/fixtures/unit/util/manufacturer/linux_dmidecode_with_spaces +60 -0
- data/spec/fixtures/unit/util/manufacturer/opensolaris_smbios +33 -0
- data/spec/fixtures/unit/util/manufacturer/smartos_smbios +533 -0
- data/spec/fixtures/unit/util/manufacturer/solaris_sunfire_v120_prtdiag +33 -0
- data/spec/fixtures/unit/util/manufacturer/solaris_t5220_prtdiag +136 -0
- data/spec/fixtures/unit/util/operatingsystem/cumuluslinux.txt +8 -0
- data/spec/fixtures/unit/util/operatingsystem/redhat-7.txt +12 -0
- data/spec/fixtures/unit/util/operatingsystem/sabayon.txt +7 -0
- data/spec/fixtures/unit/util/operatingsystem/wheezy.txt +9 -0
- data/spec/fixtures/unit/util/partitions/partitions/mount +9 -0
- data/spec/fixtures/unit/util/processor/solaris-i86pc +28 -0
- data/spec/fixtures/unit/util/processor/solaris-sun4u +151 -0
- data/spec/fixtures/unit/util/processor/x86-pentium2 +41 -0
- data/spec/fixtures/unit/util/uptime/kstat_boot_time +1 -0
- data/spec/fixtures/unit/util/uptime/sysctl_kern_boottime_darwin +1 -0
- data/spec/fixtures/unit/util/uptime/sysctl_kern_boottime_openbsd +1 -0
- data/spec/fixtures/unit/util/uptime/ubuntu_proc_uptime +1 -0
- data/spec/fixtures/unit/util/virtual/invalid_unicode_dmi_entries +0 -0
- data/spec/fixtures/unit/util/virtual/solaris10_proc_self_status1 +0 -0
- data/spec/fixtures/unit/util/vlans/centos-5-no-vlans +2 -0
- data/spec/fixtures/unit/util/vlans/linux_vlan_config +6 -0
- data/spec/fixtures/unit/util/xendomains/xendomains +4 -0
- data/spec/fixtures/unit/virtual/sysfs_dmi_entries_raw.txt +0 -0
- data/spec/fixtures/unit/zfs_version/freebsd_8.2 +14 -0
- data/spec/fixtures/unit/zfs_version/freebsd_9.0 +13 -0
- data/spec/fixtures/unit/zfs_version/linux-fuse_0.6.9 +14 -0
- data/spec/fixtures/unit/zfs_version/solaris_10 +10 -0
- data/spec/fixtures/unit/zfs_version/solaris_11 +12 -0
- data/spec/fixtures/unit/zpool_version/freebsd_8.2 +26 -0
- data/spec/fixtures/unit/zpool_version/freebsd_9.0 +38 -0
- data/spec/fixtures/unit/zpool_version/linux-fuse_0.6.9 +35 -0
- data/spec/fixtures/unit/zpool_version/solaris_10 +31 -0
- data/spec/fixtures/unit/zpool_version/solaris_11 +43 -0
- data/spec/fixtures/virtual/proc_1_cgroup/in_a_container +9 -0
- data/spec/fixtures/virtual/proc_1_cgroup/in_a_docker_container +8 -0
- data/spec/fixtures/virtual/proc_1_cgroup/not_in_a_container +9 -0
- data/spec/fixtures/virtual/proc_self_status/vserver_2_1/guest +37 -0
- data/spec/fixtures/virtual/proc_self_status/vserver_2_1/host +36 -0
- data/spec/fixtures/virtual/proc_self_status/vserver_2_3/guest +39 -0
- data/spec/fixtures/virtual/proc_self_status/vserver_2_3/host +39 -0
- data/spec/integration/facter_spec.rb +39 -0
- data/spec/lib/facter_spec/cpuinfo.rb +15 -0
- data/spec/lib/facter_spec/windows_network.rb +64 -0
- data/spec/puppetlabs_spec/files.rb +57 -0
- data/spec/puppetlabs_spec/fixtures.rb +49 -0
- data/spec/puppetlabs_spec/matchers.rb +87 -0
- data/spec/puppetlabs_spec/verbose.rb +9 -0
- data/spec/puppetlabs_spec_helper.rb +26 -0
- data/spec/shared_contexts/platform.rb +55 -0
- data/spec/shared_formats/parses.rb +3 -0
- data/spec/spec_helper.rb +75 -0
- data/spec/unit/application_spec.rb +101 -0
- data/spec/unit/architecture_spec.rb +63 -0
- data/spec/unit/blockdevices_spec.rb +109 -0
- data/spec/unit/core/aggregate_spec.rb +125 -0
- data/spec/unit/core/directed_graph_spec.rb +79 -0
- data/spec/unit/core/execution/base_spec.rb +130 -0
- data/spec/unit/core/execution/posix_spec.rb +86 -0
- data/spec/unit/core/execution/windows_spec.rb +106 -0
- data/spec/unit/core/execution_spec.rb +42 -0
- data/spec/unit/core/logging_spec.rb +104 -0
- data/spec/unit/core/resolvable_spec.rb +81 -0
- data/spec/unit/core/suitable_spec.rb +106 -0
- data/spec/unit/dhcp_servers_spec.rb +152 -0
- data/spec/unit/domain_spec.rb +310 -0
- data/spec/unit/ec2/rest_spec.rb +145 -0
- data/spec/unit/ec2_spec.rb +127 -0
- data/spec/unit/facter_spec.rb +108 -0
- data/spec/unit/filesystems_spec.rb +50 -0
- data/spec/unit/fqdn_spec.rb +16 -0
- data/spec/unit/gce/metadata_spec.rb +49 -0
- data/spec/unit/gce_spec.rb +34 -0
- data/spec/unit/hardwareisa_spec.rb +41 -0
- data/spec/unit/hardwaremodel_spec.rb +56 -0
- data/spec/unit/hostname_spec.rb +40 -0
- data/spec/unit/id_spec.rb +29 -0
- data/spec/unit/interfaces_spec.rb +57 -0
- data/spec/unit/ipaddress6_spec.rb +161 -0
- data/spec/unit/ipaddress_spec.rb +114 -0
- data/spec/unit/kernel_spec.rb +24 -0
- data/spec/unit/kernelmajversion_spec.rb +22 -0
- data/spec/unit/kernelrelease_spec.rb +69 -0
- data/spec/unit/kernelversion_spec.rb +32 -0
- data/spec/unit/ldom_spec.rb +75 -0
- data/spec/unit/lsbdistcodename_spec.rb +25 -0
- data/spec/unit/lsbdistdescription_spec.rb +25 -0
- data/spec/unit/lsbdistid_spec.rb +25 -0
- data/spec/unit/lsbdistrelease_spec.rb +25 -0
- data/spec/unit/lsbmajdistrelease_spec.rb +13 -0
- data/spec/unit/lsbrelease_spec.rb +25 -0
- data/spec/unit/macaddress_spec.rb +73 -0
- data/spec/unit/manufacturer_spec.rb +115 -0
- data/spec/unit/memory_spec.rb +470 -0
- data/spec/unit/netmask_spec.rb +106 -0
- data/spec/unit/operatingsystem_spec.rb +160 -0
- data/spec/unit/operatingsystemmajrelease_spec.rb +38 -0
- data/spec/unit/operatingsystemrelease_spec.rb +236 -0
- data/spec/unit/osfamily_spec.rb +62 -0
- data/spec/unit/partitions_spec.rb +48 -0
- data/spec/unit/physicalprocessorcount_spec.rb +85 -0
- data/spec/unit/processor_spec.rb +401 -0
- data/spec/unit/ps_spec.rb +42 -0
- data/spec/unit/selinux_spec.rb +114 -0
- data/spec/unit/ssh_spec.rb +77 -0
- data/spec/unit/uniqueid_spec.rb +27 -0
- data/spec/unit/uptime_spec.rb +110 -0
- data/spec/unit/util/collection_spec.rb +258 -0
- data/spec/unit/util/config_spec.rb +97 -0
- data/spec/unit/util/confine_spec.rb +148 -0
- data/spec/unit/util/dhcp_servers_spec.rb +63 -0
- data/spec/unit/util/directory_loader_spec.rb +88 -0
- data/spec/unit/util/ec2_spec.rb +184 -0
- data/spec/unit/util/fact_spec.rb +142 -0
- data/spec/unit/util/file_read_spec.rb +29 -0
- data/spec/unit/util/formatter_spec.rb +50 -0
- data/spec/unit/util/ip/windows_spec.rb +80 -0
- data/spec/unit/util/ip_spec.rb +467 -0
- data/spec/unit/util/loader_spec.rb +286 -0
- data/spec/unit/util/macaddress_spec.rb +141 -0
- data/spec/unit/util/macosx_spec.rb +114 -0
- data/spec/unit/util/manufacturer_spec.rb +223 -0
- data/spec/unit/util/normalization_spec.rb +113 -0
- data/spec/unit/util/operatingsystem_spec.rb +92 -0
- data/spec/unit/util/parser_spec.rb +200 -0
- data/spec/unit/util/partitions/partitions_spec.rb +67 -0
- data/spec/unit/util/partitions_spec.rb +19 -0
- data/spec/unit/util/posix_spec.rb +11 -0
- data/spec/unit/util/processor_spec.rb +92 -0
- data/spec/unit/util/registry_spec.rb +76 -0
- data/spec/unit/util/resolution_spec.rb +129 -0
- data/spec/unit/util/solaris_zones_spec.rb +127 -0
- data/spec/unit/util/uptime_spec.rb +126 -0
- data/spec/unit/util/values_spec.rb +171 -0
- data/spec/unit/util/virtual_spec.rb +364 -0
- data/spec/unit/util/vlans_spec.rb +42 -0
- data/spec/unit/util/wmi_spec.rb +19 -0
- data/spec/unit/util/xendomains_spec.rb +21 -0
- data/spec/unit/version_spec.rb +42 -0
- data/spec/unit/virtual_spec.rb +519 -0
- data/spec/unit/zfs_version_spec.rb +75 -0
- data/spec/unit/zonename_spec.rb +14 -0
- data/spec/unit/zones_spec.rb +55 -0
- data/spec/unit/zpool_version_spec.rb +75 -0
- data/spec/watchr.rb +125 -0
- metadata +815 -0
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'facter/util/confine'
|
2
|
+
require 'facter/util/config'
|
3
|
+
require 'facter/util/normalization'
|
4
|
+
require 'facter/core/execution'
|
5
|
+
require 'facter/core/resolvable'
|
6
|
+
require 'facter/core/suitable'
|
7
|
+
|
8
|
+
# This represents a fact resolution. A resolution is a concrete
|
9
|
+
# implementation of a fact. A single fact can have many resolutions and
|
10
|
+
# the correct resolution will be chosen at runtime. Each time
|
11
|
+
# {Facter.add} is called, a new resolution is created and added to the
|
12
|
+
# set of resolutions for the fact named in the call. Each resolution
|
13
|
+
# has a {#has_weight weight}, which defines its priority over other
|
14
|
+
# resolutions, and a set of {#confine _confinements_}, which defines the
|
15
|
+
# conditions under which it will be chosen. All confinements must be
|
16
|
+
# satisfied for a fact to be considered _suitable_.
|
17
|
+
#
|
18
|
+
# @api public
|
19
|
+
class Facter::Util::Resolution
|
20
|
+
# @api private
|
21
|
+
attr_accessor :code
|
22
|
+
attr_writer :value
|
23
|
+
|
24
|
+
extend Facter::Core::Execution
|
25
|
+
|
26
|
+
class << self
|
27
|
+
# Expose command execution methods that were extracted into
|
28
|
+
# Facter::Util::Execution from Facter::Util::Resolution in Facter 2.0.0 for
|
29
|
+
# compatibility.
|
30
|
+
#
|
31
|
+
# @deprecated
|
32
|
+
public :search_paths, :which, :absolute_path?, :expand_command, :with_env, :exec
|
33
|
+
end
|
34
|
+
|
35
|
+
include Facter::Core::Resolvable
|
36
|
+
include Facter::Core::Suitable
|
37
|
+
|
38
|
+
# @!attribute [rw] name
|
39
|
+
# The name of this resolution. The resolution name should be unique with
|
40
|
+
# respect to the given fact.
|
41
|
+
# @return [String]
|
42
|
+
# @api public
|
43
|
+
attr_accessor :name
|
44
|
+
|
45
|
+
# @!attribute [r] fact
|
46
|
+
# @return [Facter::Util::Fact]
|
47
|
+
# @api private
|
48
|
+
attr_reader :fact
|
49
|
+
|
50
|
+
# Create a new resolution mechanism.
|
51
|
+
#
|
52
|
+
# @param name [String] The name of the resolution.
|
53
|
+
# @return [void]
|
54
|
+
#
|
55
|
+
# @api private
|
56
|
+
def initialize(name, fact)
|
57
|
+
@name = name
|
58
|
+
@fact = fact
|
59
|
+
@confines = []
|
60
|
+
@value = nil
|
61
|
+
@timeout = 0
|
62
|
+
@weight = nil
|
63
|
+
end
|
64
|
+
|
65
|
+
def resolution_type
|
66
|
+
:simple
|
67
|
+
end
|
68
|
+
|
69
|
+
# Evaluate the given block in the context of this resolution. If a block has
|
70
|
+
# already been evaluated emit a warning to that effect.
|
71
|
+
#
|
72
|
+
# @return [void]
|
73
|
+
def evaluate(&block)
|
74
|
+
if @last_evaluated
|
75
|
+
msg = "Already evaluated #{@name}"
|
76
|
+
msg << " at #{@last_evaluated}" if msg.is_a? String
|
77
|
+
msg << ", reevaluating anyways"
|
78
|
+
Facter.warn msg
|
79
|
+
end
|
80
|
+
|
81
|
+
instance_eval(&block)
|
82
|
+
|
83
|
+
# Ruby 1.9+ provides the source location of procs which can provide useful
|
84
|
+
# debugging information if a resolution is being evaluated twice. Since 1.8
|
85
|
+
# doesn't support this we opportunistically provide this information.
|
86
|
+
if block.respond_to? :source_location
|
87
|
+
@last_evaluated = block.source_location.join(':')
|
88
|
+
else
|
89
|
+
@last_evaluated = true
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def set_options(options)
|
94
|
+
if options[:name]
|
95
|
+
@name = options.delete(:name)
|
96
|
+
end
|
97
|
+
|
98
|
+
if options.has_key?(:value)
|
99
|
+
@value = options.delete(:value)
|
100
|
+
end
|
101
|
+
|
102
|
+
if options.has_key?(:timeout)
|
103
|
+
@timeout = options.delete(:timeout)
|
104
|
+
end
|
105
|
+
|
106
|
+
if options.has_key?(:weight)
|
107
|
+
@weight = options.delete(:weight)
|
108
|
+
end
|
109
|
+
|
110
|
+
if not options.keys.empty?
|
111
|
+
raise ArgumentError, "Invalid resolution options #{options.keys.inspect}"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# Sets the code block or external program that will be evaluated to
|
116
|
+
# get the value of the fact.
|
117
|
+
#
|
118
|
+
# @return [void]
|
119
|
+
#
|
120
|
+
# @overload setcode(string)
|
121
|
+
# Sets an external program to call to get the value of the resolution
|
122
|
+
# @param [String] string the external program to run to get the
|
123
|
+
# value
|
124
|
+
#
|
125
|
+
# @overload setcode(&block)
|
126
|
+
# Sets the resolution's value by evaluating a block at runtime
|
127
|
+
# @param [Proc] block The block to determine the resolution's value.
|
128
|
+
# This block is run when the fact is evaluated. Errors raised from
|
129
|
+
# inside the block are rescued and printed to stderr.
|
130
|
+
#
|
131
|
+
# @api public
|
132
|
+
def setcode(string = nil, &block)
|
133
|
+
if string
|
134
|
+
@code = Proc.new do
|
135
|
+
output = Facter::Core::Execution.execute(string, :on_fail => nil)
|
136
|
+
if output.nil? or output.empty?
|
137
|
+
nil
|
138
|
+
else
|
139
|
+
output
|
140
|
+
end
|
141
|
+
end
|
142
|
+
elsif block_given?
|
143
|
+
@code = block
|
144
|
+
else
|
145
|
+
raise ArgumentError, "You must pass either code or a block"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
private
|
150
|
+
|
151
|
+
def resolve_value
|
152
|
+
if @value
|
153
|
+
@value
|
154
|
+
elsif @code.nil?
|
155
|
+
nil
|
156
|
+
elsif @code
|
157
|
+
@code.call()
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
require 'facter/util/resolution'
|
2
|
+
|
3
|
+
module Facter
|
4
|
+
module Util
|
5
|
+
##
|
6
|
+
# Provide a set of utility methods to interact with Solaris zones. This class
|
7
|
+
# is expected to be instantiated once per set of resolutions in order to
|
8
|
+
# cache the output of the zoneadm command, which can be quite expensive.
|
9
|
+
#
|
10
|
+
# @api private
|
11
|
+
class SolarisZones
|
12
|
+
attr_reader :zone_hash
|
13
|
+
attr_reader :zoneadm_cmd
|
14
|
+
attr_reader :zoneadm_output
|
15
|
+
attr_reader :zoneadm_keys
|
16
|
+
|
17
|
+
##
|
18
|
+
# add_facts defines all of the facts for solaris zones, for example `zones`,
|
19
|
+
# `zone_global_id`, `zone_global_status`, etc... This method defines the
|
20
|
+
# static fact named `zones`. The value of this fact is the numver of zones
|
21
|
+
# reported by the zoneadm system command. The `zones` fact also defines
|
22
|
+
# all of the dynamic facts describing the following seven attribute values
|
23
|
+
# for each zone.
|
24
|
+
#
|
25
|
+
# Zones may be added to the system while Facter is loaded. In order to
|
26
|
+
# define new dynamic facts that reflect this new information, the `virtual`
|
27
|
+
# will define new facts as a side effect of refreshing it's own value.
|
28
|
+
#
|
29
|
+
# @api private
|
30
|
+
def self.add_facts
|
31
|
+
model = new
|
32
|
+
model.refresh
|
33
|
+
model.add_dynamic_facts
|
34
|
+
Facter.add("zones") do
|
35
|
+
setcode do
|
36
|
+
model.refresh if model.flushed?
|
37
|
+
model.add_dynamic_facts
|
38
|
+
model.count
|
39
|
+
end
|
40
|
+
on_flush do
|
41
|
+
model.flush!
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# @param [Hash] opts the options to create the instance with
|
48
|
+
# @option opts [String] :zoneadm_cmd ('/usr/sbin/zoneadm list -cp') the
|
49
|
+
# system command to inspect zones
|
50
|
+
# @option opts [String] :zoneadm_output (nil) the cached output of the
|
51
|
+
# zoneadm_cmd
|
52
|
+
def initialize(opts = {})
|
53
|
+
@zoneadm_keys = [:id, :name, :status, :path, :uuid, :brand, :iptype]
|
54
|
+
@zoneadm_cmd = opts[:zoneadm_cmd] || '/usr/sbin/zoneadm list -cp'
|
55
|
+
if opts[:zoneadm_output]
|
56
|
+
@zoneadm_output = opts[:zoneadm_output]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
# add_dynamic_facts defines all of the dynamic facts derived from parsing
|
62
|
+
# the output of the zoneadm command. The zone facts are dynamic, so this
|
63
|
+
# method has the behavior of figuring out what dynamic zone facts need to
|
64
|
+
# be defined and how they should be resolved.
|
65
|
+
#
|
66
|
+
# @param model [SolarisZones] the model used to store data from the system
|
67
|
+
#
|
68
|
+
# @api private
|
69
|
+
def add_dynamic_facts
|
70
|
+
model = self
|
71
|
+
zone_hash.each_pair do |zone, attr_hsh|
|
72
|
+
attr_hsh.keys.each do |attr|
|
73
|
+
Facter.add("zone_#{zone}_#{attr}") do
|
74
|
+
setcode do
|
75
|
+
model.refresh if model.flushed?
|
76
|
+
# Don't resolve if the zone has since been deleted
|
77
|
+
if zone_hsh = model.zone_hash[zone]
|
78
|
+
zone_hsh[attr] # the value
|
79
|
+
end
|
80
|
+
end
|
81
|
+
on_flush do
|
82
|
+
model.flush!
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
##
|
90
|
+
# refresh executes the zoneadm_cmd and stores the output data.
|
91
|
+
#
|
92
|
+
# @api private
|
93
|
+
#
|
94
|
+
# @return [Hash] the parsed output of the zoneadm command
|
95
|
+
def refresh
|
96
|
+
@zoneadm_output = Facter::Core::Execution.execute(zoneadm_cmd, {:on_fail => nil})
|
97
|
+
parse!
|
98
|
+
end
|
99
|
+
|
100
|
+
##
|
101
|
+
# parse! parses the string stored in {@zoneadm_output} and stores the
|
102
|
+
# resulting Hash data structure in {@zone_hash}
|
103
|
+
#
|
104
|
+
# @api private
|
105
|
+
def parse!
|
106
|
+
if @zoneadm_output
|
107
|
+
rows = @zoneadm_output.split("\n").collect { |line| line.split(':') }
|
108
|
+
else
|
109
|
+
Facter.debug "Cannot parse zone facts, #{zoneadm_cmd} returned no output"
|
110
|
+
rows = []
|
111
|
+
end
|
112
|
+
|
113
|
+
@zone_hash = rows.inject({}) do |memo, fields|
|
114
|
+
zone = fields[1].intern
|
115
|
+
# Transform the row into a hash with keys named by the column names
|
116
|
+
memo[zone] = Hash[*@zoneadm_keys.zip(fields).flatten]
|
117
|
+
memo
|
118
|
+
end
|
119
|
+
end
|
120
|
+
private :parse!
|
121
|
+
|
122
|
+
##
|
123
|
+
# count returns the number of running zones, including the global zone.
|
124
|
+
# This method is intended to be used from the setcode block of the `zones`
|
125
|
+
# fact.
|
126
|
+
#
|
127
|
+
# @api private
|
128
|
+
#
|
129
|
+
# @return [Fixnum, nil] the number of running zones or nil if the number
|
130
|
+
# could not be determined.
|
131
|
+
def count
|
132
|
+
if @zone_hash
|
133
|
+
@zone_hash.size
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
##
|
138
|
+
# flush! purges the saved data from the zoneadm_cmd output
|
139
|
+
#
|
140
|
+
# @api private
|
141
|
+
def flush!
|
142
|
+
@zoneadm_output = nil
|
143
|
+
@zone_hash = nil
|
144
|
+
end
|
145
|
+
|
146
|
+
##
|
147
|
+
# flushed? returns true if the instance has no parsed data accessible via
|
148
|
+
# the {zone_hash} method.
|
149
|
+
#
|
150
|
+
# @api private
|
151
|
+
#
|
152
|
+
# @return [Boolean] true if there is no parsed data, false otherwise
|
153
|
+
def flushed?
|
154
|
+
!@zone_hash
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
# A module to gather uptime facts
|
4
|
+
#
|
5
|
+
module Facter::Util::Uptime
|
6
|
+
def self.get_uptime_seconds_unix
|
7
|
+
uptime_proc_uptime or uptime_sysctl or uptime_executable
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.get_uptime_seconds_win
|
11
|
+
require 'facter/util/wmi'
|
12
|
+
|
13
|
+
last_boot = ""
|
14
|
+
Facter::Util::WMI.execquery("select * from Win32_OperatingSystem").each do |x|
|
15
|
+
last_boot = x.LastBootupTime
|
16
|
+
end
|
17
|
+
self.compute_uptime(Time.parse(last_boot.split('.').first))
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def self.uptime_proc_uptime
|
23
|
+
output = Facter::Core::Execution.execute("/bin/cat #{uptime_file} 2>/dev/null")
|
24
|
+
|
25
|
+
if not output.empty?
|
26
|
+
output.chomp.split(" ").first.to_i
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.uptime_sysctl
|
31
|
+
output = Facter::Core::Execution.execute("#{uptime_sysctl_cmd} 2>/dev/null", :on_fail => nil)
|
32
|
+
if output
|
33
|
+
compute_uptime(Time.at(output.match(/\d+/)[0].to_i))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.uptime_executable
|
38
|
+
output = Facter::Core::Execution.execute("#{uptime_executable_cmd} 2>/dev/null", :on_fail => nil)
|
39
|
+
|
40
|
+
if output
|
41
|
+
up=0
|
42
|
+
if output =~ /(\d+) day(?:s|\(s\))?,\s+(\d+):(\d+)/
|
43
|
+
# Regexp handles Solaris, AIX, HP-UX, and Tru64.
|
44
|
+
# 'day(?:s|\(s\))?' says maybe 'day', 'days',
|
45
|
+
# or 'day(s)', and don't set $2.
|
46
|
+
up=86400*$1.to_i + 3600*$2.to_i + 60*$3.to_i
|
47
|
+
elsif output =~ /(\d+) day(?:s|\(s\))?,\s+(\d+) hr(?:s|\(s\))?,/
|
48
|
+
up=86400*$1.to_i + 3600*$2.to_i
|
49
|
+
elsif output =~ /(\d+) day(?:s|\(s\))?,\s+(\d+) min(?:s|\(s\))?,/
|
50
|
+
up=86400*$1.to_i + 60*$2.to_i
|
51
|
+
elsif output =~ /(\d+) day(?:s|\(s\))?,/
|
52
|
+
up=86400*$1.to_i
|
53
|
+
elsif output =~ /up\s+(\d+):(\d+),/
|
54
|
+
# must anchor to 'up' to avoid matching time of day
|
55
|
+
# at beginning of line.
|
56
|
+
up=3600*$1.to_i + 60*$2.to_i
|
57
|
+
elsif output =~ /(\d+) hr(?:s|\(s\))?,/
|
58
|
+
up=3600*$1.to_i
|
59
|
+
elsif output =~ /(\d+) min(?:s|\(s\))?,/
|
60
|
+
up=60*$1.to_i
|
61
|
+
end
|
62
|
+
up
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.compute_uptime(time)
|
67
|
+
(Time.now - time).to_i
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.uptime_file
|
71
|
+
"/proc/uptime"
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.uptime_sysctl_cmd
|
75
|
+
'sysctl -n kern.boottime'
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.uptime_executable_cmd
|
79
|
+
"uptime"
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
|
2
|
+
module Facter
|
3
|
+
module Util
|
4
|
+
# A util module for facter containing helper methods
|
5
|
+
module Values
|
6
|
+
module_function
|
7
|
+
|
8
|
+
class DeepFreezeError < StandardError; end
|
9
|
+
|
10
|
+
# Duplicate and deeply freeze a given data structure
|
11
|
+
#
|
12
|
+
# @param value [Object] The structure to freeze
|
13
|
+
# @return [void]
|
14
|
+
def deep_freeze(value)
|
15
|
+
case value
|
16
|
+
when Numeric, Symbol, TrueClass, FalseClass, NilClass
|
17
|
+
# These are immutable values, we can safely ignore them
|
18
|
+
value
|
19
|
+
when String
|
20
|
+
value.dup.freeze
|
21
|
+
when Array
|
22
|
+
value.map do |entry|
|
23
|
+
deep_freeze(entry)
|
24
|
+
end.freeze
|
25
|
+
when Hash
|
26
|
+
value.inject({}) do |hash, (key, value)|
|
27
|
+
hash[deep_freeze(key)] = deep_freeze(value)
|
28
|
+
hash
|
29
|
+
end.freeze
|
30
|
+
else
|
31
|
+
raise DeepFreezeError, "Cannot deep freeze #{value}:#{value.class}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class DeepMergeError < StandardError; end
|
36
|
+
|
37
|
+
# Perform a deep merge of two nested data structures.
|
38
|
+
#
|
39
|
+
# @param left [Object]
|
40
|
+
# @param right [Object]
|
41
|
+
# @param path [Array<String>] The traversal path followed when merging nested hashes
|
42
|
+
#
|
43
|
+
# @return [Object] The merged data structure.
|
44
|
+
def deep_merge(left, right, path = [], &block)
|
45
|
+
ret = nil
|
46
|
+
|
47
|
+
if left.is_a? Hash and right.is_a? Hash
|
48
|
+
ret = left.merge(right) do |key, left_val, right_val|
|
49
|
+
path.push(key)
|
50
|
+
merged = deep_merge(left_val, right_val, path)
|
51
|
+
path.pop
|
52
|
+
merged
|
53
|
+
end
|
54
|
+
elsif left.is_a? Array and right.is_a? Array
|
55
|
+
ret = left.dup.concat(right)
|
56
|
+
elsif right.nil?
|
57
|
+
ret = left
|
58
|
+
elsif left.nil?
|
59
|
+
ret = right
|
60
|
+
elsif left.nil? and right.nil?
|
61
|
+
ret = nil
|
62
|
+
else
|
63
|
+
msg = "Cannot merge #{left.inspect}:#{left.class} and #{right.inspect}:#{right.class}"
|
64
|
+
if not path.empty?
|
65
|
+
msg << " at root"
|
66
|
+
msg << path.map { |part| "[#{part.inspect}]" }.join
|
67
|
+
end
|
68
|
+
raise DeepMergeError, msg
|
69
|
+
end
|
70
|
+
|
71
|
+
ret
|
72
|
+
end
|
73
|
+
|
74
|
+
def convert(value)
|
75
|
+
value = value.to_s if value.is_a?(Symbol)
|
76
|
+
value = value.downcase if value.is_a?(String)
|
77
|
+
value
|
78
|
+
end
|
79
|
+
|
80
|
+
# Flatten the given data structure to something that's suitable to return
|
81
|
+
# as flat facts.
|
82
|
+
#
|
83
|
+
# @param path [String] The fact path to be prefixed to the given value.
|
84
|
+
# @param structure [Object] The data structure to flatten. Nested hashes
|
85
|
+
# will be recursively flattened, everything else will be returned as-is.
|
86
|
+
#
|
87
|
+
# @return [Hash] The given data structure prefixed with the given path
|
88
|
+
def flatten_structure(path, structure)
|
89
|
+
results = {}
|
90
|
+
|
91
|
+
if structure.is_a? Hash
|
92
|
+
structure.each_pair do |name, value|
|
93
|
+
new_path = "#{path}_#{name}".gsub(/\-|\//, '_')
|
94
|
+
results.merge! flatten_structure(new_path, value)
|
95
|
+
end
|
96
|
+
elsif structure.is_a? Array
|
97
|
+
structure.each_with_index do |value, index|
|
98
|
+
new_path = "#{path}_#{index}"
|
99
|
+
results.merge! flatten_structure(new_path, value)
|
100
|
+
end
|
101
|
+
else
|
102
|
+
results[path] = structure
|
103
|
+
end
|
104
|
+
|
105
|
+
results
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|