Class: Chef::Knife::Ec2ServerList
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::Ec2ServerList
- Defined in:
- lib/chef/knife/ec2_server_list.rb
Constant Summary
Constants inherited from Chef::Knife
Instance Attribute Summary
Attributes inherited from Chef::Knife
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
#h ⇒ Object
45 46 47 |
# File 'lib/chef/knife/ec2_server_list.rb', line 45 def h @highline ||= HighLine.new end |
#run ⇒ Object
49 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 |
# File 'lib/chef/knife/ec2_server_list.rb', line 49 def run require 'fog' require 'highline' require 'net/ssh/multi' require 'readline' $stdout.sync = true connection = Fog::AWS::EC2.new( :aws_access_key_id => Chef::Config[:knife][:aws_access_key_id], :aws_secret_access_key => Chef::Config[:knife][:aws_secret_access_key], :region => config[: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 |