Class: Chef::Knife::Ec2ServerDelete

Inherits:
Chef::Knife show all
Defined in:
lib/chef/knife/ec2_server_delete.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



45
46
47
# File 'lib/chef/knife/ec2_server_delete.rb', line 45

def h
  @highline ||= HighLine.new
end

#runObject



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
# File 'lib/chef/knife/ec2_server_delete.rb', line 49

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

  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]
  )

  @name_args.each do |instance_id|
    server = connection.servers.get(instance_id)

    puts "#{h.color("Instance ID", :cyan)}: #{server.id}"
    puts "#{h.color("Flavor", :cyan)}: #{server.flavor_id}"
    puts "#{h.color("Image", :cyan)}: #{server.image_id}"
    puts "#{h.color("Availability Zone", :cyan)}: #{server.availability_zone}"
    puts "#{h.color("Security Groups", :cyan)}: #{server.groups.join(", ")}"
    puts "#{h.color("SSH Key", :cyan)}: #{server.key_name}"
    puts "#{h.color("Public DNS Name", :cyan)}: #{server.dns_name}"
    puts "#{h.color("Public IP Address", :cyan)}: #{server.ip_address}"
    puts "#{h.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
    puts "#{h.color("Private IP Address", :cyan)}: #{server.private_ip_address}"

    puts "\n"
    confirm("Do you really want to delete this server")

    server.destroy

    Chef::Log.warn("Deleted server #{server.id}")
  end
end