From: Martyn Taylor <mtaylor(a)redhat.com>
---
.../controllers/api/provider_images_controller.rb | 37 +++++++++++++++++++-
.../_factory_provider_image.xml.haml | 3 ++
src/app/views/api/provider_images/create.xml.haml | 2 +
3 files changed, 41 insertions(+), 1 deletions(-)
create mode 100644 src/app/views/api/provider_images/_factory_provider_image.xml.haml
create mode 100644 src/app/views/api/provider_images/create.xml.haml
diff --git a/src/app/controllers/api/provider_images_controller.rb
b/src/app/controllers/api/provider_images_controller.rb
index 0153df3..a60d8aa 100644
--- a/src/app/controllers/api/provider_images_controller.rb
+++ b/src/app/controllers/api/provider_images_controller.rb
@@ -39,5 +39,40 @@ module Api
end
end
+ def create
+ req = process_post(request.body.read)
+ begin
+ if req[:type] == :failed
+ render :text => "Insufficient Parameters supplied", :status =>
400
+ else
+ @provider_image = Aeolus::Image::Factory::ProviderImage.new(req[:params])
+ @provider_image.save!
+ respond_with(@provider_image)
+ end
+ rescue ActiveResource::BadRequest
+ render :text => "Parameter Data Incorrect", :status => 400
+ rescue
+ render :text => "Internal Server Error", :status => 500
+ end
+ end
+
+ private
+ def process_post(body)
+ doc = Nokogiri::XML body
+ if !doc.xpath("/image/provider_name").empty? &&
!doc.xpath("/image/provider_account").empty? &&
+ !doc.xpath("/image/image_id").empty? &&
!doc.xpath("/image/build_id").empty? &&
+ !doc.xpath("/image/target_image_id").empty?
+ if provider_account =
ProviderAccount.find_by_label(doc.xpath("/image/provider_account").text)
+ #TODO check user permission on this provider account
+ { :type => :push, :params => { :provider =>
doc.xpath("/image/provider_name").text,
+ :credentials => provider_account.to_xml,
+ :image_id =>
doc.xpath("/image/image_id").text,
+ :build_id =>
doc.xpath("/image/build_id").text,
+ :target_image_id =>
doc.xpath("/image/target_image_id").text } }
+ end
+ else
+ { :type => :failed }
+ end
+ end
end
-end
+end
\ No newline at end of file
diff --git a/src/app/views/api/provider_images/_factory_provider_image.xml.haml
b/src/app/views/api/provider_images/_factory_provider_image.xml.haml
new file mode 100644
index 0000000..53c7a9d
--- /dev/null
+++ b/src/app/views/api/provider_images/_factory_provider_image.xml.haml
@@ -0,0 +1,3 @@
+!!!XML
+%providerimage{:id => provider_image.id, :href => provider_image.href }
+ %status=Aeolus::Image::Factory::ProviderImage.status(provider_image.id)
\ No newline at end of file
diff --git a/src/app/views/api/provider_images/create.xml.haml
b/src/app/views/api/provider_images/create.xml.haml
new file mode 100644
index 0000000..4bacc81
--- /dev/null
+++ b/src/app/views/api/provider_images/create.xml.haml
@@ -0,0 +1,2 @@
+!!! XML
+= render :partial => "factory_provider_image", :locals =>
{:provider_image => @provider_image}
\ No newline at end of file
--
1.7.6.2