Class: Chef::Knife::Status
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::Status
- Includes:
- Core::NodeFormattingOptions
- Defined in:
- lib/chef/knife/status.rb
Instance Attribute Summary
Attributes inherited from Chef::Knife
Instance Method Summary collapse
Methods included from Core::NodeFormattingOptions
Methods inherited from Chef::Knife
#api_key, #apply_computed_config, category, chef_config_dir, common_name, #config_file_settings, config_loader, #configure_chef, #create_object, #delete_object, dependency_loaders, deps, #format_rest_error, guess_category, #humanize_exception, #humanize_http_exception, inherited, #initialize, load_commands, load_config, load_deps, #maybe_setup_fips, #merge_configs, msg, #noauth_rest, #parse_options, reset_config_loader!, reset_subcommands!, #rest, run, #run_with_pretty_exceptions, #server_url, #show_usage, snake_case_name, subcommand_category, subcommand_class_from, subcommand_files, subcommand_loader, subcommands, subcommands_by_category, #test_mandatory_field, ui, unnamed?, use_separate_defaults?, #username
Methods included from Mixin::ConvertToClassName
#constantize, #convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #normalize_snake_case_name, #snake_case_basename
Methods included from Mixin::PathSanity
Constructor Details
This class inherits a constructor from Chef::Knife
Instance Method Details
#append_to_query(term) ⇒ Object
53 54 55 56 |
# File 'lib/chef/knife/status.rb', line 53 def append_to_query(term) @query << " AND " unless @query.empty? @query << term end |
#run ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/chef/knife/status.rb', line 58 def run ui.use_presenter Knife::Core::StatusPresenter if config[:long_output] opts = {} else opts = { filter_result: { name: ["name"], ipaddress: ["ipaddress"], ohai_time: ["ohai_time"], ec2: ["ec2"], run_list: ["run_list"], platform: ["platform"], platform_version: ["platform_version"], chef_environment: ["chef_environment"] } } end @query ||= "" append_to_query(@name_args[0]) if @name_args[0] append_to_query("chef_environment:#{config[:environment]}") if config[:environment] if config[:hide_healthy] ui.warn("-H / --hide-healthy is deprecated. Use --hide-by-mins MINS instead") time = Time.now.to_i # AND NOT is not valid lucene syntax, so don't use append_to_query @query << " " unless @query.empty? @query << "NOT ohai_time:[#{(time - 60 * 60)} TO #{time}]" end if config[:hide_by_mins] hidemins = config[:hide_by_mins].to_i time = Time.now.to_i # AND NOT is not valid lucene syntax, so don't use append_to_query @query << " " unless @query.empty? @query << "NOT ohai_time:[#{(time - hidemins * 60)} TO #{time}]" end @query = @query.empty? ? "*:*" : @query all_nodes = [] q = Chef::Search::Query.new Chef::Log.info("Sending query: #{@query}") q.search(:node, @query, opts) do |node| all_nodes << node end output(all_nodes.sort { |n1, n2| if config[:sort_reverse] || Chef::Config[:knife][:sort_status_reverse] (n2["ohai_time"] || 0) <=> (n1["ohai_time"] || 0) else (n1["ohai_time"] || 0) <=> (n2["ohai_time"] || 0) end }) end |