You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by ma...@redhat.com on 2011/03/02 21:04:36 UTC
[PATCH 3/5] Fix display of blobs in a bucket (blob_list) when bucket requested by id
From: marios <ma...@redhat.com>
---
client/lib/base_object.rb | 18 ++++++++++++++++++
client/lib/deltacloud.rb | 7 ++++++-
client/lib/plain_formatter.rb | 11 +++++++++++
3 files changed, 35 insertions(+), 1 deletions(-)
diff --git a/client/lib/base_object.rb b/client/lib/base_object.rb
index 06db703..43d7ee5 100644
--- a/client/lib/base_object.rb
+++ b/client/lib/base_object.rb
@@ -100,6 +100,7 @@ module DeltaCloud
when :text then return m[:value]
when :property then return m[:property]
when :collection then return m[:values]
+ when :list then return m[:value].join(", ")
else raise NoHandlerForMethod
end
end
@@ -115,6 +116,23 @@ module DeltaCloud
end
end
+ # This method adds blobs to the blob_list property
+ # of a bucket
+ def add_blob!(blob_name)
+ if @blob_list.nil?
+ @blob_list = [blob_name]
+ @objects << {
+ :type => :list,
+ :method_name => "blob_list",
+ :value => @blob_list
+ }
+ else
+ @blob_list << blob_name
+ current = search_for_method('blob_list')
+ current[:value] = @blob_list
+ end
+ end
+
private
def search_for_method(name)
diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
index b1b3e6b..292305d 100644
--- a/client/lib/deltacloud.rb
+++ b/client/lib/deltacloud.rb
@@ -179,6 +179,7 @@ module DeltaCloud
# Add default attributes [id and href] to class
def base_object(model, response)
+
c = DeltaCloud.add_class("#{model}", DeltaCloud::guess_model_type(response))
xml_to_class(c, Nokogiri::XML(response).xpath("#{model.to_s.singularize}").first)
end
@@ -200,7 +201,6 @@ module DeltaCloud
# Traverse across XML document and deal with elements
item.xpath('./*').each do |attribute|
-
# Do a link for elements which are links to other REST models
if self.entry_points.keys.include?(:"#{attribute.name}s")
obj.add_link!(attribute.name, attribute['id']) && next
@@ -234,6 +234,11 @@ module DeltaCloud
obj.add_collection!(attribute.name, (attribute/'*').collect { |value| value.text }) && next
end
+ #deal with blobs for buckets
+ if(attribute.name == 'blob')
+ obj.add_blob!(attribute.attributes['id'].value) && next
+ end
+
# Anything else is treaten as text object
obj.add_text!(attribute.name, attribute.text.convert)
end
diff --git a/client/lib/plain_formatter.rb b/client/lib/plain_formatter.rb
index 89e92f9..ca29f3d 100644
--- a/client/lib/plain_formatter.rb
+++ b/client/lib/plain_formatter.rb
@@ -94,6 +94,17 @@ module DeltaCloud
end
end
+ class Bucket < Base
+ def format
+ sprintf("%-50s | %-50s | %-10s | %-1000s",
+ @obj.id[0,50],
+ @obj.name[0,50],
+ @obj.size ? @obj.size.to_s[0,10] : "",
+ @obj.blob_list ? @obj.blob_list[0,1000] : ""
+ )
+ end
+ end
+
end
def format(obj)
--
1.7.3.4