From: Martyn Taylor <mtaylor(a)redhat.com>
---
lib/aeolus_cli/command/config_parser.rb | 3 +
lib/aeolus_cli/command/push_command.rb | 38 +++++++---------
lib/aeolus_cli/model/base.rb | 6 +++
spec/command/push_command_spec.rb | 39 +++++++---------
.../cassettes/command/push_command/push_image.yml | 47 ++++++++++++++++++++
5 files changed, 90 insertions(+), 43 deletions(-)
create mode 100644 spec/vcr/cassettes/command/push_command/push_image.yml
diff --git a/lib/aeolus_cli/command/config_parser.rb
b/lib/aeolus_cli/command/config_parser.rb
index 249dc32..e35ef71 100644
--- a/lib/aeolus_cli/command/config_parser.rb
+++ b/lib/aeolus_cli/command/config_parser.rb
@@ -117,6 +117,9 @@ module Aeolus
opts.on('-B', '--build ID', 'push all target images for a
build, to same providers as previously') do |id|
@options[:build] = id
end
+ opts.on('-t', '--targetimages ID', 'Retrieve the target
images from a build') do |id|
+ @options[:targetimage] = id
+ end
opts.on('-A', '--account NAME', 'name of specific provider
account to use for push') do |name|
@options[:account] = name
end
diff --git a/lib/aeolus_cli/command/push_command.rb
b/lib/aeolus_cli/command/push_command.rb
index 6068e5c..59e1a67 100644
--- a/lib/aeolus_cli/command/push_command.rb
+++ b/lib/aeolus_cli/command/push_command.rb
@@ -26,9 +26,8 @@ module Aeolus
:build => ''
}
@options = default.merge(@options)
- @console = ImageFactoryConsole.new()
- @console.start
end
+
def run
begin
if combo_implemented?
@@ -38,20 +37,22 @@ module Aeolus
quit(1)
end
- sleep(5)
- @console.push(@options[:provider], get_creds, @options[:id],
@options[:build]).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
+ pi = Aeolus::CLI::ProviderImage.new({:provider_name =>
@options[:provider].to_s,
+ :provider_account =>
@options[:account],
+ :image_id => @options[:image],
+ :build_id => @options[:build],
+ :target_image_id =>
@options[:targetimage]})
+ pi.save!
+ puts ""
+ puts "Image: " + pi.image_id
+ puts "Build: " + pi.build_id
+ puts "Target Image: " + pi.target_image_id
+ puts "Provider Image: " + pi.id
+ puts "Status: " + pi.status
quit(0)
end
- rescue
- puts "An Error occured whilst trying to push this build, please check
aeolus-image --help for details on how to use this command"
- quit(1)
+ rescue => e
+ handle_exception(e)
end
end
@@ -60,7 +61,7 @@ module Aeolus
end
def combo_implemented?
- if @options[:provider].empty? || (@options[:build].empty? &&
@options[:id].empty?)
+ if (@options[:provider].empty? || @options[:build].empty? ||
@options[:image].empty? || @options[:account].empty? || @options[:targetimage].empty?)
puts "This combination of parameters is not currently supported"
quit(1)
end
@@ -68,11 +69,6 @@ module Aeolus
end
private
- def quit(code)
- @console.shutdown
- exit(code)
- end
-
def pushed?(image)
begin
uuid = Regexp.new('[\w]{8}[-][\w]{4}[-][\w]{4}[-][\w]{4}[-][\w]{12}')
@@ -83,4 +79,4 @@ module Aeolus
end
end
end
-end
+end
\ No newline at end of file
diff --git a/lib/aeolus_cli/model/base.rb b/lib/aeolus_cli/model/base.rb
index 771e871..88f34d1 100644
--- a/lib/aeolus_cli/model/base.rb
+++ b/lib/aeolus_cli/model/base.rb
@@ -38,6 +38,12 @@ module Aeolus
end
end
+ # Active Resrouce Uses dashes instead of underscores, this method overrides to use
underscore
+ def to_xml(options={})
+ options[:dasherize] ||= false
+ super({ :root => self.class.element_name }.merge(options))
+ end
+
# Instance Methods
def to_s
id
diff --git a/spec/command/push_command_spec.rb b/spec/command/push_command_spec.rb
index 5694e76..1596532 100644
--- a/spec/command/push_command_spec.rb
+++ b/spec/command/push_command_spec.rb
@@ -25,30 +25,25 @@ module Aeolus
end
describe "#run" do
- before(:each) do
- options = {}
- options[:target] = ['mock','ec2']
- options[:template] = "#{File.dirname(__FILE__)}" +
"/../examples/custom_repo.tdl"
- b = BuildCommand.new(options)
- sleep(5)
- tmpl_str = b.send(:read_file, options[:template])
- b.console.build(tmpl_str, ['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
+ VCR.use_cassette('command/push_command/push_image') do
+ @options = ({ :image => "ae24eed8-6190-4725-877a-24bb1517fb54",
+ :build => "accaad33-6bc7-4cd0-9260-3fd5c1b73ff9",
+ :targetimage =>
"817ab83c-beda-4b84-bad1-38d90ebfe5ea",
+ :account => "ec2-acc",
+ :provider => "ec2-us-east-1" })
+ p = PushCommand.new(@options, @output)
+ begin
+ p.run
+ rescue SystemExit => e
+ e.status.should == 0
+ end
+ $stdout.string.should include("Image:
ae24eed8-6190-4725-877a-24bb1517fb54")
+ $stdout.string.should include("Build:
accaad33-6bc7-4cd0-9260-3fd5c1b73ff9")
+ $stdout.string.should include("Target Image:
817ab83c-beda-4b84-bad1-38d90ebfe5ea")
+ $stdout.string.should include("Provider Image:
92f03089-99a6-473d-afef-0a91b67b481a")
+ $stdout.string.should include("Status:")
end
- $stdout.string.should include("Image:")
- $stdout.string.should include("Provider Image:")
- $stdout.string.should include("Build:")
end
end
diff --git a/spec/vcr/cassettes/command/push_command/push_image.yml
b/spec/vcr/cassettes/command/push_command/push_image.yml
new file mode 100644
index 0000000..4955035
--- /dev/null
+++ b/spec/vcr/cassettes/command/push_command/push_image.yml
@@ -0,0 +1,47 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :post
+ uri:
https://admin:password@localhost/conductor/api/provider_images.xml
+ body: |
+ <?xml version="1.0" encoding="UTF-8"?>
+ <provider_image>
+ <image_id>ae24eed8-6190-4725-877a-24bb1517fb54</image_id>
+ <build_id>accaad33-6bc7-4cd0-9260-3fd5c1b73ff9</build_id>
+ <provider_name>ec2-us-east-1</provider_name>
+
<target_image_id>817ab83c-beda-4b84-bad1-38d90ebfe5ea</target_image_id>
+ <provider_account>ec2-acc</provider_account>
+ </provider_image>
+
+ headers:
+ content-type:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ x-ua-compatible:
+ - IE=Edge
+ etag:
+ - "\"9c9d30753c5411f0dbd56cd50bde0bf5\""
+ content-type:
+ - application/xml; charset=utf-8
+ server:
+ - WEBrick/1.3.1 (Ruby/1.8.7/2011-06-30)
+ date:
+ - Wed, 19 Oct 2011 21:16:03 GMT
+ x-runtime:
+ - "0.751304"
+ content-length:
+ - "186"
+ set-cookie:
+ -
_session_id=BAh7CCIPc2Vzc2lvbl9pZCIlOGRjMDU1OTA5ODY0MGM0MmYxYzk1ZDc0NjViMzcwNmMiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--3d8777cec91b80ea8327f909528ccc140af9b335;
path=/; HttpOnly
+ cache-control:
+ - max-age=0, private, must-revalidate
+ body: |
+ <provider_image
href='http://localhost:3000/api/provider_images/92f03089-99a6-473d-afef-0a91b67b481a'
id='92f03089-99a6-473d-afef-0a91b67b481a'>
+ <status>New</status>
+ </provider_image>
+
+ http_version: "1.1"
--
1.7.6.4