Class: Chef::Knife::Status

Inherits:
Chef::Knife show all
Includes:
Core::FormattingOptions
Defined in:
lib/chef/knife/status.rb

Constant Summary

Constants inherited from Chef::Knife

CHEF_ORGANIZATION_MANAGEMENT, KNIFE_ROOT, OFFICIAL_PLUGINS, OPSCODE_HOSTED_CHEF_ACCESS_CONTROL, VERSION

Instance Attribute Summary

Attributes inherited from Chef::Knife

#name_args, #ui

Instance Method Summary collapse

Methods included from Core::FormattingOptions

included

Methods inherited from Chef::Knife

#api_key, #apply_computed_config, category, chef_config_dir, common_name, #config_file_defaults, #config_file_settings, config_loader, #config_source, #configure_chef, #create_object, #delete_object, dependency_loaders, deps, #format_rest_error, guess_category, #humanize_exception, #humanize_http_exception, inherited, #initialize, list_commands, load_commands, load_config, load_deps, #maybe_setup_fips, #merge_configs, msg, #noauth_rest, #parse_options, reset_config_loader!, reset_subcommands!, #rest, #root_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

Constructor Details

This class inherits a constructor from Chef::Knife

Instance Method Details

#append_to_query(term) ⇒ Object



49
50
51
52
# File 'lib/chef/knife/status.rb', line 49

def append_to_query(term)
  @query << " AND " unless @query.empty?
  @query << term
end

#runObject



54
55
56
57
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
# File 'lib/chef/knife/status.rb', line 54

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"],
             cloud: ["cloud"], 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_by_mins]
    hide_by_mins = 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 - hide_by_mins * 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

  all_nodes.sort_by! { |n| n["ohai_time"] || 0 }
  all_nodes.reverse! if config[:sort_reverse] || config[:sort_status_reverse]

  output(all_nodes)
end