Class: Chef::Knife::Cloud::ServerShowCommand

Inherits:
Command show all
Defined in:
lib/chef/knife/cloud/server/show_command.rb

Instance Attribute Summary

Attributes inherited from Command

#custom_arguments, #service

Instance Method Summary collapse

Methods inherited from Command

#run

Methods included from Helpers

#after_exec_command, #before_exec_command, #create_service_instance, #locate_config_value, #msg_pair, #pretty_key, #set_default_config, #validate!

Constructor Details

#initialize(argv = []) ⇒ ServerShowCommand

Returns a new instance of ServerShowCommand.



26
27
28
29
30
# File 'lib/chef/knife/cloud/server/show_command.rb', line 26

def initialize(argv = [])
  super argv
  # columns_with_info is array of hash with label, key and attribute extraction callback, ex [{:label => "Label text", :key => 'key', value_callback => callback_method to extract/format the required value}, ...]
  @columns_with_info = []
end

Instance Method Details

#execute_commandObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/chef/knife/cloud/server/show_command.rb', line 42

def execute_command
  server = service.get_server(locate_config_value(:instance_id))
  if server.nil?
    error_message = "Server doesn't exists for this #{locate_config_value(:instance_id)} instance id."
    ui.error(error_message)
    raise CloudExceptions::ServerShowError, error_message
  else
    service.server_summary(server, @columns_with_info)
  end
end

#validate_params!Object



32
33
34
35
36
37
38
39
40
# File 'lib/chef/knife/cloud/server/show_command.rb', line 32

def validate_params!
  errors = []
  config[:instance_id] = @name_args.first
  if locate_config_value(:instance_id).nil?
    errors << "You must provide a valid Instance Id"
  end
  error_message = ""
  raise CloudExceptions::ValidationError, error_message if errors.each { |e| ui.error(e); error_message = "#{error_message} #{e}." }.any?
end