From: Martyn Taylor <mtaylor(a)redhat.com>
REBASE
REBASE
---
lib/base_command.rb | 5 +++++
lib/config_parser.rb | 10 +++++++++-
lib/delete_command.rb | 26 ++++++++++++++++++++++++++
3 files changed, 40 insertions(+), 1 deletions(-)
diff --git a/lib/base_command.rb b/lib/base_command.rb
index f1adcad..ea91ec5 100644
--- a/lib/base_command.rb
+++ b/lib/base_command.rb
@@ -71,6 +71,11 @@ module Aeolus
schema.validate(doc)
end
+ def is_uuid?(id)
+ uuid = Regexp.new('[\w]{8}[-][\w]{4}[-][\w]{4}[-][\w]{4}[-][\w]{12}')
+ uuid.match(id).nil? ? false : true
+ end
+
private
def load_config
begin
diff --git a/lib/config_parser.rb b/lib/config_parser.rb
index a1d440c..e8a32ed 100644
--- a/lib/config_parser.rb
+++ b/lib/config_parser.rb
@@ -119,6 +119,7 @@ module Aeolus
@options[:targetimage] = id
end
opts.on('-D', '--providerimage ID', 'delete provider
image') do |id|
+ @options[:subcommand] = :provider_image
@options[:providerimage] = id
end
@@ -205,7 +206,14 @@ module Aeolus
end
def delete
- "Not implemented"
+ if @options[:subcommand].nil?
+ # TODO: Pull out Print Usage into seporate method, and print
+ puts "Could not find subcommand for delete, run `./aeolus-image --help`
for usage instructions"
+ exit(1)
+ else
+ delete_command = DeleteCommand.new(@options)
+ delete_command.send(@options[:subcommand])
+ end
end
end
end
diff --git a/lib/delete_command.rb b/lib/delete_command.rb
index ba63732..3eb121b 100644
--- a/lib/delete_command.rb
+++ b/lib/delete_command.rb
@@ -4,6 +4,32 @@ module Aeolus
def initialize(opts={}, logger=nil)
super(opts, logger)
end
+
+ def provider_image
+ delete_provider_image(@options[:providerimage])
+ end
+
+ private
+ def delete_provider_image(provider_image)
+ if !(is_uuid?(provider_image))
+ puts "Error: '" + provider_image + "' is not a valid
Provider Image ID"
+ exit(1)
+ end
+
+ begin
+ iwhd['/provider_images/' + provider_image].delete
+ puts "Provider Image: '" + provider_image + "' was
succesfully deleted"
+ exit(0)
+ rescue RestClient::ResourceNotFound
+ puts "Error: Could not find Provider Image with ID: '" +
provider_image + "'"
+ exit(1)
+ rescue => e
+ puts "Error: Could not delete Provider Image with ID: '" +
provider_image + "'"
+ puts e.inspect
+ exit(1)
+ end
+ end
end
+
end
end
--
1.7.4