incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 2/2] Added client support for listing supported drivers by API instance
Date Fri, 18 Feb 2011 13:05:19 GMT
From: Michal Fojtik <mfojtik@redhat.com>

---
 client/lib/deltacloud.rb |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
index 9975dc4..ae3fbe6 100644
--- a/client/lib/deltacloud.rb
+++ b/client/lib/deltacloud.rb
@@ -66,6 +66,27 @@ module DeltaCloud
     API.new(nil, nil, url).driver_name
   end
 
+  def self.drivers(url)
+    api = API.new(nil, nil, url)
+    drivers = {}
+    api::request(:get, '/drivers', {}) do |response|
+      response = Nokogiri::XML(response)
+      (response/"/api/drivers/driver").each do |d|
+        drivers[d[:id].to_sym] = { :name => (d/'name').text }
+        entrypoint = {}
+        (d/'entrypoints').each do |entrypoint|
+          entrypoint = (entrypoint/'entrypoint').collect { |e| { :id => e[:id], :url =>
e.text } }
+        end
+        drivers[d[:id].to_sym].merge!({ :entrypoints => entrypoint }) unless entrypoint.empty?
+        if (d/'credentials')
+          drivers[d[:id].to_sym].merge!({ :username => (d/'credentials/username').text})
if (d/'credentials/username')
+          drivers[d[:id].to_sym].merge!({ :password => (d/'credentials/password').text})
if (d/'credentials/password')
+        end
+      end
+    end
+    drivers
+  end
+
   class API
     attr_reader :api_uri, :driver_name, :api_version, :features, :entry_points
     attr_reader :api_driver, :api_provider
-- 
1.7.4


Mime
View raw message