[PATCH aeolus-cli] Bug 796781: Handle environment param in cli call for import (revised)
Martyn Taylor
mtaylor at redhat.com
Fri Feb 24 18:26:05 UTC 2012
Ack
On 02/24/2012 03:31 PM, Scott Seago wrote:
> https://bugzilla.redhat.com/show_bug.cgi?id=796781
> ---
> lib/aeolus_cli/command/config_parser.rb | 11 +++++++----
> lib/aeolus_cli/command/import_command.rb | 5 +++--
> man/aeolus-image-import.1 | 8 +++++++-
> spec/command/import_command_spec.rb | 15 +++++++++++++--
> 4 files changed, 30 insertions(+), 9 deletions(-)
>
> diff --git a/lib/aeolus_cli/command/config_parser.rb b/lib/aeolus_cli/command/config_parser.rb
> index 1401870..de9689a 100644
> --- a/lib/aeolus_cli/command/config_parser.rb
> +++ b/lib/aeolus_cli/command/config_parser.rb
> @@ -151,7 +151,7 @@ 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|
> + opts.on('-E', '--environment ENVIRONMENT', 'environment to build for') do |environment|
> @options[:environment] = environment
> end
> opts.on( '-h', '--help', 'Get usage information for this command')
> @@ -233,13 +233,16 @@ module Aeolus
> opts.on('-A', '--account NAME,NAME', Array, 'name of specific account to import to') do |name|
> @options[:provider_account] = name
> end
> + opts.on('-E', '--environment ENVIRONMENT', 'environment to import into') do |environment|
> + @options[:environment] = environment
> + end
> opts.on( '-h', '--help', 'Get usage information for this command')
>
> opts.separator ""
> opts.separator "Examples:"
> - opts.separator "aeolus-image import --account my-ec2 --id $ami_id # import an AMI from the specified provider"
> - opts.separator "aeolus-image import --account my-ec2 --id $ami_id --description '<image><name>My Image</name></image>' # import an AMI from the specified provider"
> - opts.separator "aeolus-image import --account my-ec2 --id $ami_id --description<path_to_xml_file> # import an AMI from the specified provider"
> + opts.separator "aeolus-image import --account my-ec2 --id $ami_id --environment default # import an AMI from the specified provider"
> + opts.separator "aeolus-image import --account my-ec2 --id $ami_id --environment default --description '<image><name>My Image</name></image>' # import an AMI from the specified provider"
> + opts.separator "aeolus-image import --account my-ec2 --id $ami_id --environment default --description<path_to_xml_file> # import an AMI from the specified provider"
> opts.separator ""
> opts.separator "RHEV:"
> opts.separator "Enter the template id for the provider image id. The template id can be found through the RHEV REST API."
> diff --git a/lib/aeolus_cli/command/import_command.rb b/lib/aeolus_cli/command/import_command.rb
> index c53d749..63ee873 100644
> --- a/lib/aeolus_cli/command/import_command.rb
> +++ b/lib/aeolus_cli/command/import_command.rb
> @@ -34,7 +34,8 @@ module Aeolus
>
> image = Aeolus::CLI::Image.new({:target_identifier => @options[:id],
> :image_descriptor => @options[:description],
> - :provider_account_name => @options[:provider_account].first})
> + :provider_account_name => @options[:provider_account].first,
> + :environment => @options[:environment]})
> image.save!
>
> headers = ActiveSupport::OrderedHash.new
> @@ -68,7 +69,7 @@ module Aeolus
> raise ArgumentError, "params should not contain nil"
> end
>
> - required_keys = [:id, :provider_account]
> + required_keys = [:id, :provider_account, :environment]
> optional_keys = [:description]
>
> isect = params.keys& required_keys
> diff --git a/man/aeolus-image-import.1 b/man/aeolus-image-import.1
> index 33a7653..8772798 100644
> --- a/man/aeolus-image-import.1
> +++ b/man/aeolus-image-import.1
> @@ -2,7 +2,7 @@
> .SH NAME
> aeolus-image import \- command for importing existing provider images into aeolus
> .SH SYNOPSIS
> -.B aeolus-image import [\-h|--help] [\-u|--username] [\-w|--password] [\-A|--account [account-name]] [\--id [provider-image-id]] [--description [path-to-file|xml string]] [\-d|--daemon]
> +.B aeolus-image import [\-h|--help] [\-u|--username] [\-w|--password] [\-A|--account [account-name]] [\--id [provider-image-id]] [\-E|--environment] [--description [path-to-file|xml string]] [\-d|--daemon]
> .SH DESCRIPTION
> aeolus-image import allows users to import pre-existing images that exist in cloud provders for example AMI from EC2, into aeolus.
> .SH OPTIONS
> @@ -19,6 +19,9 @@ The provider account name as it exists in Conductor from where the importing ima
> \--id<provider-image-id>
> The providers ID given to the importing image
> .TP
> +\-E, --environment
> +Limit image list to environment
> +.TP
> \--description<path-to-xml-description|xml string>
> A user defined description to associate with the importing image
> .TP
> @@ -33,17 +36,20 @@ Import the AMI ami-1234567 from the provider account my-ec2 into aeolus
> .B aeolus-image import
> \--account my-ec2
> \--id ami-1234567
> +\--environment default
> .TP
> Import the AMI ami-1234567 from the provider account my-ec2 into aeolus with a given xml description
> .B aeolus-image import
> \--account my-ec2
> \--id ami-1234567
> +\--environment default
> \--description '<image><name>myAMI</name></image>'
> .TP
> Import the AMI ami-1234567 from the provider account my-ec2 into aeolus providing a path to the description XML file
> .B aeolus-image import
> \--account my-ec2
> \--id ami-1234567
> +\--environment default
> \--description /foo/bar/description.xml
> .SH RHEV
> .TP
> diff --git a/spec/command/import_command_spec.rb b/spec/command/import_command_spec.rb
> index a221b4e..01c57a6 100644
> --- a/spec/command/import_command_spec.rb
> +++ b/spec/command/import_command_spec.rb
> @@ -20,13 +20,15 @@ module Aeolus
> let( :description ) { "<image><name>MyImage</name></image>" }
> let( :options ) { { :id => "ami-5592553c",
> :provider_account => ["ec2-us-east-1"],
> + :environment => "default",
> :description => description } }
> let( :importc ) { ImportCommand.new( options ) }
>
> describe "#import_image" do
> context "without description parameter" do
> let( :options ) { { :id => "ami-5592553c",
> - :provider_account => ["ec2-us-east-1"] } }
> + :provider_account => ["ec2-us-east-1"],
> + :environment => "default" } }
>
> it "should import an image with default description value" do
> VCR.use_cassette('command/import_command/import_image_default') do
> @@ -166,7 +168,8 @@ module Aeolus
> context "correct params" do
> let( :params ) { { :id => "ami-5592553c",
> :provider_account => ["ec2-us-east-1"],
> - :description => description } }
> + :description => description,
> + :environment => "default" } }
> it { subject.call.should be_true }
> end
>
> @@ -176,10 +179,18 @@ module Aeolus
> it { should raise_error(ArgumentError, /missing/) }
> end
>
> + context "missing environment" do
> + let( :params ) { { :id => "ami-5592553c",
> + :description => description,
> + :provider_account => ["ec2-us-east-1"]} }
> + it { should raise_error(ArgumentError, /missing environment/) }
> + end
> +
> context "unexpected parameter" do
> let( :params ) { { :id => "ami-5592553c",
> :provider_account => ["ec2-us-east-1"],
> :other_parameter => "other_value",
> + :environment => "default",
> :description => description } }
> it { should raise_error(ArgumentError, /unexpected/) }
> end
More information about the aeolus-devel
mailing list