Class: Chef::Knife::Ec2ServerList

Inherits:
Chef::Knife show all
Defined in:
lib/chef/knife/ec2_server_list.rb

Constant Summary

Constants inherited from Chef::Knife

DEFAULT_SUBCOMMAND_FILES

Instance Attribute Summary

Attributes inherited from Chef::Knife

#name_args

Instance Method Summary collapse

Methods inherited from Chef::Knife

#ask_question, #bulk_delete, category, #configure_chef, #confirm, #create_object, #delete_object, #edit_data, #edit_object, #file_exists_and_is_readable?, #format_for_display, #format_list_for_display, guess_category, inherited, #initialize, list_commands, load_commands, #load_from_file, #msg, msg, #output, #parse_options, #pretty_print, #rest, run, #show_usage, snake_case_name, #stdin, #stdout, subcommand_category, subcommand_class_from, subcommands, subcommands_by_category, unnamed?

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename

Constructor Details

This class inherits a constructor from Chef::Knife

Instance Method Details

#hObject



46
47
48
# File 'lib/chef/knife/ec2_server_list.rb', line 46

def h
  @highline ||= HighLine.new
end

#runObject



50
51
52
53
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
# File 'lib/chef/knife/ec2_server_list.rb', line 50

def run 
  require 'fog'
  require 'highline'
  require 'net/ssh/multi'
  require 'readline'

  $stdout.sync = true

  connection = Fog::AWS::Compute.new(
    :aws_access_key_id => Chef::Config[:knife][:aws_access_key_id],
    :aws_secret_access_key => Chef::Config[:knife][:aws_secret_access_key],
    :region => Chef::Config[:knife][:region]
  )

  server_list = [ 
    h.color('Instance ID', :bold), 
    h.color('Public IP', :bold), 
    h.color('Private IP', :bold),
    h.color('Flavor', :bold),
    h.color('Image', :bold),
    h.color('Security Groups', :bold),
    h.color('State', :bold)
  ]
  connection.servers.all.each do |server|
    server_list << server.id.to_s
    server_list << (server.ip_address == nil ? "" : server.ip_address)
    server_list << (server.private_ip_address == nil ? "" : server.private_ip_address) 
    server_list << (server.flavor_id == nil ? "" : server.flavor_id)
    server_list << (server.image_id == nil ? "" : server.image_id)
    server_list << server.groups.join(", ")
    server_list << server.state
  end
  puts h.list(server_list, :columns_across, 7)

end