From: Maros Zatko <mzatko(a)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
--
1.7.6.2