[PATCH aeolus-image-rubygem] Fixed template body initialize
by Jan Provazník
From: Jan Provaznik <jprovazn(a)redhat.com>
---
lib/aeolus_image/model/warehouse/template.rb | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/lib/aeolus_image/model/warehouse/template.rb b/lib/aeolus_image/model/warehouse/template.rb
index eb0fd24..befd55f 100644
--- a/lib/aeolus_image/model/warehouse/template.rb
+++ b/lib/aeolus_image/model/warehouse/template.rb
@@ -16,8 +16,14 @@ module Aeolus
module Image
module Warehouse
class Template < WarehouseModel
+ attr_reader :body
+
@bucket_name = 'templates'
+ def initialize(obj)
+ super
+ @body = obj.body
+ end
end
end
end
--
1.7.6.4
12 years, 5 months
[PATCH aeolus-image-rubygem] Updated warehouse models initialize method and fixed image body
by Jan Provazník
From: Jan Provaznik <jprovazn(a)redhat.com>
This patch unifies initialize method for all warehouse objects, attr_(reader|writer)
is created only of this method doesn't exist yet.
Also fixes passing of image body - till now this value was always nil.
---
lib/aeolus_image/model/warehouse/icicle.rb | 8 --------
lib/aeolus_image/model/warehouse/image.rb | 16 ++++------------
lib/aeolus_image/model/warehouse/image_build.rb | 16 ++--------------
lib/aeolus_image/model/warehouse/provider_image.rb | 14 +-------------
lib/aeolus_image/model/warehouse/target_image.rb | 14 +-------------
lib/aeolus_image/model/warehouse/template.rb | 9 +--------
.../model/warehouse/warehouse_model.rb | 16 ++++++++++++----
7 files changed, 21 insertions(+), 72 deletions(-)
diff --git a/lib/aeolus_image/model/warehouse/icicle.rb b/lib/aeolus_image/model/warehouse/icicle.rb
index 76aa6c3..1a11da8 100644
--- a/lib/aeolus_image/model/warehouse/icicle.rb
+++ b/lib/aeolus_image/model/warehouse/icicle.rb
@@ -18,14 +18,6 @@ module Aeolus
class Icicle < WarehouseModel
@bucket_name = 'icicles'
- def initialize(attrs)
- attrs.each do |k,v|
- sym = :attr_accessor
- self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
- send(:"#{k}=", v)
- end
- end
-
def packages
unless @packages
begin
diff --git a/lib/aeolus_image/model/warehouse/image.rb b/lib/aeolus_image/model/warehouse/image.rb
index fa1be4e..05ef257 100644
--- a/lib/aeolus_image/model/warehouse/image.rb
+++ b/lib/aeolus_image/model/warehouse/image.rb
@@ -20,17 +20,9 @@ module Aeolus
@bucket_name = 'images'
- def initialize(attrs)
- attrs.each do |k,v|
- if k.to_sym == :latest_build
- sym = :attr_writer
- else
- sym = :attr_accessor
- end
- self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
- send(:"#{k}=", v)
- end
- @xml_body = Nokogiri::XML @body
+ def initialize(obj)
+ super
+ @xml_body = Nokogiri::XML obj.body
end
def template_xml
@@ -90,4 +82,4 @@ module Aeolus
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/aeolus_image/model/warehouse/image_build.rb b/lib/aeolus_image/model/warehouse/image_build.rb
index 41375c7..e47c2d7 100644
--- a/lib/aeolus_image/model/warehouse/image_build.rb
+++ b/lib/aeolus_image/model/warehouse/image_build.rb
@@ -18,23 +18,11 @@ module Aeolus
class ImageBuild < WarehouseModel
@bucket_name = 'builds'
- def initialize(attrs)
- attrs.each do |k,v|
- if k.to_sym == :image
- sym = :attr_writer
- else
- sym = :attr_accessor
- end
- self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
- send(:"#{k}=", v)
- end
- end
-
def self.find_all_by_image_uuid(uuid)
self.set_warehouse_and_bucket if self.bucket.nil?
self.bucket.objects.map do |wh_object|
if wh_object.attr('image') == uuid
- ImageBuild.new(wh_object.attrs(wh_object.attr_list))
+ ImageBuild.new(wh_object)
end
end.compact
end
@@ -67,4 +55,4 @@ module Aeolus
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/aeolus_image/model/warehouse/provider_image.rb b/lib/aeolus_image/model/warehouse/provider_image.rb
index 489a624..6a65ab7 100644
--- a/lib/aeolus_image/model/warehouse/provider_image.rb
+++ b/lib/aeolus_image/model/warehouse/provider_image.rb
@@ -18,18 +18,6 @@ module Aeolus
class ProviderImage < WarehouseModel
@bucket_name = 'provider_images'
- def initialize(attrs)
- attrs.each do |k,v|
- if [:provider, :target_image].include?(k.to_sym)
- sym = :attr_writer
- else
- sym = :attr_accessor
- end
- self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
- send(:"#{k}=", v)
- end
- end
-
def target_image
TargetImage.find(@target_image) if @target_image
end
@@ -45,4 +33,4 @@ module Aeolus
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/aeolus_image/model/warehouse/target_image.rb b/lib/aeolus_image/model/warehouse/target_image.rb
index 4e6079a..089edc0 100644
--- a/lib/aeolus_image/model/warehouse/target_image.rb
+++ b/lib/aeolus_image/model/warehouse/target_image.rb
@@ -18,18 +18,6 @@ module Aeolus
class TargetImage < WarehouseModel
@bucket_name = 'target_images'
- def initialize(attrs)
- attrs.each do |k,v|
- if k.to_sym == :build
- sym = :attr_writer
- else
- sym = :attr_accessor
- end
- self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
- send(:"#{k}=", v)
- end
- end
-
def build
ImageBuild.find(@build) if @build
end
@@ -55,4 +43,4 @@ module Aeolus
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/aeolus_image/model/warehouse/template.rb b/lib/aeolus_image/model/warehouse/template.rb
index e48497c..eb0fd24 100644
--- a/lib/aeolus_image/model/warehouse/template.rb
+++ b/lib/aeolus_image/model/warehouse/template.rb
@@ -18,14 +18,7 @@ module Aeolus
class Template < WarehouseModel
@bucket_name = 'templates'
- def initialize(attrs)
- attrs.each do |k,v|
- sym = :attr_accessor
- self.class.send(sym, k.to_sym) unless respond_to?(:"#{k}=")
- send(:"#{k}=", v)
- end
- end
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/aeolus_image/model/warehouse/warehouse_model.rb b/lib/aeolus_image/model/warehouse/warehouse_model.rb
index 84afe07..1a90288 100644
--- a/lib/aeolus_image/model/warehouse/warehouse_model.rb
+++ b/lib/aeolus_image/model/warehouse/warehouse_model.rb
@@ -19,6 +19,14 @@ module Aeolus
class BucketNotFound < Exception;end
class WarehouseModel
+ def initialize(obj)
+ attrs = obj.attrs(obj.attr_list)
+ attrs.each do |k,v|
+ self.class.send(:attr_writer, k.to_sym) unless respond_to?(:"#{k}=")
+ self.class.send(:attr_reader, k.to_sym) unless respond_to?(k.to_sym)
+ send(:"#{k}=", v)
+ end
+ end
def ==(other_obj)
# If the objects have different instance variables defined, they're definitely not ==
@@ -60,17 +68,17 @@ module Aeolus
def first
obj = bucket_objects.first
- obj ? self.new(obj.attrs(obj.attr_list)) : nil
+ obj ? self.new(obj) : nil
end
def last
obj = bucket_objects.last
- obj ? self.new(obj.attrs(obj.attr_list)) : nil
+ obj ? self.new(obj) : nil
end
def all
bucket_objects.map do |wh_object|
- self.new(wh_object.attrs(wh_object.attr_list))
+ self.new(wh_object)
end
end
@@ -78,7 +86,7 @@ module Aeolus
self.set_warehouse_and_bucket if self.bucket.nil?
begin
if self.bucket.include?(uuid)
- self.new(self.bucket.object(uuid).attrs(self.bucket.object(uuid).attr_list))
+ self.new(self.bucket.object(uuid))
else
nil
end
--
1.7.6.4
12 years, 5 months
engineering expo presentation
by Mo Morsi
You may find my current working revision of my Upstate NY Engineering
Expo presentation on Aeolus here
http://mo.morsi.org/files/aeolus/engineering-expo.odp
The conference is a multi-disciplinary engineering conference w/
presentations from engineers of all backgrounds so I went over some
cloud computing basics before diving into Aeolus and what it can do for
the end-user.
Most of it is in place, but it isn't 100% complete, still working on
tightening it up and on the demo portion.
Take care,
-Mo
12 years, 5 months
[PATCH] Webhooks Notification API (rev. 1)
by Tomas Sedovic
This revision addresses the issues with the previous patch raised by Pádraig
Brady. Namely:
* Creating a new hook now sets the `Location` HTTP header properly
* `version` is stored in the database and displayed whenever a hook XML is shown
* Made aeolus-conductor.spec.in aware of the newly-added views
* Updated and simplified the tests
Note that as before, this implements only the registration portion of the
notification API. Sending events will happen post-1.0.
Thomas
12 years, 5 months
[PATCH conductor] Add webhooks registration API
by Tomas Sedovic
From: Tomas Sedovic <tsedovic(a)redhat.com>
https://www.aeolusproject.org/redmine/issues/2694
This will allow Pacemaker Cloud to register with Conductor. Conductor will
then be able to send Pacemaker Cloud notifications about instance and
deployable lifetime.
See this wiki page for the notification API spec:
https://www.aeolusproject.org/redmine/projects/aeolus/wiki/Pacemaker_Clou...
---
src/app/controllers/api/hooks_controller.rb | 74 +++++++
src/app/models/hook.rb | 3 +
src/app/views/api/hooks/_hook.xml.haml | 3 +
src/app/views/api/hooks/index.xml.haml | 4 +
src/app/views/api/hooks/show.xml.haml | 2 +
src/config/routes.rb | 2 +
src/db/migrate/20111101162621_create_hooks.rb | 13 ++
src/spec/controllers/api/hooks_controller_spec.rb | 226 +++++++++++++++++++++
8 files changed, 327 insertions(+), 0 deletions(-)
create mode 100644 src/app/controllers/api/hooks_controller.rb
create mode 100644 src/app/models/hook.rb
create mode 100644 src/app/views/api/hooks/_hook.xml.haml
create mode 100644 src/app/views/api/hooks/index.xml.haml
create mode 100644 src/app/views/api/hooks/show.xml.haml
create mode 100644 src/db/migrate/20111101162621_create_hooks.rb
create mode 100644 src/spec/controllers/api/hooks_controller_spec.rb
diff --git a/src/app/controllers/api/hooks_controller.rb b/src/app/controllers/api/hooks_controller.rb
new file mode 100644
index 0000000..e5e4d4c
--- /dev/null
+++ b/src/app/controllers/api/hooks_controller.rb
@@ -0,0 +1,74 @@
+#
+# 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 HooksController < ApplicationController
+ before_filter :require_user_api
+ rescue_from ActiveRecord::RecordNotFound, :with => :not_found
+
+ respond_to :xml
+ layout :false
+
+ def index
+ @hooks = Hook.all
+ respond_with(@hooks)
+ end
+
+ def show
+ @hook = Hook.find(params[:id])
+ respond_with(@hook)
+ end
+
+ def create
+ unless params[:hook]
+ head :status => 400 and return
+ end
+
+ version = params[:hook].delete :version
+ unless version == '1'
+ head :status => 501 and return
+ end
+
+ @hook = Hook.new params[:hook]
+ if @hook.save
+ render 'show', :status => :created
+ else
+ head :status => 400
+ end
+ end
+
+ def destroy
+ hook = Hook.find(params[:id])
+
+ if hook.destroy
+ head :status => 204
+ else
+ head :status => 500
+ end
+ end
+
+ private
+ def not_found
+ head :status => :not_found
+ end
+
+ end
+end
diff --git a/src/app/models/hook.rb b/src/app/models/hook.rb
new file mode 100644
index 0000000..35b4fc3
--- /dev/null
+++ b/src/app/models/hook.rb
@@ -0,0 +1,3 @@
+class Hook < ActiveRecord::Base
+ validates_presence_of :uri
+end
diff --git a/src/app/views/api/hooks/_hook.xml.haml b/src/app/views/api/hooks/_hook.xml.haml
new file mode 100644
index 0000000..73806d5
--- /dev/null
+++ b/src/app/views/api/hooks/_hook.xml.haml
@@ -0,0 +1,3 @@
+!!!XML
+%hook{:id => hook.id, :href => api_hook_url(hook.id) }
+ %uri= hook.uri
diff --git a/src/app/views/api/hooks/index.xml.haml b/src/app/views/api/hooks/index.xml.haml
new file mode 100644
index 0000000..94046b9
--- /dev/null
+++ b/src/app/views/api/hooks/index.xml.haml
@@ -0,0 +1,4 @@
+!!!XML
+%hooks
+ - @hooks.each do |hook|
+ = render :partial => 'hook', :locals => {:hook => hook}
diff --git a/src/app/views/api/hooks/show.xml.haml b/src/app/views/api/hooks/show.xml.haml
new file mode 100644
index 0000000..1c091c7
--- /dev/null
+++ b/src/app/views/api/hooks/show.xml.haml
@@ -0,0 +1,2 @@
+!!! XML
+= render :partial => "hook", :locals => {:hook => @hook}
diff --git a/src/config/routes.rb b/src/config/routes.rb
index dfba2a7..c11c216 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -207,6 +207,8 @@ Conductor::Application.routes.draw do
resources :provider_images
# :except => [:new, :edit]
+
+ resources :hooks
end
scope "/api" do
diff --git a/src/db/migrate/20111101162621_create_hooks.rb b/src/db/migrate/20111101162621_create_hooks.rb
new file mode 100644
index 0000000..8bf4792
--- /dev/null
+++ b/src/db/migrate/20111101162621_create_hooks.rb
@@ -0,0 +1,13 @@
+class CreateHooks < ActiveRecord::Migration
+ def self.up
+ create_table :hooks do |t|
+ t.string :uri
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :hooks
+ end
+end
diff --git a/src/spec/controllers/api/hooks_controller_spec.rb b/src/spec/controllers/api/hooks_controller_spec.rb
new file mode 100644
index 0000000..48f6ace
--- /dev/null
+++ b/src/spec/controllers/api/hooks_controller_spec.rb
@@ -0,0 +1,226 @@
+#
+# 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.
+
+require 'spec_helper'
+
+describe Api::HooksController do
+ render_views
+
+ context "when authenticated as admin" do
+
+ before(:each) do
+ send_and_accept_xml
+ @admin_permission = FactoryGirl.create :admin_permission
+ @admin = @admin_permission.user
+ mock_warden(@admin)
+ end
+
+ describe "#index" do
+
+ context "when there are no hooks" do
+
+ before(:each) do
+ get :index
+ end
+
+ it { response.should be_success }
+ it { response.headers['Content-Type'].should include("application/xml") }
+ it "should have no hooks" do
+ resp = Hash.from_xml(response.body)
+ resp['hooks']['hooks'].should be_nil
+ end
+
+ end
+
+ context "when there are 2 hooks" do
+
+ before(:each) do
+ @hooks = []
+ @hooks << Hook.new(:uri => 'http://example.com')
+ @hooks << Hook.new(:uri => 'https://pacemaker-cloud.org/events')
+ @hooks.each {|h| h.save}
+ get :index
+ end
+
+ it { response.should be_success }
+ it { response.headers['Content-Type'].should include("application/xml") }
+ it "should have hooks with correct attributes" do
+ resp = Hash.from_xml(response.body)
+ hooks = resp['hooks']['hook']
+
+ hooks.should have(2).things
+ hooks.first['uri'].should == @hooks.first.uri
+ hooks.last['uri'].should == @hooks.last.uri
+ end
+ end
+ end
+
+
+
+ describe "#show" do
+ context "when there are no hooks" do
+ before(:each) do
+ get :show, :id => 5
+ end
+
+ it { response.should_not be_success }
+ it { response.headers['Content-Type'].should include("application/xml") }
+
+ it "should return 404" do
+ response.status.should == 404
+ end
+
+ end
+
+ context "when there is 1 hook" do
+ before(:each) do
+ @hook = Hook.new(:uri => 'https://example.com')
+ @hook.save
+ end
+
+ it "should return the requested hook" do
+ get :show, :id => @hook.id
+
+ response.should be_success
+ response.headers['Content-Type'].should include("application/xml")
+
+ resp = Hash.from_xml(response.body)
+ hook = resp['hook']
+ hook.should_not be_blank
+ hook['uri'].should == @hook.uri
+ end
+
+ it "should return 404 for nonexistent hook" do
+ get :show, :id => 52983
+
+ response.status.should == 404
+ response.headers['Content-Type'].should include("application/xml")
+ end
+ end
+ end
+
+ describe "#create" do
+
+ it "should return 501 for unknown version" do
+ post :create, :hook => {
+ :uri => 'https://example.com',
+ :version => '2' }
+ response.status.should == 501
+ end
+
+ it "should return 501 for missing version" do
+ post :create, :hook => { :uri => 'https://example.com' }
+ response.status.should == 501
+ end
+
+ it "should return 400 for missing data" do
+ post :create
+ response.status.should == 400
+ end
+
+ it "should return 400 for invalid hook data" do
+ data = { :version => '1'}
+ post :create, :hook => data
+ response.status.should == 400
+
+ data[:uri] = ''
+ post :create, :hook => data
+ response.status.should == 400
+ end
+
+ it "should register a new hook" do
+ new_hook = { :uri => 'https://example.com', :version => '1' }
+ post :create, :hook => new_hook
+
+ response.should be_success
+ response.headers['Content-Type'].should include("application/xml")
+
+ resp = Hash.from_xml(response.body)
+ hook = resp['hook']
+ hook.should_not be_blank
+ hook['uri'].should == new_hook[:uri]
+ end
+
+ end
+
+ describe "#destroy" do
+ context "when there are no hooks" do
+ before(:each) do
+ delete :destroy, :id => 29830
+ end
+
+ it { response.should_not be_success }
+ it { response.headers['Content-Type'].should include("application/xml") }
+
+ it "should return 404" do
+ response.status.should == 404
+ end
+ end
+
+ context "when there is 1 hook" do
+ before(:each) do
+ @hook = Hook.new(:uri => 'https://example.com')
+ @hook.save
+ end
+
+ it "should delete requested hook" do
+ delete :destroy, :id => @hook.id
+
+ response.status.should == 204
+ end
+
+ it "should return 404 for nonexistent hook" do
+ delete :destroy, :id => 52983
+
+ response.status.should == 404
+ end
+ end
+ end
+ end
+
+ context "when not logged in" do
+
+ before(:each) do
+ send_and_accept_xml
+ @hook = Hook.new(:uri => 'https://example.com')
+ @hook.save
+ mock_warden(nil)
+ end
+
+ it "index should return 401" do
+ get :index
+ response.status.should == 401
+ end
+
+ it "show should return 401" do
+ get :show, :id => @hook.id
+ response.status.should == 401
+ end
+
+ it "create should return 401" do
+ post :create, :hook => { :uri => 'https://example.com', :version => '1' }
+ response.status.should == 401
+ end
+
+ it "destroy should return 401" do
+ delete :destroy, :id => @hook.id
+ response.status.should == 401
+ end
+ end
+
+end
--
1.7.6.4
12 years, 5 months