Module: Facter
- Includes:
- ApiDebugger
- Defined in:
- lib/custom_facts/util/fact.rb,
lib/facter.rb,
lib/util/file_helper.rb,
lib/framework/cli/cli.rb,
lib/models/loaded_fact.rb,
lib/resolvers/utils/ssh.rb,
lib/models/resolved_fact.rb,
lib/models/searched_fact.rb,
lib/resolvers/partitions.rb,
lib/framework/utils/utils.rb,
lib/resolvers/windows/ssh.rb,
lib/framework/core/options.rb,
lib/models/fact_collection.rb,
lib/resolvers/dmi_resolver.rb,
lib/resolvers/ssh_resolver.rb,
lib/resolvers/base_resolver.rb,
lib/resolvers/disk_resolver.rb,
lib/resolvers/lpar_resolver.rb,
lib/resolvers/path_resolver.rb,
lib/resolvers/ruby_resolver.rb,
lib/resolvers/wpar_resolver.rb,
lib/framework/logging/logger.rb,
lib/resolvers/agent_resolver.rb,
lib/resolvers/aix/partitions.rb,
lib/resolvers/debian_version.rb,
lib/resolvers/uname_resolver.rb,
lib/facts_utils/uptime_parser.rb,
lib/resolvers/aix/mountpoints.rb,
lib/resolvers/augeas_resolver.rb,
lib/resolvers/memory_resolver.rb,
lib/resolvers/uptime_resolver.rb,
lib/framework/core/fact_filter.rb,
lib/resolvers/selinux_resolver.rb,
lib/resolvers/sw_vers_resolver.rb,
lib/custom_facts/core/aggregate.rb,
lib/custom_facts/core/execution.rb,
lib/facts_utils/bytes_converter.rb,
lib/framework/config/block_list.rb,
lib/framework/core/fact_manager.rb,
lib/resolvers/hostname_resolver.rb,
lib/resolvers/identity_resolver.rb,
lib/resolvers/os_level_resolver.rb,
lib/resolvers/timezone_resolver.rb,
lib/resolvers/utils/fingerprint.rb,
lib/custom_facts/util/resolution.rb,
lib/framework/core/session_cache.rb,
lib/resolvers/aix/ffi/ffi_helper.rb,
lib/framework/core/fact_augmenter.rb,
lib/framework/logging/multilogger.rb,
lib/resolvers/aix/utils/odm_query.rb,
lib/resolvers/macosx/dmi_resolver.rb,
lib/resolvers/os_release_resolver.rb,
lib/resolvers/processors_resolver.rb,
lib/framework/config/config_reader.rb,
lib/framework/parsers/query_parser.rb,
lib/resolvers/eos_release_resolver.rb,
lib/resolvers/filesystems_resolver.rb,
lib/resolvers/lsb_release_resolver.rb,
lib/resolvers/mountpoints_resolver.rb,
lib/resolvers/solaris/zfs_resolver.rb,
lib/resolvers/aix/hardware_resolver.rb,
lib/resolvers/aix/os_level_resolver.rb,
lib/resolvers/fips_enabled_resolver.rb,
lib/resolvers/solaris/zone_resolver.rb,
lib/resolvers/suse_release_resolver.rb,
lib/resolvers/windows/fips_resolver.rb,
lib/custom_facts/core/execution/base.rb,
lib/resolvers/facterversion_resolver.rb,
lib/resolvers/load_averages_resolver.rb,
lib/resolvers/solaris/zpool_resolver.rb,
lib/custom_facts/core/execution/posix.rb,
lib/resolvers/aix/filesystem_resolver.rb,
lib/resolvers/aix/networking_resolver.rb,
lib/resolvers/puppet_version_resolver.rb,
lib/resolvers/redhat_release_resolver.rb,
lib/resolvers/utils/filesystem_helper.rb,
lib/resolvers/windows/kernel_resolver.rb,
lib/resolvers/windows/memory_resolver.rb,
lib/resolvers/windows/netkvm_resolver.rb,
lib/resolvers/windows/uptime_resolver.rb,
lib/facts_utils/windows_release_finder.rb,
lib/custom_facts/core/execution/windows.rb,
lib/facts_utils/bytes_to_human_readable.rb,
lib/framework/core/options/option_store.rb,
lib/resolvers/aix/architecture_resolver.rb,
lib/resolvers/macosx/ipaddress_resolver.rb,
lib/resolvers/macosx/processor_resolver.rb,
lib/resolvers/networking_linux_resolver.rb,
lib/resolvers/solaris/solaris_zone_name.rb,
lib/resolvers/windows/dmi_bios_resolver.rb,
lib/resolvers/windows/identity_resolver.rb,
lib/resolvers/windows/system32_resolver.rb,
lib/resolvers/aix/load_averages_resolver.rb,
lib/resolvers/solaris/ipaddress_resolver.rb,
lib/framework/formatters/formatter_helper.rb,
lib/resolvers/macosx/filesystems_resolver.rb,
lib/resolvers/macosx/mountpoints_resolver.rb,
lib/resolvers/macosx/swap_memory_resolver.rb,
lib/resolvers/windows/networking_resolver.rb,
lib/resolvers/windows/processors_resolver.rb,
lib/framework/core/fact/internal/core_fact.rb,
lib/framework/formatters/formatter_factory.rb,
lib/resolvers/solaris/filesystems_resolver.rb,
lib/framework/core/fact_loaders/fact_loader.rb,
lib/resolvers/macosx/load_averages_resolver.rb,
lib/resolvers/macosx/system_memory_resolver.rb,
lib/framework/core/options/options_validator.rb,
lib/framework/formatters/json_fact_formatter.rb,
lib/framework/formatters/yaml_fact_formatter.rb,
lib/framework/formatters/hocon_fact_formatter.rb,
lib/resolvers/macosx/system_profiler_resolver.rb,
lib/resolvers/windows/virtualization_resolver.rb,
lib/framework/core/options/config_file_options.rb,
lib/framework/formatters/legacy_fact_formatter.rb,
lib/resolvers/windows/product_release_resolver.rb,
lib/framework/core/fact_loaders/class_discoverer.rb,
lib/resolvers/solaris/solaris_os_release_resolver.rb,
lib/resolvers/windows/dmi_computersystem_resolver.rb,
lib/resolvers/windows/win_os_description_resolver.rb,
lib/framework/core/fact_loaders/external_fact_loader.rb,
lib/framework/core/fact_loaders/internal_fact_loader.rb,
lib/resolvers/windows/hardware_architecture_resolver.rb,
lib/framework/core/fact/external/external_fact_manager.rb,
lib/framework/core/fact/internal/internal_fact_manager.rb
Overview
CuAt (Customized Attributes) non-default attribute values CuDv (Customized Devices) the devices present on this machine PdAt (Predefined Attributes) default values for all device attributes PdDv (Predefined Devices) the list of all devices supported by this release of AIX
Defined Under Namespace
Modules: Aix, Core, FactAugmenter, FactsUtils, FilesystemHelper, OptionsValidator, Resolvers, Util, Utils Classes: BlockList, BytesToHumanReadable, ClassDiscoverer, Cli, ConfigFileOptions, ConfigReader, CoreFact, ExternalFactLoader, ExternalFactManager, FactCollection, FactFilter, FactLoader, FactManager, FingerPrint, FormatterFactory, FormatterHelper, HoconFactFormatter, InternalFactLoader, InternalFactManager, JsonFactFormatter, LegacyFactFormatter, LoadedFact, Log, MultiLogger, ODMQuery, OptionStore, Options, QueryParser, ResolveCustomFactError, ResolvedFact, SearchedFact, SessionCache, Ssh, UptimeParser, WindowsReleaseFinder, YamlFactFormatter
Constant Summary collapse
- RED =
31
- DEFAULT_LOG_LEVEL =
:warn
Class Method Summary collapse
-
.[](name) ⇒ Facter::Util::Fact?
Alias method for Facter.fact().
-
.add(name, options = {}, &block) ⇒ Facter::Util::Fact
Add custom facts to fact collection.
-
.clear ⇒ nil
Clears all cached values and removes all facts from memory.
- .clear_messages ⇒ Object
- .core_value(user_query) ⇒ Object
-
.debug(msg) ⇒ nil
Prints out a debug message when debug option is set to true.
-
.debugging(debug_bool) ⇒ type
Enable or disable debugging.
-
.debugging? ⇒ bool
Check whether debuging is enabled.
-
.fact(user_query) ⇒ Facter::Util::Fact?
Returns a fact object by name.
- .log_exception(exception, message = :default) ⇒ Object
- .on_message(&block) ⇒ Object
-
.reset ⇒ nil
Reset search paths for custom and external facts If config file is set custom and external facts will be reloaded.
-
.search(*dirs) ⇒ void
Register directories to be searched for custom facts.
-
.search_external(dirs) ⇒ void
Registers directories to be searched for external facts.
-
.search_external_path ⇒ Array<String>
Returns the registered search directories.for external facts.
-
.search_path ⇒ Array<String>
Returns the registered search directories for custom facts.
-
.to_hash ⇒ FactCollection
Gets a hash mapping fact names to their values The hash contains core facts, legacy facts, custom facts and external facts (all facts that can be resolved).
-
.to_user_output(cli_options, *args) ⇒ Array
private
Gets a hash mapping fact names to their values.
-
.trace(bool) ⇒ type
Enable or disable trace.
-
.trace? ⇒ bool
Check whether printing stack trace is enabled.
-
.value(user_query) ⇒ String
Gets the value for a fact.
-
.version ⇒ String
Returns Facter version.
Methods included from ApiDebugger
Class Method Details
.[](name) ⇒ Facter::Util::Fact?
Alias method for Facter.fact()
32 33 34 |
# File 'lib/facter.rb', line 32 def [](name) fact(name) end |
.add(name, options = {}, &block) ⇒ Facter::Util::Fact
Add custom facts to fact collection
47 48 49 50 51 |
# File 'lib/facter.rb', line 47 def add(name, = {}, &block) [:fact_type] = :custom LegacyFacter.add(name, , &block) LegacyFacter.collection.invalidate_custom_facts end |
.clear ⇒ nil
Clears all cached values and removes all facts from memory.
58 59 60 61 62 63 |
# File 'lib/facter.rb', line 58 def clear @already_searched = {} LegacyFacter.clear LegacyFacter.collection.invalidate_custom_facts LegacyFacter.collection.reload_custom_facts end |
.clear_messages ⇒ Object
21 22 23 |
# File 'lib/facter.rb', line 21 def @logger.debug('clear_messages is not implemented') end |
.core_value(user_query) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/facter.rb', line 65 def core_value(user_query) user_query = user_query.to_s resolved_facts = Facter::FactManager.instance.resolve_core([user_query]) fact_collection = FactCollection.new.build_fact_collection!(resolved_facts) splitted_user_query = Facter::Utils.split_user_query(user_query) fact_collection.dig(*splitted_user_query) end |
.debug(msg) ⇒ nil
Prints out a debug message when debug option is set to true
79 80 81 82 83 84 |
# File 'lib/facter.rb', line 79 def debug(msg) return unless debugging? @logger.debug(msg) nil end |
.debugging(debug_bool) ⇒ type
Enable or disable debugging
105 106 107 |
# File 'lib/facter.rb', line 105 def debugging(debug_bool) Facter::Options[:debug] = debug_bool end |
.debugging? ⇒ bool
Check whether debuging is enabled
95 96 97 |
# File 'lib/facter.rb', line 95 def debugging? Options[:debug] end |
.fact(user_query) ⇒ Facter::Util::Fact?
Returns a fact object by name. If you use this, you still have to call ‘value` on it to retrieve the actual value.
119 120 121 122 123 124 |
# File 'lib/facter.rb', line 119 def fact(user_query) user_query = user_query.to_s resolve_fact(user_query) @already_searched[user_query] end |
.log_exception(exception, message = :default) ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/facter.rb', line 259 def log_exception(exception, = :default) arr = [] if == :default arr << exception. elsif arr << end if @trace arr << 'backtrace:' arr.concat(exception.backtrace) end @logger.error(arr.flatten.join("\n")) end |
.on_message(&block) ⇒ Object
86 87 88 |
# File 'lib/facter.rb', line 86 def (&block) Facter::Log.(&block) end |
.reset ⇒ nil
Reset search paths for custom and external facts If config file is set custom and external facts will be reloaded
132 133 134 135 136 137 138 139 |
# File 'lib/facter.rb', line 132 def reset LegacyFacter.reset Options[:custom_dir] = [] Options[:external_dir] = [] LegacyFacter.search(*Options.custom_dir) LegacyFacter.search_external(Options.external_dir) nil end |
.search(*dirs) ⇒ void
This method returns an undefined value.
Register directories to be searched for custom facts. The registered directories must be absolute paths or they will be ignored.
149 150 151 152 |
# File 'lib/facter.rb', line 149 def search(*dirs) Options[:custom_dir] += dirs LegacyFacter.search(*dirs) end |
.search_external(dirs) ⇒ void
This method returns an undefined value.
Registers directories to be searched for external facts.
161 162 163 164 |
# File 'lib/facter.rb', line 161 def search_external(dirs) Options[:external_dir] += dirs LegacyFacter.search_external(dirs) end |
.search_external_path ⇒ Array<String>
Returns the registered search directories.for external facts.
171 172 173 |
# File 'lib/facter.rb', line 171 def search_external_path Options.external_dir end |
.search_path ⇒ Array<String>
Returns the registered search directories for custom facts.
180 181 182 |
# File 'lib/facter.rb', line 180 def search_path Options.custom_dir end |
.to_hash ⇒ FactCollection
Gets a hash mapping fact names to their values The hash contains core facts, legacy facts, custom facts and external facts (all facts that can be resolved).
190 191 192 193 194 195 196 |
# File 'lib/facter.rb', line 190 def to_hash log_blocked_facts resolved_facts = Facter::FactManager.instance.resolve_facts Facter::SessionCache.invalidate_all_caches Facter::FactCollection.new.build_fact_collection!(resolved_facts) end |
.to_user_output(cli_options, *args) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Gets a hash mapping fact names to their values
244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/facter.rb', line 244 def to_user_output(, *args) = .map { |(k, v)| [k.to_sym, v] }.to_h Facter::Options.init_from_cli(, args) @logger.info("executed with command line: #{ARGV.drop(1).join(' ')}") log_blocked_facts resolved_facts = Facter::FactManager.instance.resolve_facts(args) SessionCache.invalidate_all_caches fact_formatter = Facter::FormatterFactory.build(Facter::Options.get) status = error_check(args, resolved_facts) [fact_formatter.format(resolved_facts), status || 0] end |
.trace(bool) ⇒ type
Enable or disable trace
213 214 215 |
# File 'lib/facter.rb', line 213 def trace(bool) @trace = bool end |
.trace? ⇒ bool
Check whether printing stack trace is enabled
203 204 205 |
# File 'lib/facter.rb', line 203 def trace? @trace end |
.value(user_query) ⇒ String
Gets the value for a fact. Returns ‘nil` if no such fact exists.
223 224 225 226 227 |
# File 'lib/facter.rb', line 223 def value(user_query) user_query = user_query.to_s resolve_fact(user_query) @already_searched[user_query]&.value end |
.version ⇒ String
Returns Facter version
234 235 236 237 |
# File 'lib/facter.rb', line 234 def version version_file = ::File.join(ROOT_DIR, 'VERSION') ::File.read(version_file).strip end |