Permalink
Browse files

Add 'destroy' command (to cleanup after tests)

  • Loading branch information...
jasonrudolph committed Oct 1, 2012
1 parent 6679ea1 commit 7d1a98e4c4c3feacb3592a217e6f943590b3acaa
Showing with 35 additions and 0 deletions.
  1. +14 −0 bin/elzar
  2. +16 −0 lib/elzar/cli.rb
  3. +5 −0 lib/elzar/compute.rb
View
@@ -56,6 +56,20 @@ command :cook do |c|
end
end
+desc 'Destroys the given EC2 instance'
+arg_name 'instance_id' # TODO raise error if arg not given
+command :destroy do |c|
+ c.flag :aws_config_dir,
+ :default_value => Elzar::AwsConfig::DEFAULT_CONFIG_DIR,
+ :arg_name => 'aws_config_dir',
+ :desc => "The directory containing your AWS config files"
+
+ c.action do |global_options,options,args|
+ instance_id = args.first
+ Elzar::Cli::Destroy.run(instance_id, global_options.merge(options))
+ end
+end
+
pre do |global,command,options,args|
# Pre logic here
# Return true to proceed; false to abourt and not call the
View
@@ -123,5 +123,21 @@ def run
MSG
end
end
+
+ class Destroy < Runner
+ attr_reader :instance_id
+
+ required_argument :instance_id
+
+ def initialize(instance_id, options = {})
+ @instance_id = instance_id
+ @aws_config_dir = options[:aws_config_dir]
+ end
+
+ def run
+ Elzar::Compute.destroy!(instance_id, aws_config)
+ notify "Destroyed instance #{instance_id}"
+ end
+ end
end
end
View
@@ -32,6 +32,11 @@ def self.converge!(instance_id, aws_config)
[slushy_instance.instance_id, slushy_instance.server.public_ip_address]
end
+ def self.destroy!(instance_id, aws_config)
+ slushy_instance = slushy_instance_for(instance_id, aws_config)
+ slushy_instance.terminate
+ end
+
private
def self.fog_connection(aws_config)

0 comments on commit 7d1a98e

Please sign in to comment.