On Fri, 2011-08-05 at 10:44 +0100, mtaylor(a)redhat.com wrote:
From: Martyn Taylor <mtaylor(a)redhat.com>
This is structured differently to allow other commands to access the list of provider
images. In particular in delete targetimage, so that all the provider images of this
tartgetimage are also deleted.
---
lib/config_parser.rb | 2 +-
lib/list_command.rb | 31 +++++++++++++++++++++++++++++--
2 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/lib/config_parser.rb b/lib/config_parser.rb
index 8e98971..a1d440c 100644
--- a/lib/config_parser.rb
+++ b/lib/config_parser.rb
@@ -85,7 +85,7 @@ module Aeolus
@options[:id] = id
end
opts.on('-P', '--providerimages ID', 'Retrieve the
provider images from a target image') do |id|
- @options[:subcommand] = :targetimages
+ @options[:subcommand] = :providerimages
@options[:id] = id
end
opts.on('-g', '--targets', 'Retrieve the values available
for the --target parameter') do
diff --git a/lib/list_command.rb b/lib/list_command.rb
index 062adbb..ca7308a 100644
--- a/lib/list_command.rb
+++ b/lib/list_command.rb
@@ -46,7 +46,7 @@ module Aeolus
end
def targetimages
- check_bucket_exists("target_images")
+ check_bucket_exists("target-images")
This change doesn't look right to me ^. I just looked at my iwhd, and
the bucket uses '_', not '-', as does the code below. Has something
changed that I have not seen yet?
doc = Nokogiri::XML iwhd['/target_images'].get
doc.xpath("/objects/object/key").each do |target_image|
begin
@@ -59,6 +59,33 @@ module Aeolus
quit(0)
end
+ def providerimages
+ providerimages = [["Provider Image ID"]]
+ list_providerimages(@options[:id]).each do |pi|
+ providerimages << [pi]
+ end
+ format_print(providerimages)
+ quit(0)
+ end
+
+ def list_providerimages(targetimage)
+ providerimages = []
+ if check_bucket_exists("provider_images").nil?
+ return providerimages
+ end
+
+ doc = Nokogiri::XML iwhd['/provider_images'].get
+ doc.xpath("/objects/object/key").each do |provider_image|
+ begin
+ if iwhd['/provider_images/' + provider_image.text +
"/target_image"].get == targetimage
+ providerimages << provider_image.text
+ end
+ rescue RestClient::ResourceNotFound
+ end
+ end
+ providerimages
+ end
+
def targets
targets = [["NAME", "TARGET CODE"]]
targets << ["Mock", "mock"]
@@ -144,7 +171,7 @@ module Aeolus
begin
iwhd["/" + bucket].get
rescue
- quit(0)
+ nil
end
end
end