You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by lu...@apache.org on 2010/07/09 01:48:39 UTC
svn commit: r962351 - in /incubator/deltacloud/trunk: server/ server/lib/
server/lib/deltacloud/helpers/ server/lib/sinatra/ tests/ec2/ tests/mock/
Author: lutter
Date: Thu Jul 8 23:48:39 2010
New Revision: 962351
URL: http://svn.apache.org/viewvc?rev=962351&view=rev
Log:
Removed builder dependency from gemspec
Fixed error reporting in Sinatra
Changed reported API version to 0.1
Modified:
incubator/deltacloud/trunk/server/deltacloud-core.gemspec
incubator/deltacloud/trunk/server/deltacloud.rb
incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb
incubator/deltacloud/trunk/server/lib/drivers.rb
incubator/deltacloud/trunk/server/lib/sinatra/respond_to.rb
incubator/deltacloud/trunk/server/server.rb
incubator/deltacloud/trunk/tests/ec2/api.feature
incubator/deltacloud/trunk/tests/mock/api.feature
Modified: incubator/deltacloud/trunk/server/deltacloud-core.gemspec
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/deltacloud-core.gemspec?rev=962351&r1=962350&r2=962351&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/deltacloud-core.gemspec (original)
+++ incubator/deltacloud/trunk/server/deltacloud-core.gemspec Thu Jul 8 23:48:39 2010
@@ -62,7 +62,6 @@ require 'rake'
s.add_dependency('rack', '>= 1.0.0')
s.add_dependency('thin', '>= 1.2.5')
s.add_dependency('rerun', '>= 0.5.2')
- s.add_dependency('builder', '>= 2.1.2')
s.add_dependency('json', '>= 1.2.3')
s.add_development_dependency('compass', '>= 0.8.17')
s.add_development_dependency('nokogiri', '>= 1.4.1')
Modified: incubator/deltacloud/trunk/server/deltacloud.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/deltacloud.rb?rev=962351&r1=962350&r2=962351&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/deltacloud.rb (original)
+++ incubator/deltacloud/trunk/server/deltacloud.rb Thu Jul 8 23:48:39 2010
@@ -12,3 +12,6 @@ require 'deltacloud/models/instance'
require 'deltacloud/models/instance_profile'
require 'deltacloud/models/storage_snapshot'
require 'deltacloud/models/storage_volume'
+
+require 'deltacloud/validation'
+require 'deltacloud/helpers'
Modified: incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb?rev=962351&r1=962350&r2=962351&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb Thu Jul 8 23:48:39 2010
@@ -53,4 +53,52 @@ module ApplicationHelper
return 'password' if driver_has_feature?(:authentication_password)
end
+ def filter_all(model)
+ filter = {}
+ filter.merge!(:id => params[:id]) if params[:id]
+ filter.merge!(:architecture => params[:architecture]) if params[:architecture]
+ filter.merge!(:owner_id => params[:owner_id]) if params[:owner_id]
+ filter.merge!(:state => params[:state]) if params[:state]
+ filter = nil if filter.keys.size.eql?(0)
+ singular = model.to_s.singularize.to_sym
+ @elements = driver.send(model.to_sym, credentials, filter)
+ instance_variable_set(:"@#{model}", @elements)
+ respond_to do |format|
+ format.html { haml :"#{model}/index" }
+ format.xml { haml :"#{model}/index" }
+ format.json { convert_to_json(singular, @elements) }
+ end
+ end
+
+ def show(model)
+ @element = driver.send(model, credentials, { :id => params[:id]} )
+ instance_variable_set("@#{model}", @element)
+ respond_to do |format|
+ format.html { haml :"#{model.to_s.pluralize}/show" }
+ format.xml { haml :"#{model.to_s.pluralize}/show" }
+ format.json { convert_to_json(model, @element) }
+ end
+ end
+
+ def report_error(status, template)
+ @error = request.env['sinatra.error']
+ response.status = status
+ respond_to do |format|
+ format.xml { haml :"errors/#{template}", :layout => false }
+ format.html { haml :"errors/#{template}" }
+ end
+ end
+
+ def instance_action(name)
+ @instance = driver.send(:"#{name}_instance", credentials, params["id"])
+
+ return redirect(instances_url) if name.eql?(:destroy) or @instance.class!=Instance
+
+ respond_to do |format|
+ format.html { haml :"instances/show" }
+ format.xml { haml :"instances/show" }
+ format.json {convert_to_json(:instance, @instance) }
+ end
+ end
+
end
Modified: incubator/deltacloud/trunk/server/lib/drivers.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/drivers.rb?rev=962351&r1=962350&r2=962351&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/drivers.rb (original)
+++ incubator/deltacloud/trunk/server/lib/drivers.rb Thu Jul 8 23:48:39 2010
@@ -9,6 +9,8 @@ DRIVERS = {
:mock => { :name => "Mock" }
}
+DRIVER=ENV['API_DRIVER'] ? ENV['API_DRIVER'].to_sym : :mock
+
def driver_name
DRIVERS[DRIVER][:name]
end
Modified: incubator/deltacloud/trunk/server/lib/sinatra/respond_to.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/sinatra/respond_to.rb?rev=962351&r1=962350&r2=962351&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/sinatra/respond_to.rb (original)
+++ incubator/deltacloud/trunk/server/lib/sinatra/respond_to.rb Thu Jul 8 23:48:39 2010
@@ -267,3 +267,6 @@ module Sinatra
end
end
end
+
+Rack::Mime::MIME_TYPES.merge!({ ".gv" => "text/plain" })
+Sinatra::Application.register Sinatra::RespondTo
Modified: incubator/deltacloud/trunk/server/server.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/server.rb?rev=962351&r1=962350&r2=962351&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/server.rb (original)
+++ incubator/deltacloud/trunk/server/server.rb Thu Jul 8 23:48:39 2010
@@ -1,21 +1,18 @@
-require 'rubygems'
require 'deltacloud'
+require 'drivers'
require 'json'
require 'sinatra'
require 'sinatra/respond_to'
-require 'erb'
-require 'haml'
-require 'open3'
-require 'builder'
-require 'drivers'
require 'sinatra/static_assets'
require 'sinatra/rabbit'
require 'sinatra/lazy_auth'
-require 'deltacloud/validation'
-require 'deltacloud/helpers'
+require 'erb'
+require 'haml'
+require 'open3'
configure do
set :raise_errors => false
+ set :show_exceptions, false
end
configure :development do
@@ -24,59 +21,10 @@ configure :development do
$stderr.sync = true
end
-DRIVER=ENV['API_DRIVER'] ? ENV['API_DRIVER'].to_sym : :mock
-
# You could use $API_HOST environment variable to change your hostname to
# whatever you want (eg. if you running API behind NAT)
HOSTNAME=ENV['API_HOST'] ? ENV['API_HOST'] : nil
-Rack::Mime::MIME_TYPES.merge!({ ".gv" => "text/plain" })
-
-Sinatra::Application.register Sinatra::RespondTo
-
-# Common actions
-#
-
-def filter_all(model)
- filter = {}
- filter.merge!(:id => params[:id]) if params[:id]
- filter.merge!(:architecture => params[:architecture]) if params[:architecture]
- filter.merge!(:owner_id => params[:owner_id]) if params[:owner_id]
- filter.merge!(:state => params[:state]) if params[:state]
- filter = nil if filter.keys.size.eql?(0)
- singular = model.to_s.singularize.to_sym
- @elements = driver.send(model.to_sym, credentials, filter)
- instance_variable_set(:"@#{model}", @elements)
- respond_to do |format|
- format.html { haml :"#{model}/index" }
- format.xml { haml :"#{model}/index" }
- format.json { convert_to_json(singular, @elements) }
- end
-end
-
-def show(model)
- @element = driver.send(model, credentials, { :id => params[:id]} )
- instance_variable_set("@#{model}", @element)
- respond_to do |format|
- format.html { haml :"#{model.to_s.pluralize}/show" }
- format.xml { haml :"#{model.to_s.pluralize}/show" }
- format.json { convert_to_json(model, @element) }
- end
-end
-
-
-#
-# Error handlers
-#
-def report_error(status, template)
- @error = request.env['sinatra.error']
- response.status = status
- respond_to do |format|
- format.xml { haml :"errors/#{template}", :layout => false }
- format.html { haml :"errors/#{template}" }
- end
-end
-
error Deltacloud::Validation::Failure do
report_error(400, "validation_failure")
end
@@ -93,7 +41,7 @@ end
get '/' do redirect '/api'; end
get '/api\/?' do
- @version = 1.0
+ @version = 0.1
respond_to do |format|
format.xml { haml :"api/show" }
format.json do
@@ -111,10 +59,20 @@ end
# Rabbit DSL
collection :realms do
- description "Within a cloud provider a realm represents a boundary containing resources. The exact definition of a realm is left to the cloud provider. In some cases, a realm may represent different datacenters, different continents, or different pools of resources within a single datacenter. A cloud provider may insist that resources must all exist within a single realm in order to cooperate. For instance, storage volumes may only be allowed to be mounted to instances within the same realm."
+ description <<END
+ Within a cloud provider a realm represents a boundary containing resources.
+ The exact definition of a realm is left to the cloud provider.
+ In some cases, a realm may represent different datacenters, different continents,
+ or different pools of resources within a single datacenter.
+ A cloud provider may insist that resources must all exist within a single realm in
+ order to cooperate. For instance, storage volumes may only be allowed to be mounted to
+ instances within the same realm.
+END
operation :index do
- description 'Operation will list all available realms. For specific architecture use "architecture" parameter.'
+ description <<END
+ Operation will list all available realms. For specific architecture use "architecture" parameter.
+END
param :id, :string
param :architecture, :string, :optional, [ 'i386', 'x86_64' ]
control { filter_all(:realms) }
@@ -130,10 +88,17 @@ collection :realms do
end
collection :images do
- description "An image is a platonic form of a machine. Images are not directly executable, but are a template for creating actual instances of machines."
+ description <<END
+ An image is a platonic form of a machine. Images are not directly executable,
+ but are a template for creating actual instances of machines."
+END
operation :index do
- description 'The instances collection will return a set of all images available to the current use. You can filter images using "owner_id" and "architecture" parameter'
+ description <<END
+ The instances collection will return a set of all images
+ available to the current use. You can filter images using
+ "owner_id" and "architecture" parameter
+END
param :id, :string
param :owner_id, :string
param :architecture, :string, :optional
@@ -196,20 +161,11 @@ get "/api/instances/new" do
end
end
-def instance_action(name)
- @instance = driver.send(:"#{name}_instance", credentials, params["id"])
-
- return redirect(instances_url) if name.eql?(:destroy) or @instance.class!=Instance
-
- respond_to do |format|
- format.html { haml :"instances/show" }
- format.xml { haml :"instances/show" }
- format.json {convert_to_json(:instance, @instance) }
- end
-end
-
collection :instances do
- description "An instance is a concrete machine realized from an image. The images collection may be obtained by following the link from the primary entry-point."
+ description <<END
+ An instance is a concrete machine realized from an image.
+ The images collection may be obtained by following the link from the primary entry-point."
+END
operation :index do
description "List all instances"
Modified: incubator/deltacloud/trunk/tests/ec2/api.feature
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/tests/ec2/api.feature?rev=962351&r1=962350&r2=962351&view=diff
==============================================================================
--- incubator/deltacloud/trunk/tests/ec2/api.feature (original)
+++ incubator/deltacloud/trunk/tests/ec2/api.feature Thu Jul 8 23:48:39 2010
@@ -6,7 +6,7 @@ Feature: Accessing API entry points
When client access this URI
Then client should get root element 'api'
And this element should have attribute 'driver' with value 'ec2'
- And this element should have attribute 'version' with value '1.0'
+ And this element should have attribute 'version' with value '0.1'
Scenario: List of entry points
Given URI /api exists
Modified: incubator/deltacloud/trunk/tests/mock/api.feature
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/tests/mock/api.feature?rev=962351&r1=962350&r2=962351&view=diff
==============================================================================
--- incubator/deltacloud/trunk/tests/mock/api.feature (original)
+++ incubator/deltacloud/trunk/tests/mock/api.feature Thu Jul 8 23:48:39 2010
@@ -6,7 +6,7 @@ Feature: Accessing API entry points
When client access this URI
Then client should get root element 'api'
And this element should have attribute 'driver' with value 'mock'
- And this element should have attribute 'version' with value '1.0'
+ And this element should have attribute 'version' with value '0.1'
Scenario: List of entry points
Given URI /api exists