Return-Path: Delivered-To: apmail-incubator-deltacloud-dev-archive@minotaur.apache.org Received: (qmail 91187 invoked from network); 28 Mar 2011 23:42:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 28 Mar 2011 23:42:00 -0000 Received: (qmail 49498 invoked by uid 500); 28 Mar 2011 23:42:00 -0000 Delivered-To: apmail-incubator-deltacloud-dev-archive@incubator.apache.org Received: (qmail 49479 invoked by uid 500); 28 Mar 2011 23:42:00 -0000 Mailing-List: contact deltacloud-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: deltacloud-dev@incubator.apache.org Delivered-To: mailing list deltacloud-dev@incubator.apache.org Received: (qmail 49471 invoked by uid 99); 28 Mar 2011 23:42:00 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Mar 2011 23:42:00 +0000 X-ASF-Spam-Status: No, hits=-5.0 required=5.0 tests=RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of lutter@redhat.com designates 209.132.183.28 as permitted sender) Received: from [209.132.183.28] (HELO mx1.redhat.com) (209.132.183.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Mar 2011 23:41:52 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2SNfULj003543 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 28 Mar 2011 19:41:30 -0400 Received: from avon.watzmann.net (ovpn-113-147.phx2.redhat.com [10.3.113.147]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p2SNfTYe000805 for ; Mon, 28 Mar 2011 19:41:29 -0400 From: lutter@redhat.com To: deltacloud-dev@incubator.apache.org Subject: [PATCH 2/3] drivers: new collection Date: Mon, 28 Mar 2011 16:41:21 -0700 Message-Id: <1301355682-17465-3-git-send-email-lutter@redhat.com> In-Reply-To: <1301355682-17465-1-git-send-email-lutter@redhat.com> References: <1301355682-17465-1-git-send-email-lutter@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Virus-Checked: Checked by ClamAV on apache.org From: David Lutterkort --- .../lib/deltacloud/helpers/application_helper.rb | 14 ++++++ server/server.rb | 43 ++++++++++++++++--- server/views/api/drivers.html.haml | 14 ------ server/views/api/drivers.xml.haml | 11 ----- server/views/api/show.html.haml | 2 +- server/views/drivers/index.html.haml | 15 +++++++ server/views/drivers/index.xml.haml | 7 +++ 7 files changed, 73 insertions(+), 33 deletions(-) delete mode 100644 server/views/api/drivers.html.haml delete mode 100644 server/views/api/drivers.xml.haml create mode 100644 server/views/drivers/index.html.haml create mode 100644 server/views/drivers/index.xml.haml diff --git a/server/lib/deltacloud/helpers/application_helper.rb b/server/lib/deltacloud/helpers/application_helper.rb index 4ee0480..345aaff 100644 --- a/server/lib/deltacloud/helpers/application_helper.rb +++ b/server/lib/deltacloud/helpers/application_helper.rb @@ -204,4 +204,18 @@ module ApplicationHelper "#{text[0..(length/2)]}#{end_string}" end + # Reverse the entrypoints hash for a driver from drivers.yaml; note that + # +d+ is a hash, not an actual driver object + def driver_provider(d) + result = {} + if d[:entrypoints] + d[:entrypoints].each do |kind, details| + details.each do |prov, url| + result[prov] ||= {} + result[prov][kind] = url + end + end + end + result + end end diff --git a/server/server.rb b/server/server.rb index 3c4273c..d287031 100644 --- a/server/server.rb +++ b/server/server.rb @@ -83,17 +83,11 @@ Sinatra::Application.register Sinatra::RespondTo # Redirect to /api get '/' do redirect url_for('/api'), 301; end -get '/api/drivers\/?' do - respond_to do |format| - format.xml { haml :"api/drivers" } - format.html { haml :"api/drivers" } - end -end - get '/api\/?' do if params[:force_auth] return [401, 'Authentication failed'] unless driver.valid_credentials?(credentials) end + @collections = [:drivers] + driver.supported_collections respond_to do |format| format.xml { haml :"api/show" } format.json do @@ -110,6 +104,41 @@ end # Rabbit DSL +collection :drivers do + global! + + description < '20%' } - %tt= id - %td= details[:name] diff --git a/server/views/api/drivers.xml.haml b/server/views/api/drivers.xml.haml deleted file mode 100644 index 93975f0..0000000 --- a/server/views/api/drivers.xml.haml +++ /dev/null @@ -1,11 +0,0 @@ -%api{ :version => settings.version } - %drivers - - settings.drivers.each do |id, details| - %driver{ :id => id } - %name< - =details[:name] - - if details[:entrypoints] - - details[:entrypoints].each do |list_id, entrypoints| - %entrypoints{:id => list_id} - - entrypoints.each do |entrypoint, url| - %entrypoint{ :id => entrypoint }<=cdata(url) diff --git a/server/views/api/show.html.haml b/server/views/api/show.html.haml index 199c9fd..287b989 100644 --- a/server/views/api/show.html.haml +++ b/server/views/api/show.html.haml @@ -2,7 +2,7 @@ Deltacloud API #{settings.version} %ul - - driver.supported_collections.sort_by { |k| k.to_s }.each do |key| + - @collections.sort_by { |k| k.to_s }.each do |key| %li = link_to key.to_s.gsub('_', ' ').titlecase, url_for("/api/#{key}") %dl diff --git a/server/views/drivers/index.html.haml b/server/views/drivers/index.html.haml new file mode 100644 index 0000000..fc35115 --- /dev/null +++ b/server/views/drivers/index.html.haml @@ -0,0 +1,15 @@ +%h1 + Available Drivers + +%table.display + %thead + %tr + %th ID + %th Name + %tbody + - @drivers.each do |id, details| + %tr + %td{ :width => '20%' } + %tt + %a{ :href => driver_url(id) }= id + %td= details[:name] diff --git a/server/views/drivers/index.xml.haml b/server/views/drivers/index.xml.haml new file mode 100644 index 0000000..63e809f --- /dev/null +++ b/server/views/drivers/index.xml.haml @@ -0,0 +1,7 @@ +%drivers + - @drivers.each do |id, details| + %driver{ :href => driver_url(id), :id => id } + %name< + =details[:name] + - driver_provider(details).keys.each do |prov| + %provider{ :id => prov } -- 1.7.4