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/13 11:25:43 UTC

Added with_config method to deltacloud client

Hi,

This patch allow you to switch driver using just one instance of Deltacloud
API.
Example usage:

client = DeltaCloud.new('mockuser', 'mockdriver', 'http://localhost:3001/api')

client.with_config(:driver => 'rhevm', :username => '', :password => '') do |rhevm|
  rhevm.realms
end

  --  Michal


Re: [PATCH core] Added with_config method to client to allow switching drivers/providers using Ruby block syntax.

Posted by Michal Fojtik <mf...@redhat.com>.
On 14/01/11 17:06 -0800, David Lutterkort wrote:
>ACK, couple comments:
>
>On Thu, 2011-01-13 at 11:25 +0100, mfojtik@redhat.com wrote:
>> From: Michal Fojtik <mf...@redhat.com>
>>
>> ---
>>  client/lib/deltacloud.rb |    9 +++++++++
>>  1 files changed, 9 insertions(+), 0 deletions(-)
>>
>> diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
>> index 6985d5c..01cc2ca 100644
>> --- a/client/lib/deltacloud.rb
>> +++ b/client/lib/deltacloud.rb
>> @@ -77,6 +77,15 @@ module DeltaCloud
>>        yield self if block_given?
>>      end
>>
>> +    def with_config(opts, &block)
>
>Would be nice to document what goes into opts.

Agree, I'll put comment above.

>
>> +      api_instance = self.dup
>> +      api_instance.use_driver(opts[:driver],
>> +                             :username => opts[:username],
>> +                             :password => opts[:password],
>> +                             :provider => opts[:provider])
>> +      yield api_instance
>
>Isn't that missing a 'if block_given?' ?

You're right, I'll return api_instance in case that there is no block.


   -- Michal


-- 
--------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org
--------------------------------------------------------

Re: [PATCH core] Added with_config method to client to allow switching drivers/providers using Ruby block syntax.

Posted by David Lutterkort <lu...@redhat.com>.
ACK, couple comments:

On Thu, 2011-01-13 at 11:25 +0100, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
> 
> ---
>  client/lib/deltacloud.rb |    9 +++++++++
>  1 files changed, 9 insertions(+), 0 deletions(-)
> 
> diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
> index 6985d5c..01cc2ca 100644
> --- a/client/lib/deltacloud.rb
> +++ b/client/lib/deltacloud.rb
> @@ -77,6 +77,15 @@ module DeltaCloud
>        yield self if block_given?
>      end
>  
> +    def with_config(opts, &block)

Would be nice to document what goes into opts.

> +      api_instance = self.dup
> +      api_instance.use_driver(opts[:driver],
> +                             :username => opts[:username],
> +                             :password => opts[:password],
> +                             :provider => opts[:provider])
> +      yield api_instance

Isn't that missing a 'if block_given?' ?

David



[PATCH core] Added with_config method to client to allow switching drivers/providers using Ruby block syntax.

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

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

diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
index 6985d5c..01cc2ca 100644
--- a/client/lib/deltacloud.rb
+++ b/client/lib/deltacloud.rb
@@ -77,6 +77,15 @@ module DeltaCloud
       yield self if block_given?
     end
 
+    def with_config(opts, &block)
+      api_instance = self.dup
+      api_instance.use_driver(opts[:driver],
+                             :username => opts[:username],
+                             :password => opts[:password],
+                             :provider => opts[:provider])
+      yield api_instance
+    end
+
     def connect(&block)
       yield self
     end
-- 
1.7.3.4