deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 14/26] Core: Added possiblity to list all Rabbit defined routes by rake rabbit:routes
Date Tue, 15 May 2012 15:15:46 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/Rakefile  |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 server/config.ru |   40 +++++++++++++++++-----------------------
 2 files changed, 68 insertions(+), 23 deletions(-)

diff --git a/server/Rakefile b/server/Rakefile
index 147cdcf..5d205ce 100644
--- a/server/Rakefile
+++ b/server/Rakefile
@@ -193,3 +193,54 @@ namespace :mock do
 
   end
 end
+
+namespace :openshift do
+
+  desc "Deploy Deltacloud API to OpenShift"
+  task :deploy do
+    print "RHN or OpenShift login with OpenShift Express access: "
+    STDOUT.flush
+    login = STDIN.gets.chomp
+    print "Password: "
+    system "stty -echo"
+    password = STDIN.gets.chomp
+    system "stty echo"
+    puts `rhc-create-app --rhlogin #{login} --app deltacloudtest --password '#{password}'
--type ruby-1.8`
+  end
+end
+
+namespace :rabbit do
+  load File.join(File.dirname(__FILE__), 'config.ru')
+
+  desc "List the routes defined by Rabbit"
+  task :routes do
+    Deltacloud.collections.each do |c|
+      puts "\033[1;32;m#{c.name}\33[0m"
+      c.operations.each do |o|
+        puts "\033[1;37m%6s\033[0m :%-10s %-30s (%s)" % [
+          o.http_method.to_s.upcase,
+          o.operation_name,
+          o.full_path,
+          o.description[0..100]
+        ]
+      end
+      unless c.collections.empty?
+        puts
+        c.collections.each do |s|
+          puts "\033[1;32;m#{s.name}\33[0m"
+          s.operations.each do |o|
+            puts "\033[1;37m%6s\033[0m :%-10s %-30s (%s)" % [
+              o.http_method.to_s.upcase,
+              o.operation_name,
+              o.full_path,
+              o.description[0..100]
+            ]
+          end
+        end
+      end
+      puts
+    end
+  end
+
+end
+
diff --git a/server/config.ru b/server/config.ru
index f17de43..2280d0e 100644
--- a/server/config.ru
+++ b/server/config.ru
@@ -22,6 +22,7 @@ ENV['API_DRIVER'] ||= 'mock'
 # Set the API frontend use ('cimi' or 'deltacloud', default is 'deltacloud')
 ENV['API_FRONTEND'] ||= 'deltacloud'
 
+
 # We need to set different API version and entrypoint location
 if ENV['API_FRONTEND'] == 'deltacloud'
   API_VERSION = "9.9.9"
@@ -31,29 +32,22 @@ elsif ENV['API_FRONTEND'] == 'cimi'
   API_ROOT_URL = "/cloudEntryPoint"
 end
 
-#begin
-  require File.join(File.dirname(__FILE__), 'lib', ENV['API_FRONTEND'], 'server.rb')
-#rescue LoadError => e
-#  puts "[ERROR] The specified frontend (#{ENV['API_FRONTEND']}) not supported (#{e.message})"
-#  exit 1
-#end
-
-if self.respond_to? :map
-  map "/" do
-    class IndexEntrypoint < Sinatra::Base
-      get "/" do
-        redirect API_ROOT_URL, 301
-      end
-    end
-    run IndexEntrypoint
-  end
+require File.join(File.dirname(__FILE__), 'lib', ENV['API_FRONTEND'], 'server.rb')
 
-  map API_ROOT_URL do
-    use Rack::Static, :urls => ["/stylesheets", "/javascripts"], :root => "public"
-    use Rack::Session::Cookie
-    case ENV['API_FRONTEND']
-      when 'deltacloud' then run Rack::Cascade.new([Deltacloud::API])
-      when 'cimi' then run Rack::Cascade.new([CIMI::API])
-    end
+frontend_klass = case ENV['API_FRONTEND']
+  when 'deltacloud' then Deltacloud::API
+  when 'cimi' then CIMI::API
+end
+
+class IndexEntrypoint < Sinatra::Base
+  get "/" do
+    redirect API_ROOT_URL, 301
   end
 end
+
+run Rack::URLMap.new(
+  "/" => IndexEntrypoint.new,
+  API_ROOT_URL => frontend_klass.new,
+  "/stylesheets" =>  Rack::Directory.new( "public/stylesheets" ),
+  "/javascripts" =>  Rack::Directory.new( "public/javascripts" )
+) if respond_to? :run
-- 
1.7.10.1


Mime
View raw message