On 08/05/2011 11:44 AM, mtaylor(a)redhat.com wrote:
From: Martyn Taylor<mtaylor(a)redhat.com>
---
lib/config_parser.rb | 4 ++++
lib/delete_command.rb | 29 +++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/lib/config_parser.rb b/lib/config_parser.rb
index 0a8f647..af2c98e 100644
--- a/lib/config_parser.rb
+++ b/lib/config_parser.rb
@@ -115,6 +115,10 @@ module Aeolus
opts.separator ""
opts.separator "Delete options:"
+ opts.on('-I', '--image ID', 'delete build image and
associated objects') do |id|
+ @options[:subcommand] = :image
+ @options[:image] = id
+ end
opts.on('-B', '--build ID', 'delete build and associated
objects') do |id|
@options[:subcommand] = :build
@options[:build] = id
diff --git a/lib/delete_command.rb b/lib/delete_command.rb
index 28d1ad7..543a820 100644
--- a/lib/delete_command.rb
+++ b/lib/delete_command.rb
@@ -53,6 +53,22 @@ module Aeolus
end
end
+ def image
+ check_id(@options[:image], "Image")
+ begin
+ delete_image(@options[:image])
+ puts "Image: '" + @options[:image] + "' was succesfully
deleted"
+ exit(0)
+ rescue RestClient::ResourceNotFound
+ puts "Error: Could not find Image with ID: '" + @options[:image]
+ "'"
+ exit(1)
+ rescue => e
+ puts "Error: Could not delete Image with ID: '" +
@options[:image] + "'"
+ puts e.inspect
+ exit(1)
+ end
+ end
+
private
def delete_provider_image(provider_image)
iwhd['/provider_images/' + provider_image].delete
@@ -84,6 +100,19 @@ module Aeolus
iwhd['/builds/' + build].delete
end
+ def delete_image(image)
+ # Delete Builds
+ list_command = ListCommand.new
+ list_command.list_builds(image).each do |build|
+ begin
+ delete_build(build)
+ rescue
+ end
+ end
+ # Delete Image
+ iwhd['/images/' + image].delete
+ end
+
def check_id(uuid, type)
if !(is_uuid?(uuid))
puts "Error: '" + uuid + "' is not a valid " +
type + " ID"
ACK, one error I hit (and we discussed on IRC):
when listing images and bucket 'images' doesn't exist, aeolus-image
throws error, you suggested this fix in lib/list_command.rb:
def images
- check_bucket_exists("images")
images = [["IMAGE ID", "LASTEST PUSHED BUILD",
"NAME",
"TARGET", "OS", "OS VERSION", "ARCH",
"DESCRIPTION"]]
+ if check_bucket_exists("images").nil?
+ format_print(images)
+ quit(0)
+ end