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/04/05 11:12:35 UTC
Added support for drivers collection to client
Hi,
This patch extend client to support new drivers collection.
Few examples how it works:
client = DeltaCloud::new('mockuser', 'mockpassword', 'http://localhost:3001/api')
pp client.drivers[1].id => "ec2"
pp client.drivers[1].name => "EC2"
pp client.driver('ec2').providers => ["us-west-1", "ap-southeast-1", "eu-west-1", "us-east-1"]
pp client.driver('ec2').provider('us-west-1') => [{"s3"=>"s3-us-west-1.amazonaws.com"}, {"elb"=>"elasticloadbalancing.us-west-1.amazonaws.com"}, {"ec2"=>"ec2.us-west-1.amazonaws.com"}]
-- Michal
[PATCH core] Added drivers collection to client.
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
---
client/lib/base_object.rb | 15 +++++++++++++++
client/lib/deltacloud.rb | 12 ++++++++++--
server/views/drivers/index.xml.haml | 6 ++++--
server/views/drivers/show.xml.haml | 10 ++++++----
4 files changed, 35 insertions(+), 8 deletions(-)
diff --git a/client/lib/base_object.rb b/client/lib/base_object.rb
index 43d7ee5..2050589 100644
--- a/client/lib/base_object.rb
+++ b/client/lib/base_object.rb
@@ -92,11 +92,26 @@ module DeltaCloud
}
end
+ def add_providers!(values)
+ @objects << {
+ :type => :provider,
+ :method_name => 'provider',
+ :values => values
+ }
+ @objects << {
+ :type => :providers,
+ :method_name => 'providers',
+ :values => values.keys
+ }
+ end
+
# Basic method hander. This define a way how value from property
# will be returned
def method_handler(m, args=[])
case m[:type]
when :link then return @client.send(m[:method_name].singularize, m[:id])
+ when :provider then m[:values][args.first]
+ when :providers then m[:values]
when :text then return m[:value]
when :property then return m[:property]
when :collection then return m[:values]
diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
index e2db0ba..37e04fa 100644
--- a/client/lib/deltacloud.rb
+++ b/client/lib/deltacloud.rb
@@ -234,8 +234,16 @@ module DeltaCloud
obj.add_collection!(attribute.name, meta.inspect) && next
end
- # Deal with collections like public-addresses, private-addresses
- if (attribute/'./*').length > 0
+ if (attribute/'provider').length > 0
+ providers = {}
+ (attribute/'provider').each do |provider|
+ providers[provider[:id]] = (provider/'entrypoint').collect { |e| { e[:kind] => e.text } }
+ end
+ obj.add_providers!(providers) && next
+ end
+
+ # Add special collection for driver providers
+ if not (attribute/'*').to_a.empty?
obj.add_collection!(attribute.name, (attribute/'*').collect { |value| value.text }) && next
end
diff --git a/server/views/drivers/index.xml.haml b/server/views/drivers/index.xml.haml
index 63e809f..afa4b28 100644
--- a/server/views/drivers/index.xml.haml
+++ b/server/views/drivers/index.xml.haml
@@ -3,5 +3,7 @@
%driver{ :href => driver_url(id), :id => id }
%name<
=details[:name]
- - driver_provider(details).keys.each do |prov|
- %provider{ :id => prov }
+ - unless driver_provider(details).keys.empty?
+ %providers
+ - driver_provider(details).keys.each do |prov|
+ %provider{ :id => prov }
diff --git a/server/views/drivers/show.xml.haml b/server/views/drivers/show.xml.haml
index ea5f508..b8afead 100644
--- a/server/views/drivers/show.xml.haml
+++ b/server/views/drivers/show.xml.haml
@@ -1,7 +1,9 @@
%driver{ :href => driver_url(@name), :id => @name }
%name<
= @driver[:name]
- - driver_provider(@driver).each do |prov, details|
- %provider{ :id => prov }
- - details.each do |kind, url|
- %entrypoint{ :kind => kind }<=cdata(url)
+ - unless driver_provider(@driver).empty?
+ %providers
+ - driver_provider(@driver).each do |prov, details|
+ %provider{ :id => prov }
+ - details.each do |kind, url|
+ %entrypoint{ :kind => kind }<=cdata(url)
--
1.7.4.1