https://www.aeolusproject.org/redmine/issues/1701
Simple first pass, subset of full flag list implemented. For now, we support: push --provider PROVIDER1,Provider2 --id $image_id
QMF notifications of push status will be added in a later patch. --- .../aeolus-image/lib/config_parser.rb | 7 +- .../image_factory/aeolus-image/lib/push_command.rb | 37 +++++++++++ .../aeolus-image/spec/build_command_spec.rb | 2 +- .../aeolus-image/spec/config_parser_spec.rb | 2 +- .../aeolus-image/spec/push_command_spec.rb | 64 ++++++++++++++++++++ 5 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 services/image_factory/aeolus-image/spec/push_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 b59a723..5e6b84f 100644 --- a/services/image_factory/aeolus-image/lib/config_parser.rb +++ b/services/image_factory/aeolus-image/lib/config_parser.rb @@ -51,7 +51,7 @@ module Aeolus opts.on('-d', '--id ID', 'id for a given object') do |id| @options[:id] = id end - opts.on('-r', '--provider NAME', 'name of specific provider (ie ec2-us-east1)') do |name| + opts.on('-r', '--provider NAME1,NAME2', Array,'name of specific provider (ie ec2-us-east1)') do |name| @options[:provider] = name end opts.on('-I', '--image ID', 'ID of the base image, can be used in build and push commands, see examples') do |id| @@ -138,7 +138,7 @@ module Aeolus
opts.separator "" opts.separator "Push examples:" - opts.separator "aeolus-image push --provider ec2-us-east-1 --id $target_image_id # push the target image to the specified provider" + opts.separator "aeolus-image push --provider ec2-us-east-1,my-rhev-m --id $image_id # push the image to the specified providers" opts.separator "aeolus-image push --build $build_id # push all target images for a build, to same providers as previously" opts.separator "aeolus-image push --account $provider_account --build $build_id # ditto, using a specific provider account" opts.separator "aeolus-image push --image $image_id # push all the target images for the latest build" @@ -187,7 +187,8 @@ module Aeolus end
def push - "Not implemented" + b = PushCommand.new(@options) + b.run end
def import diff --git a/services/image_factory/aeolus-image/lib/push_command.rb b/services/image_factory/aeolus-image/lib/push_command.rb index f51e851..1beeb54 100644 --- a/services/image_factory/aeolus-image/lib/push_command.rb +++ b/services/image_factory/aeolus-image/lib/push_command.rb @@ -1,8 +1,45 @@ +require 'rest_client' + module Aeolus module Image class PushCommand < BaseCommand + attr_accessor :console def initialize(opts={}, logger=nil) super(opts, logger) + @console = ImageFactoryConsole.new() + @console.start + end + def run + if combo_implemented? + sleep(5) + @console.push(@options[:provider], get_creds, @options[:id]).each do |adaptor| + puts "" + puts "Provider Image: #{adaptor.image_id}" + puts "Image: #{adaptor.image}" + puts "Build: #{adaptor.build}" + puts "Status: #{adaptor.status}" + puts "Percent Complete: #{adaptor.percent_complete}" + end + quit(0) + end + end + + def get_creds + conductor['provider_accounts'].get + end + + def combo_implemented? + if @options[:provider].empty? || @options[:id].empty? + puts "This combination of parameters is not currently supported" + quit(1) + end + true + end + + private + def quit(code) + @console.shutdown + exit(code) end end end diff --git a/services/image_factory/aeolus-image/spec/build_command_spec.rb b/services/image_factory/aeolus-image/spec/build_command_spec.rb index 11182bf..3931917 100644 --- a/services/image_factory/aeolus-image/spec/build_command_spec.rb +++ b/services/image_factory/aeolus-image/spec/build_command_spec.rb @@ -9,7 +9,7 @@ module Aeolus @stdout_orig = $stdout $stdout = StringIO.new @options = {} - @options[:target] = ['mock','mock'] + @options[:target] = ['mock','ec2'] @options[:template] = 'spec/sample_data/custom_repo.tdl' end
diff --git a/services/image_factory/aeolus-image/spec/config_parser_spec.rb b/services/image_factory/aeolus-image/spec/config_parser_spec.rb index 7473add..434285f 100644 --- a/services/image_factory/aeolus-image/spec/config_parser_spec.rb +++ b/services/image_factory/aeolus-image/spec/config_parser_spec.rb @@ -61,7 +61,7 @@ module Aeolus
it "should set options hash for valid push options" do config_parser = ConfigParser.new(%w(push --provider ec2-us-east1 --id 12345)) - config_parser.options[:provider].should == 'ec2-us-east1' + config_parser.options[:provider].should == ['ec2-us-east1'] config_parser.options[:id].should == '12345' end
diff --git a/services/image_factory/aeolus-image/spec/push_command_spec.rb b/services/image_factory/aeolus-image/spec/push_command_spec.rb new file mode 100644 index 0000000..e454728 --- /dev/null +++ b/services/image_factory/aeolus-image/spec/push_command_spec.rb @@ -0,0 +1,64 @@ +require 'spec_helper' +require 'stringio' + +module Aeolus + module Image + describe PushCommand do + + before(:each) do + @output = double('output') + @stdout_orig = $stdout + $stdout = StringIO.new + @options = {} + @options[:provider] = ['mock'] + @options[:user] = 'admin' + @options[:password] = 'password' + end + + after(:each) do + $stdout = @stdout_orig + end + + describe "#run" do + before(:each) do + options = {} + options[:target] = ['mock','ec2'] + options[:template] = 'spec/sample_data/custom_repo.tdl' + b = BuildCommand.new(options) + sleep(5) + b.console.build(b.read_file, ['mock','ec2']).each do |adaptor| + @build_id = adaptor.image + end + b.console.shutdown + @options[:id] = @build_id + end + + it "should push an image with valid options" do + p = PushCommand.new(@options, @output) + begin + p.run + rescue SystemExit => e + e.status.should == 0 + end + $stdout.string.should include("Image:") + $stdout.string.should include("Provider Image:") + $stdout.string.should include("Build:") + end + end + + describe "#combo_implemented?" do + it "should give useful feedback if no template or target is specified" do + @options[:id] = '' + @options[:provider] = [] + b = PushCommand.new(@options, @output) + begin + b.combo_implemented? + rescue SystemExit => e + e.status.should == 1 + end + $stdout.string.should include("This combination of parameters is not currently supported") + end + end + end + end +end \ No newline at end of file
Ack with one minor nit inline
Also, changing the provider command to ARRAY will mess with the import_image command patch. However, we need to readdress all of these option names etc... So, when you rebase this commit just replace @options[:provider] with @options[:provider].first in the console method call in the image_import method.
Cheers
Martyn
----- Original Message ----- From: "Jason Guiditta" jguiditt@redhat.com To: aeolus-devel@lists.fedorahosted.org Sent: Wednesday, 15 June, 2011 8:39:18 PM Subject: [PATCH conductor] Issue #1701: Push to provider.
https://www.aeolusproject.org/redmine/issues/1701
Simple first pass, subset of full flag list implemented. For now, we support: push --provider PROVIDER1,Provider2 --id $image_id
QMF notifications of push status will be added in a later patch. --- .../aeolus-image/lib/config_parser.rb | 7 +- .../image_factory/aeolus-image/lib/push_command.rb | 37 +++++++++++ .../aeolus-image/spec/build_command_spec.rb | 2 +- .../aeolus-image/spec/config_parser_spec.rb | 2 +- .../aeolus-image/spec/push_command_spec.rb | 64 ++++++++++++++++++++ 5 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 services/image_factory/aeolus-image/spec/push_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 b59a723..5e6b84f 100644 --- a/services/image_factory/aeolus-image/lib/config_parser.rb +++ b/services/image_factory/aeolus-image/lib/config_parser.rb @@ -51,7 +51,7 @@ module Aeolus opts.on('-d', '--id ID', 'id for a given object') do |id| @options[:id] = id end - opts.on('-r', '--provider NAME', 'name of specific provider (ie ec2-us-east1)') do |name| + opts.on('-r', '--provider NAME1,NAME2', Array,'name of specific provider (ie ec2-us-east1)') do |name| @options[:provider] = name end opts.on('-I', '--image ID', 'ID of the base image, can be used in build and push commands, see examples') do |id| @@ -138,7 +138,7 @@ module Aeolus
opts.separator "" opts.separator "Push examples:" - opts.separator "aeolus-image push --provider ec2-us-east-1 --id $target_image_id # push the target image to the specified provider" + opts.separator "aeolus-image push --provider ec2-us-east-1,my-rhev-m --id $image_id # push the image to the specified providers" opts.separator "aeolus-image push --build $build_id # push all target images for a build, to same providers as previously" opts.separator "aeolus-image push --account $provider_account --build $build_id # ditto, using a specific provider account" opts.separator "aeolus-image push --image $image_id # push all the target images for the latest build" @@ -187,7 +187,8 @@ module Aeolus end
def push - "Not implemented" + b = PushCommand.new(@options) + b.run end
def import diff --git a/services/image_factory/aeolus-image/lib/push_command.rb b/services/image_factory/aeolus-image/lib/push_command.rb index f51e851..1beeb54 100644 --- a/services/image_factory/aeolus-image/lib/push_command.rb +++ b/services/image_factory/aeolus-image/lib/push_command.rb @@ -1,8 +1,45 @@ +require 'rest_client' You dont need to import this, since its already imported in basecommand + module Aeolus module Image class PushCommand < BaseCommand + attr_accessor :console def initialize(opts={}, logger=nil) super(opts, logger) + @console = ImageFactoryConsole.new() + @console.start + end + def run + if combo_implemented? + sleep(5) + @console.push(@options[:provider], get_creds, @options[:id]).each do |adaptor| + puts "" + puts "Provider Image: #{adaptor.image_id}" + puts "Image: #{adaptor.image}" + puts "Build: #{adaptor.build}" + puts "Status: #{adaptor.status}" + puts "Percent Complete: #{adaptor.percent_complete}" + end + quit(0) + end + end + + def get_creds + conductor['provider_accounts'].get + end + + def combo_implemented? + if @options[:provider].empty? || @options[:id].empty? + puts "This combination of parameters is not currently supported" + quit(1) + end + true + end + + private + def quit(code) + @console.shutdown + exit(code) end end end diff --git a/services/image_factory/aeolus-image/spec/build_command_spec.rb b/services/image_factory/aeolus-image/spec/build_command_spec.rb index 11182bf..3931917 100644 --- a/services/image_factory/aeolus-image/spec/build_command_spec.rb +++ b/services/image_factory/aeolus-image/spec/build_command_spec.rb @@ -9,7 +9,7 @@ module Aeolus @stdout_orig = $stdout $stdout = StringIO.new @options = {} - @options[:target] = ['mock','mock'] + @options[:target] = ['mock','ec2'] @options[:template] = 'spec/sample_data/custom_repo.tdl' end
diff --git a/services/image_factory/aeolus-image/spec/config_parser_spec.rb b/services/image_factory/aeolus-image/spec/config_parser_spec.rb index 7473add..434285f 100644 --- a/services/image_factory/aeolus-image/spec/config_parser_spec.rb +++ b/services/image_factory/aeolus-image/spec/config_parser_spec.rb @@ -61,7 +61,7 @@ module Aeolus
it "should set options hash for valid push options" do config_parser = ConfigParser.new(%w(push --provider ec2-us-east1 --id 12345)) - config_parser.options[:provider].should == 'ec2-us-east1' + config_parser.options[:provider].should == ['ec2-us-east1'] config_parser.options[:id].should == '12345' end
diff --git a/services/image_factory/aeolus-image/spec/push_command_spec.rb b/services/image_factory/aeolus-image/spec/push_command_spec.rb new file mode 100644 index 0000000..e454728 --- /dev/null +++ b/services/image_factory/aeolus-image/spec/push_command_spec.rb @@ -0,0 +1,64 @@ +require 'spec_helper' +require 'stringio' + +module Aeolus + module Image + describe PushCommand do + + before(:each) do + @output = double('output') + @stdout_orig = $stdout + $stdout = StringIO.new + @options = {} + @options[:provider] = ['mock'] + @options[:user] = 'admin' + @options[:password] = 'password' + end + + after(:each) do + $stdout = @stdout_orig + end + + describe "#run" do + before(:each) do + options = {} + options[:target] = ['mock','ec2'] + options[:template] = 'spec/sample_data/custom_repo.tdl' + b = BuildCommand.new(options) + sleep(5) + b.console.build(b.read_file, ['mock','ec2']).each do |adaptor| + @build_id = adaptor.image + end + b.console.shutdown + @options[:id] = @build_id + end + + it "should push an image with valid options" do + p = PushCommand.new(@options, @output) + begin + p.run + rescue SystemExit => e + e.status.should == 0 + end + $stdout.string.should include("Image:") + $stdout.string.should include("Provider Image:") + $stdout.string.should include("Build:") + end + end + + describe "#combo_implemented?" do + it "should give useful feedback if no template or target is specified" do + @options[:id] = '' + @options[:provider] = [] + b = PushCommand.new(@options, @output) + begin + b.combo_implemented? + rescue SystemExit => e + e.status.should == 1 + end + $stdout.string.should include("This combination of parameters is not currently supported") + end + end + end + end +end \ No newline at end of file
aeolus-devel@lists.fedorahosted.org