[PATCH aeolus-cli] bug 786220 - Scope images to Pool Family

Scott Seago sseago at redhat.com
Wed Feb 15 18:51:37 UTC 2012


https://bugzilla.redhat.com/show_bug.cgi?id=786220
---
 lib/aeolus_cli.rb                       |    1 +
 lib/aeolus_cli/command/build_command.rb |    4 ++--
 lib/aeolus_cli/command/config_parser.rb |   10 ++++++++++
 lib/aeolus_cli/command/list_command.rb  |   16 +++++++++++++++-
 lib/aeolus_cli/model/environment.rb     |   20 ++++++++++++++++++++
 spec/command/build_command_spec.rb      |    1 +
 6 files changed, 49 insertions(+), 3 deletions(-)
 create mode 100644 lib/aeolus_cli/model/environment.rb

diff --git a/lib/aeolus_cli.rb b/lib/aeolus_cli.rb
index 851d8da..8070845 100644
--- a/lib/aeolus_cli.rb
+++ b/lib/aeolus_cli.rb
@@ -32,3 +32,4 @@ require File.join(File.dirname(__FILE__), 'aeolus_cli/model', 'target_image')
 require File.join(File.dirname(__FILE__), 'aeolus_cli/model', 'provider')
 require File.join(File.dirname(__FILE__), 'aeolus_cli/model', 'provider_account')
 require File.join(File.dirname(__FILE__), 'aeolus_cli/model', 'provider_type')
+require File.join(File.dirname(__FILE__), 'aeolus_cli/model', 'environment')
diff --git a/lib/aeolus_cli/command/build_command.rb b/lib/aeolus_cli/command/build_command.rb
index fe62654..0741846 100644
--- a/lib/aeolus_cli/command/build_command.rb
+++ b/lib/aeolus_cli/command/build_command.rb
@@ -34,7 +34,7 @@ module Aeolus
           begin
             template = read_template
             validate_xml_schema(template)
-            image = Aeolus::CLI::Image.new({:targets => @options[:target] * ",", :tdl => template})
+            image = Aeolus::CLI::Image.new({:targets => @options[:target] * ",", :tdl => template, :environment => @options[:environment]})
             image.save!
 
             headers = ActiveSupport::OrderedHash.new
@@ -81,7 +81,7 @@ module Aeolus
       end
 
       def combo_implemented?
-        if @options[:template].empty? || @options[:target].empty?
+        if @options[:template].empty? || @options[:target].empty? || @options[:environment].nil?
           puts "Error: This combination of parameters is not currently supported"
           quit(1)
         end
diff --git a/lib/aeolus_cli/command/config_parser.rb b/lib/aeolus_cli/command/config_parser.rb
index ef64349..7bc9515 100644
--- a/lib/aeolus_cli/command/config_parser.rb
+++ b/lib/aeolus_cli/command/config_parser.rb
@@ -87,6 +87,9 @@ module Aeolus
           opts.on('-i', '--images', 'Retrieve a list of images') do
             @options[:subcommand] = :images
           end
+          opts.on('-E', '--environment ENVIRONMENT', 'Limit image list to environment') do |environment|
+            @options[:environment] =  environment
+          end
           opts.on('-b', '--builds ID', 'Retrieve the builds of an image') do |id|
             @options[:subcommand] = :builds
             @options[:id] = id
@@ -108,11 +111,15 @@ module Aeolus
           opts.on('-a', '--accounts', 'Retrieve the values available for the --account parameter') do
             @options[:subcommand] = :accounts
           end
+          opts.on('-c', '--environments', 'Retrieve the values available for the --environment parameter') do
+            @options[:subcommand] = :environments
+          end
           opts.on( '-h', '--help', 'Get usage information for this command')
 
           opts.separator ""
           opts.separator "Examples:"
           opts.separator "aeolus-image list --images                     # list available images"
+          opts.separator "aeolus-image list --images --envionment $env   # list available images for an environment"
           opts.separator "aeolus-image list --builds $image_id           # list the builds of an image"
           opts.separator "aeolus-image list --targetimages $build_id     # list the target images from a build"
           opts.separator "aeolus-image list --providerimages $target_id  # list the provider images from a target image"
@@ -138,6 +145,9 @@ module Aeolus
           opts.on('-T', '--target TARGET1,TARGET2', Array, 'provider type (ec2, rackspace, rhevm, etc)') do |name|
             @options[:target] = name
           end
+          opts.on('-E', '--environment ENVIRONMENT', 'Limit image list to environment') do |environment|
+            @options[:environment] =  environment
+          end
           opts.on( '-h', '--help', 'Get usage information for this command')
 
           opts.separator ""
diff --git a/lib/aeolus_cli/command/list_command.rb b/lib/aeolus_cli/command/list_command.rb
index 4714985..479b961 100644
--- a/lib/aeolus_cli/command/list_command.rb
+++ b/lib/aeolus_cli/command/list_command.rb
@@ -24,11 +24,13 @@ module Aeolus
           headers = ActiveSupport::OrderedHash.new
           headers[:id] = "ID"
           headers[:name] = "Name"
+          headers[:environment] = "Environment"
           headers[:os] = "OS"
           headers[:os_version] = "OS Version"
           headers[:arch] = "Arch"
           headers[:description] = "Description"
-          print_collection(Aeolus::CLI::Image.all, headers)
+          collection = @options[:environment].nil? ? Aeolus::CLI::Image.all : Aeolus::CLI::Image.find(:all, :from => Aeolus::CLI::Base.site.path + "/environments/" + @options[:environment] + "/images.xml")
+          print_collection(collection, headers)
           quit(0)
         rescue => e
           handle_exception(e)
@@ -127,6 +129,18 @@ module Aeolus
           handle_exception(e)
         end
       end
+
+      def environments
+        begin
+          headers = ActiveSupport::OrderedHash.new
+          headers[:name] = "Name"
+          print_collection(Aeolus::CLI::Environment.all, headers)
+          quit(0)
+        rescue => e
+          handle_exception(e)
+        end
+      end
+
     end
   end
 end
diff --git a/lib/aeolus_cli/model/environment.rb b/lib/aeolus_cli/model/environment.rb
new file mode 100644
index 0000000..1832f92
--- /dev/null
+++ b/lib/aeolus_cli/model/environment.rb
@@ -0,0 +1,20 @@
+#   Copyright 2012 Red Hat, Inc.
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+module Aeolus
+  module CLI
+    class Environment < Base
+    end
+  end
+end
diff --git a/spec/command/build_command_spec.rb b/spec/command/build_command_spec.rb
index 645f0ff..c7ae408 100644
--- a/spec/command/build_command_spec.rb
+++ b/spec/command/build_command_spec.rb
@@ -20,6 +20,7 @@ module Aeolus
       before(:each) do
         @options[:target] = ['ec2']
         @options[:template] = "#{File.dirname(__FILE__)}" + "../../fixtures/valid_template.tdl"
+        @options[:environment] = ['default']
       end
 
       describe "#run" do
-- 
1.7.6.4




More information about the aeolus-devel mailing list