Class: Chef::Knife::Cloud::ServerListCommand
- Inherits:
-
ResourceListCommand
- Object
- Chef::Knife
- Command
- ResourceListCommand
- Chef::Knife::Cloud::ServerListCommand
- Defined in:
- lib/chef/knife/cloud/server/list_command.rb
Instance Attribute Summary
Attributes inherited from Command
Instance Method Summary collapse
- #before_exec_command ⇒ Object
- #format_server_state(state) ⇒ Object
-
#get_resource_col_val(server) ⇒ Object
Override from base to display chef node data along with server list display.
- #query_resource ⇒ Object
Methods inherited from ResourceListCommand
#data_sort, #execute_command, #initialize, #is_resource_filtered?, #list
Methods inherited from Command
Methods included from Helpers
#after_exec_command, #create_service_instance, #execute_command, #msg_pair, #pretty_key, #set_default_config, #validate!, #validate_params!
Constructor Details
This class inherits a constructor from Chef::Knife::Cloud::ResourceListCommand
Instance Method Details
#before_exec_command ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/chef/knife/cloud/server/list_command.rb', line 9 def before_exec_command if config[:chef_data] begin # Chef::Node.list(inflate = true) to use Solr search. @node_list = Chef::Node.list(true) rescue Errno::ECONNREFUSED => e = "Connection error with Chef server. #{e}" ui.warn() raise CloudExceptions::ChefServerError, end @chef_data_col_info = [ { label: "Chef Node Name", key: "name" }, { label: "Environment", key: "chef_environment" }, { label: "FQDN", key: "fqdn" }, { label: "Runlist", key: "run_list" }, { label: "Tags", key: "tags" }, { label: "Platform", key: "platform" }, ] if config[:chef_node_attribute] @chef_data_col_info << { label: "#{config[:chef_node_attribute]}", key: "#{config[:chef_node_attribute]}" } end @columns_with_info.concat(@chef_data_col_info) end end |
#format_server_state(state) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/chef/knife/cloud/server/list_command.rb', line 68 def format_server_state(state) state = state.to_s.downcase state_color = case state when "shutting-down", "terminated", "stopping", "stopped", "error", "shutoff" :red when "pending", "build", "paused", "suspended", "hard_reboot" :yellow else :green end ui.color(state, state_color) end |
#get_resource_col_val(server) ⇒ Object
Override from base to display chef node data along with server list display.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/chef/knife/cloud/server/list_command.rb', line 37 def get_resource_col_val(server) list = [] @columns_with_info.each do |col_info| if config[:chef_data] && @chef_data_col_info.include?(col_info) server_name = service.get_server_name(server) if @node_list.include?(server_name) node = @node_list[server_name] # Raise serverlisting error on invalid chef_node_attribute. if col_info[:key] == config[:chef_node_attribute] && ! node.attribute?(col_info[:key]) = "The Node does not have a #{col_info[:key]} attribute." ui.error() raise CloudExceptions::CloudAPIException, else value = (col_info[:value_callback].nil? ? node.send(col_info[:key]).to_s : col_info[:value_callback].call(node.send(col_info[:key]))) end else # Set chef data value for those server which is not part chef server. value = "" end else value = (col_info[:value_callback].nil? ? server.send(col_info[:key]).to_s : col_info[:value_callback].call(server.send(col_info[:key]))) end list << value end list end |
#query_resource ⇒ Object
64 65 66 |
# File 'lib/chef/knife/cloud/server/list_command.rb', line 64 def query_resource @service.list_servers end |