From: Martyn Taylor mtaylor@redhat.com
--- .../aeolus-image/lib/config_parser.rb | 10 +++++++++- .../image_factory/aeolus-image/lib/list_command.rb | 5 +++++ .../aeolus-image/spec/list_command_spec.rb | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletions(-) create mode 100644 services/image_factory/aeolus-image/spec/list_command_spec.rb
diff --git a/services/image_factory/aeolus-image/lib/config_parser.rb b/services/image_factory/aeolus-image/lib/config_parser.rb index 3ee8b1e..91b637a 100644 --- a/services/image_factory/aeolus-image/lib/config_parser.rb +++ b/services/image_factory/aeolus-image/lib/config_parser.rb @@ -1,3 +1,4 @@ +require 'rubygems' require 'optparse' require 'logger' require 'base_command' @@ -171,7 +172,14 @@ module Aeolus # For the list example above, that object would call a method 'images' based on the item # @options[:subcommand] being :images, so internally that class may do something like: # self.send(@options[:subcommand]) - "Not implemented" + if !@options['subcommand'].nil? + list_command = ListCommand.new(@options) + list_command.send(@options[:subcommand]) + else + # TODO: Pull out Print Usage into seporate method, and print + puts "Could not find subcommand for list, run `./aeolus-image --help` for usage instructions" + exit(1) + end end
def build diff --git a/services/image_factory/aeolus-image/lib/list_command.rb b/services/image_factory/aeolus-image/lib/list_command.rb index 35f6927..9939f74 100644 --- a/services/image_factory/aeolus-image/lib/list_command.rb +++ b/services/image_factory/aeolus-image/lib/list_command.rb @@ -4,6 +4,11 @@ module Aeolus def initialize(opts={}, logger=nil) super(opts, logger) end + + def images + doc = Nokogiri::XML iwhd['/images'].get + doc.xpath("/objects/object/key").collect { |node| "uuid: " + node.text } + end end end end diff --git a/services/image_factory/aeolus-image/spec/list_command_spec.rb b/services/image_factory/aeolus-image/spec/list_command_spec.rb new file mode 100644 index 0000000..01d3646 --- /dev/null +++ b/services/image_factory/aeolus-image/spec/list_command_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +module Aeolus + module Image + describe ListCommand do + it "should return a list of images" do + regexp = Regexp.new('[uuid:\s][\w]{8}[-][\w]{4}[-][\w]{4}[-][\w]{4}[-][\w]{12}') + listc = ListCommand.new + images = listc.images + images.each do |image| + regexp.match(image.to_s).should_not == nil + end + end + + end + end +end \ No newline at end of file