You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/01/07 11:27:53 UTC

Added use_config and changed initializer for client

Hi,

This patch will change the way how we initialize Ruby client.
For now, you need to pass username, password and URL as a separate
attributes.
I think that passing that as Hash will give us more flexibility
to use different configs.
Also I added 'use_config' method for client which will allow you
to switch driver and URL on initialized client instance.

Example:

config = {
  :ec2 => {
    :driver => 'ec2',
    :username => 'xxx',
    :password => 'xxx',
    :url => 'http://localhost:3001/api'
  },
  :mock => {
    :driver => 'mock',
    :username => 'mockuser',
    :password => 'mockpassword',
  },
  :rhevm => {
    :driver => 'rhevm',
    :username => 'admin@domain',
    :password => 'password',
  }
}

client = DeltaCloud::new(config[:ec2])
client.realms => will return EC2 realms

client.use_config! config[:mock]
client.realms => will return Mock realms

Let me know what do you think :-)


  -- Michal


[PATCH core] Added use_config! and changed initializer to use Hash options

Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>

---
 client/lib/deltacloud.rb |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
index 6985d5c..e8d6375 100644
--- a/client/lib/deltacloud.rb
+++ b/client/lib/deltacloud.rb
@@ -34,9 +34,15 @@ module DeltaCloud
   # @param [String, password] API password
   # @param [String, user_name] API URL (eg. http://localhost:3001/api)
   # @return [DeltaCloud::API]
-  def self.new(user_name, password, api_url, opts={}, &block)
-    opts ||= {}
-    API.new(user_name, password, api_url, opts, &block)
+  #def self.new(user_name, password, api_url, opts={}, &block)
+  #  opts ||= {}
+  #  API.new(user_name, password, api_url, opts, &block)
+  #end
+
+  def self.new(opts={}, &block)
+    opts ||={}
+    client = API.new(opts[:username], opts[:password], opts[:url], opts, &block)
+    client.use_driver(opts[:driver], opts) if opts[:driver]
   end
 
   # Check given credentials if their are valid against
@@ -256,6 +262,11 @@ module DeltaCloud
       return self
     end
 
+    def use_config!(opts={})
+      @api_uri = URI.parse(opts[:url]) if opts[:url]
+      use_driver(opts[:driver], opts)
+    end
+
     def extended_headers
       headers = {}
       headers["X-Deltacloud-Driver"] = @api_driver.to_s if @api_driver
-- 
1.7.3.4