From: Maros Zatko mzatko@redhat.com
--- src/app/controllers/api/builds_controller.rb | 43 +++++++++++++++++++ src/app/controllers/api/images_controller.rb | 44 ++++++++++++++++++++ .../controllers/api/provider_images_controller.rb | 43 +++++++++++++++++++ .../controllers/api/target_images_controller.rb | 43 +++++++++++++++++++ src/app/views/api/builds/_build.xml.haml | 3 + src/app/views/api/builds/index.xml.haml | 4 ++ src/app/views/api/builds/show.xml.haml | 2 + src/app/views/api/images/_image.xml.haml | 8 ++++ src/app/views/api/images/index.xml.haml | 4 ++ src/app/views/api/images/show.xml.haml | 2 + src/app/views/api/provider_images/_image.xml.haml | 6 +++ src/app/views/api/provider_images/index.xml.haml | 4 ++ src/app/views/api/provider_images/show.xml.haml | 2 + src/app/views/api/target_images/_image.xml.haml | 7 +++ src/app/views/api/target_images/index.xml.haml | 4 ++ src/app/views/api/target_images/show.xml.haml | 2 + src/config/routes.rb | 14 ++++++ src/spec/spec_helper.rb | 6 +++ 18 files changed, 241 insertions(+), 0 deletions(-) create mode 100644 src/app/controllers/api/builds_controller.rb create mode 100644 src/app/controllers/api/images_controller.rb create mode 100644 src/app/controllers/api/provider_images_controller.rb create mode 100644 src/app/controllers/api/target_images_controller.rb create mode 100644 src/app/views/api/builds/_build.xml.haml create mode 100644 src/app/views/api/builds/index.xml.haml create mode 100644 src/app/views/api/builds/show.xml.haml create mode 100644 src/app/views/api/images/_image.xml.haml create mode 100644 src/app/views/api/images/index.xml.haml create mode 100644 src/app/views/api/images/show.xml.haml create mode 100644 src/app/views/api/provider_images/_image.xml.haml create mode 100644 src/app/views/api/provider_images/index.xml.haml create mode 100644 src/app/views/api/provider_images/show.xml.haml create mode 100644 src/app/views/api/target_images/_image.xml.haml create mode 100644 src/app/views/api/target_images/index.xml.haml create mode 100644 src/app/views/api/target_images/show.xml.haml
diff --git a/src/app/controllers/api/builds_controller.rb b/src/app/controllers/api/builds_controller.rb new file mode 100644 index 0000000..3aeb543 --- /dev/null +++ b/src/app/controllers/api/builds_controller.rb @@ -0,0 +1,43 @@ +# +# Copyright (C) 2011 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. A copy of the GNU General Public License is +# also available at http://www.gnu.org/copyleft/gpl.html. + +# Filters added to this controller apply to all controllers in the application. +# Likewise, all the methods added will be available for all controllers. + +module Api + class BuildsController < ApplicationController + respond_to :xml + layout :false + + def index + @builds = Aeolus::Image::ImageBuild.all + respond_with(@builds) + end + + def show + id = params[:id] + @build = Aeolus::Image::ImageBuild.find(id) + p @build + if @build + respond_with(@build) + else + render :nothing => true, :status => 404 + end + end + end +end diff --git a/src/app/controllers/api/images_controller.rb b/src/app/controllers/api/images_controller.rb new file mode 100644 index 0000000..a4c443b --- /dev/null +++ b/src/app/controllers/api/images_controller.rb @@ -0,0 +1,44 @@ +# +# Copyright (C) 2011 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. A copy of the GNU General Public License is +# also available at http://www.gnu.org/copyleft/gpl.html. + +# Filters added to this controller apply to all controllers in the application. +# Likewise, all the methods added will be available for all controllers. + +module Api + class ImagesController < ApplicationController +# before_filter :require_user + + respond_to :xml + layout :false + + def index + @images = Aeolus::Image::Image.all + respond_with(@images) + end + + def show + id = params[:id] + @image = Aeolus::Image::Image.find(id) + if @image + respond_with(@image) + else + render :nothing => true, :status => 404 + end + end + end +end diff --git a/src/app/controllers/api/provider_images_controller.rb b/src/app/controllers/api/provider_images_controller.rb new file mode 100644 index 0000000..86668e0 --- /dev/null +++ b/src/app/controllers/api/provider_images_controller.rb @@ -0,0 +1,43 @@ +# +# Copyright (C) 2011 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. A copy of the GNU General Public License is +# also available at http://www.gnu.org/copyleft/gpl.html. + +# Filters added to this controller apply to all controllers in the application. +# Likewise, all the methods added will be available for all controllers. + +module Api + class ProviderImagesController < ApplicationController + respond_to :xml + layout :false + + def index + @images = Aeolus::Image::ProviderImage.all + respond_with(@images) + end + + def show + id = params[:id] + @image = Aeolus::Image::ProviderImage.find(id) + if @image + respond_with(@image) + else + render :nothing => true, :status => 404 + end + end + + end +end diff --git a/src/app/controllers/api/target_images_controller.rb b/src/app/controllers/api/target_images_controller.rb new file mode 100644 index 0000000..4957c01 --- /dev/null +++ b/src/app/controllers/api/target_images_controller.rb @@ -0,0 +1,43 @@ +# +# Copyright (C) 2011 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. A copy of the GNU General Public License is +# also available at http://www.gnu.org/copyleft/gpl.html. + +# Filters added to this controller apply to all controllers in the application. +# Likewise, all the methods added will be available for all controllers. + +module Api + class TargetImagesController < ApplicationController + respond_to :xml + layout :false + + def index + @images = Aeolus::Image::TargetImage.all + respond_with(@images) + end + + def show + id = params[:id] + @image = Aeolus::Image::TargetImage.find(id) + if @image + respond_with(@image) + else + render :nothing => true, :status => 404 + end + end + + end +end diff --git a/src/app/views/api/builds/_build.xml.haml b/src/app/views/api/builds/_build.xml.haml new file mode 100644 index 0000000..c50aa78 --- /dev/null +++ b/src/app/views/api/builds/_build.xml.haml @@ -0,0 +1,3 @@ +!!! XML +%build{:id => build.uuid, :href => api_build_url(build.uuid) } + %image{:type => 'xs:string', :href => api_image_url(build.image.uuid)}= build.image.uuid diff --git a/src/app/views/api/builds/index.xml.haml b/src/app/views/api/builds/index.xml.haml new file mode 100644 index 0000000..aca031c --- /dev/null +++ b/src/app/views/api/builds/index.xml.haml @@ -0,0 +1,4 @@ +!!! XML +%builds{:type => 'xs:list'} + - @builds.each do |bld| + = render :partial => 'build', :locals => {:build => bld} diff --git a/src/app/views/api/builds/show.xml.haml b/src/app/views/api/builds/show.xml.haml new file mode 100644 index 0000000..3d3c330 --- /dev/null +++ b/src/app/views/api/builds/show.xml.haml @@ -0,0 +1,2 @@ +!!! XML += render :partial => "build", :locals => {:build => @build} diff --git a/src/app/views/api/images/_image.xml.haml b/src/app/views/api/images/_image.xml.haml new file mode 100644 index 0000000..9abbc3c --- /dev/null +++ b/src/app/views/api/images/_image.xml.haml @@ -0,0 +1,8 @@ +!!!XML +%image{:id => image.uuid, :href => api_image_url(image.uuid) } + %name{:type => 'xs:string'}= image.name + %description{:type => 'xs:string'}= image.description + %os{:type => 'xs:string'}= image.os.name + %os_version{:type => 'xs:string'}= image.os.version + %arch{:type => 'xs:string'}= image.os.arch + %link{:rel=>'builds', :href => api_image_builds_url(image.uuid)} diff --git a/src/app/views/api/images/index.xml.haml b/src/app/views/api/images/index.xml.haml new file mode 100644 index 0000000..62262ec --- /dev/null +++ b/src/app/views/api/images/index.xml.haml @@ -0,0 +1,4 @@ +!!!XML +%images{:type => 'xs:list', :href => api_images_url} + - @images.each do |img| + = render :partial => 'image', :locals => {:image => img} diff --git a/src/app/views/api/images/show.xml.haml b/src/app/views/api/images/show.xml.haml new file mode 100644 index 0000000..88f3efe --- /dev/null +++ b/src/app/views/api/images/show.xml.haml @@ -0,0 +1,2 @@ +!!! XML += render :partial => "image", :locals => {:image => @image} diff --git a/src/app/views/api/provider_images/_image.xml.haml b/src/app/views/api/provider_images/_image.xml.haml new file mode 100644 index 0000000..4df32ea --- /dev/null +++ b/src/app/views/api/provider_images/_image.xml.haml @@ -0,0 +1,6 @@ +!!!XML +%provider_image{:id => image.uuid, :href => api_image_url(image.uuid) } + %icicle= image.icicle + %object_type= image.object_type + %target_identifier= image.target_identifier + %link{:rel=>'target_image', :href => api_provider_image_target_images_url(image.uuid)} diff --git a/src/app/views/api/provider_images/index.xml.haml b/src/app/views/api/provider_images/index.xml.haml new file mode 100644 index 0000000..fd7d01e --- /dev/null +++ b/src/app/views/api/provider_images/index.xml.haml @@ -0,0 +1,4 @@ +!!!XML +%provider_images{:type => 'xs:list', :href=>api_provider_images_url} + - @images.each do |img| + = render :partial => 'image', :locals => {:image => img} diff --git a/src/app/views/api/provider_images/show.xml.haml b/src/app/views/api/provider_images/show.xml.haml new file mode 100644 index 0000000..88f3efe --- /dev/null +++ b/src/app/views/api/provider_images/show.xml.haml @@ -0,0 +1,2 @@ +!!! XML += render :partial => "image", :locals => {:image => @image} diff --git a/src/app/views/api/target_images/_image.xml.haml b/src/app/views/api/target_images/_image.xml.haml new file mode 100644 index 0000000..bea6ae7 --- /dev/null +++ b/src/app/views/api/target_images/_image.xml.haml @@ -0,0 +1,7 @@ +!!!XML +%target_image{:id => image.uuid, :href => api_target_image_url(image.uuid) } + %icicle= image.icicle + %object_type= image.object_type + %template= image.template + %link{:rel=>'build', :href=>api_build_url(image.build.uuid), :id=>image.build.uuid} + %link{:rel=>'provider_images', :href => api_target_image_provider_images_url(image.uuid)} diff --git a/src/app/views/api/target_images/index.xml.haml b/src/app/views/api/target_images/index.xml.haml new file mode 100644 index 0000000..995f613 --- /dev/null +++ b/src/app/views/api/target_images/index.xml.haml @@ -0,0 +1,4 @@ +!!!XML +%target_images{:type => 'xs:list', :href=>api_target_images_url} + - @images.each do |img| + = render :partial => 'image', :locals => {:image => img} diff --git a/src/app/views/api/target_images/show.xml.haml b/src/app/views/api/target_images/show.xml.haml new file mode 100644 index 0000000..88f3efe --- /dev/null +++ b/src/app/views/api/target_images/show.xml.haml @@ -0,0 +1,2 @@ +!!! XML += render :partial => "image", :locals => {:image => @image} diff --git a/src/config/routes.rb b/src/config/routes.rb index 68d1451..78340bd 100644 --- a/src/config/routes.rb +++ b/src/config/routes.rb @@ -181,6 +181,20 @@ Conductor::Application.routes.draw do post 'create' end
+ namespace :api do + resources :images do + resources :builds + end + resources :builds + resources :provider_images do + resources :target_images + end + resources :target_images do + resources :provider_images + end + # :except => [:new, :edit] + end + #match 'matching_profiles', :to => '/hardware_profiles/matching_profiles/:hardware_profile_id/provider/:provider_id', :controller => 'hardware_profiles', :action => 'matching_profiles', :conditions => { :method => :get }, :as =>'matching_profiles' match 'dashboard', :to => 'dashboard', :as => 'dashboard' root :to => "pools#index" diff --git a/src/spec/spec_helper.rb b/src/spec/spec_helper.rb index 498f637..078710b 100644 --- a/src/spec/spec_helper.rb +++ b/src/spec/spec_helper.rb @@ -31,6 +31,12 @@ module RequestContentTypeHelper def accept_xml @request.env["HTTP_ACCEPT"] = "application/xml" end + + def send_and_accept_xml + @request.env["HTTP_ACCEPT"] = "application/xml" + @request.env["CONTENT_TYPE"] = "application/xml" + end + end
include RequestContentTypeHelper
From: Martyn Taylor mtaylor@redhat.com
--- src/app/models/catalog_entry.rb | 2 +- src/app/models/image.rb | 8 ++++---- src/config/initializers/aeolus-image.rb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/app/models/catalog_entry.rb b/src/app/models/catalog_entry.rb index 1f52f21..88ff7e8 100644 --- a/src/app/models/catalog_entry.rb +++ b/src/app/models/catalog_entry.rb @@ -64,7 +64,7 @@ class CatalogEntry < ActiveRecord::Base def fetch_images images = [] fetch_image_uuids.each do |uuid| - images << Aeolus::Image::Image.find(uuid) + images << Aeolus::Image::Warehouse::Image.find(uuid) end images.compact.uniq end diff --git a/src/app/models/image.rb b/src/app/models/image.rb index 96eaa2e..dc0b55b 100644 --- a/src/app/models/image.rb +++ b/src/app/models/image.rb @@ -42,13 +42,13 @@ class Image < WarehouseModel
# The iwhd API really isn't built for what we're trying to do. # Here's a nutty workaround to not issues thousands of queries. - # images should be an array of Aeolus::Image::Image objects + # images should be an array of Aeolus::Image::Warehouse::Image objects # Please don't shoot me for this! def self.provider_images_for_image_list(images) # Fetch all of these, but only once - provider_images = Aeolus::Image::ProviderImage.all - target_images = Aeolus::Image::TargetImage.all - builds = Aeolus::Image::ImageBuild.all + provider_images = Aeolus::Image::Warehouse::ProviderImage.all + target_images = Aeolus::Image::Warehouse::TargetImage.all + builds = Aeolus::Image::Warehouse::ImageBuild.all return_objs = {} images.each do |image| _builds = builds.select{|b| b.instance_variable_get('@image') == image.uuid} diff --git a/src/config/initializers/aeolus-image.rb b/src/config/initializers/aeolus-image.rb index 4c9f12b..86cdfca 100644 --- a/src/config/initializers/aeolus-image.rb +++ b/src/config/initializers/aeolus-image.rb @@ -17,4 +17,4 @@ # also available at http://www.gnu.org/copyleft/gpl.html.
config = YAML.load_file("#{::Rails.root.to_s}/config/settings.yml") -Aeolus::Image::WarehouseModel.send(:class_variable_set, '@@config', config) +Aeolus::Image::Warehouse::WarehouseModel.send(:class_variable_set, '@@config', config)
From: Martyn Taylor mtaylor@redhat.com
--- src/app/controllers/api/builds_controller.rb | 4 ++-- src/app/controllers/api/images_controller.rb | 4 ++-- .../controllers/api/provider_images_controller.rb | 4 ++-- .../controllers/api/target_images_controller.rb | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/app/controllers/api/builds_controller.rb b/src/app/controllers/api/builds_controller.rb index 3aeb543..d3db74d 100644 --- a/src/app/controllers/api/builds_controller.rb +++ b/src/app/controllers/api/builds_controller.rb @@ -25,13 +25,13 @@ module Api layout :false
def index - @builds = Aeolus::Image::ImageBuild.all + @builds = Aeolus::Image::Warehouse::ImageBuild.all respond_with(@builds) end
def show id = params[:id] - @build = Aeolus::Image::ImageBuild.find(id) + @build = Aeolus::Image::Warehouse::ImageBuild.find(id) p @build if @build respond_with(@build) diff --git a/src/app/controllers/api/images_controller.rb b/src/app/controllers/api/images_controller.rb index a4c443b..472e423 100644 --- a/src/app/controllers/api/images_controller.rb +++ b/src/app/controllers/api/images_controller.rb @@ -27,13 +27,13 @@ module Api layout :false
def index - @images = Aeolus::Image::Image.all + @images = Aeolus::Image::Warehouse::Image.all respond_with(@images) end
def show id = params[:id] - @image = Aeolus::Image::Image.find(id) + @image = Aeolus::Image::Warehouse::Image.find(id) if @image respond_with(@image) else diff --git a/src/app/controllers/api/provider_images_controller.rb b/src/app/controllers/api/provider_images_controller.rb index 86668e0..0153df3 100644 --- a/src/app/controllers/api/provider_images_controller.rb +++ b/src/app/controllers/api/provider_images_controller.rb @@ -25,13 +25,13 @@ module Api layout :false
def index - @images = Aeolus::Image::ProviderImage.all + @images = Aeolus::Image::Warehouse::ProviderImage.all respond_with(@images) end
def show id = params[:id] - @image = Aeolus::Image::ProviderImage.find(id) + @image = Aeolus::Image::Warehouse::ProviderImage.find(id) if @image respond_with(@image) else diff --git a/src/app/controllers/api/target_images_controller.rb b/src/app/controllers/api/target_images_controller.rb index 4957c01..f307ac1 100644 --- a/src/app/controllers/api/target_images_controller.rb +++ b/src/app/controllers/api/target_images_controller.rb @@ -25,13 +25,13 @@ module Api layout :false
def index - @images = Aeolus::Image::TargetImage.all + @images = Aeolus::Image::Warehouse::TargetImage.all respond_with(@images) end
def show id = params[:id] - @image = Aeolus::Image::TargetImage.find(id) + @image = Aeolus::Image::Warehouse::TargetImage.find(id) if @image respond_with(@image) else
From: Martyn Taylor mtaylor@redhat.com
--- src/config/application.rb | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/src/config/application.rb b/src/config/application.rb index 0777494..c985826 100644 --- a/src/config/application.rb +++ b/src/config/application.rb @@ -42,6 +42,7 @@ else require 'thin' require 'json' require 'fastercsv' + require 'active_support/core_ext' #require 'railties'
unless (ENV["RAILS_ENV"] == "production")
From: Martyn Taylor mtaylor@redhat.com
--- src/config/initializers/aeolus-image.rb | 1 + src/config/settings.yml | 2 ++ 2 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/src/config/initializers/aeolus-image.rb b/src/config/initializers/aeolus-image.rb index 86cdfca..461ef37 100644 --- a/src/config/initializers/aeolus-image.rb +++ b/src/config/initializers/aeolus-image.rb @@ -18,3 +18,4 @@
config = YAML.load_file("#{::Rails.root.to_s}/config/settings.yml") Aeolus::Image::Warehouse::WarehouseModel.send(:class_variable_set, '@@config', config) +Aeolus::Image::Factory::Base.site = config[:imagefactory][:url] diff --git a/src/config/settings.yml b/src/config/settings.yml index 0a629f1..9d7de04 100644 --- a/src/config/settings.yml +++ b/src/config/settings.yml @@ -12,3 +12,5 @@ # :port: 389 :iwhd: :url: http://localhost:9090 +:imagefactory: + :url: https://localhost:8075/imagefactory \ No newline at end of file
From: Martyn Taylor mtaylor@redhat.com
--- src/config/application.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/config/application.rb b/src/config/application.rb index c985826..154ebdb 100644 --- a/src/config/application.rb +++ b/src/config/application.rb @@ -42,7 +42,7 @@ else require 'thin' require 'json' require 'fastercsv' - require 'active_support/core_ext' + require 'nokogiri' #require 'railties'
unless (ENV["RAILS_ENV"] == "production")
From: Martyn Taylor mtaylor@redhat.com
--- src/app/controllers/api/images_controller.rb | 39 +++++++++++++++++++++- src/app/views/api/images/_factory_image.xml.haml | 7 ++++ src/app/views/api/images/create.xml.haml | 2 + 3 files changed, 47 insertions(+), 1 deletions(-) create mode 100644 src/app/views/api/images/_factory_image.xml.haml create mode 100644 src/app/views/api/images/create.xml.haml
diff --git a/src/app/controllers/api/images_controller.rb b/src/app/controllers/api/images_controller.rb index 472e423..141d2f6 100644 --- a/src/app/controllers/api/images_controller.rb +++ b/src/app/controllers/api/images_controller.rb @@ -40,5 +40,42 @@ module Api render :nothing => true, :status => 404 end end + + def create + req = process_post(request.body.read) + begin + if req[:type] == :failed + render :text => "Insufficient Parameters supplied", :status => 400 + else + @image = Aeolus::Image::Factory::Image.new(req[:params]) + @image.save! + respond_with(@image) + end + rescue ActiveResource::BadRequest + render :text => "Parameter Data Incorrect", :status => 400 + rescue + render :text => "Internal Server Error From Factory", :status => 500 + end + end + + private + def process_post(body) + doc = Nokogiri::XML body + if !doc.xpath("/image/targets").empty? && !doc.xpath("/image/tdl/template").empty? + { :type => :build, :params => { :template => doc.xpath("/image/tdl/template").to_s, + :targets => doc.xpath("/image/targets").text } + } + elsif !doc.xpath("/image/target_name").empty? && !doc.xpath("/image/target_identifier").empty? && + !doc.xpath("/image/image_descriptor").empty? && !doc.xpath("/image/provider_name").empty? + + { :type => :import, :params => { :target_name => doc.xpath("/image/target_name").text, + :target_identifier => doc.xpath("/image/target_identifier").text, + :image_descriptor => doc.xpath("/image/image_descriptor").children.first.to_s, + :provider_name => doc.xpath("/image/provider_name").text } + } + else + { :type => :failed } + end + end end -end +end \ No newline at end of file diff --git a/src/app/views/api/images/_factory_image.xml.haml b/src/app/views/api/images/_factory_image.xml.haml new file mode 100644 index 0000000..cea74bc --- /dev/null +++ b/src/app/views/api/images/_factory_image.xml.haml @@ -0,0 +1,7 @@ +!!!XML +%image{:id => image.id, :href => image.href } + %build{:id => image.build.id, :href => image.build.href} + %targetimages + - image.build.target_images.each do |target_image| + %targetimage{:id => target_image.id, :href => target_image.href} + %status=Aeolus::Image::Factory::TargetImage.status(target_image.id) \ No newline at end of file diff --git a/src/app/views/api/images/create.xml.haml b/src/app/views/api/images/create.xml.haml new file mode 100644 index 0000000..a558d2f --- /dev/null +++ b/src/app/views/api/images/create.xml.haml @@ -0,0 +1,2 @@ +!!! XML += render :partial => "factory_image", :locals => {:image => @image} \ No newline at end of file
From: Martyn Taylor mtaylor@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
On 10/03/2011 12:00 PM, mtaylor@redhat.com wrote:
From: Martyn Taylormtaylor@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
ACK to the series. Works for me.
aeolus-devel@lists.fedorahosted.org