You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by ma...@apache.org on 2011/03/11 20:47:01 UTC
svn commit: r1080740 - in /incubator/deltacloud/trunk/client:
bin/deltacloudc lib/deltacloud.rb lib/plain_formatter.rb
Author: marios
Date: Fri Mar 11 19:47:00 2011
New Revision: 1080740
URL: http://svn.apache.org/viewvc?rev=1080740&view=rev
Log:
Various fixes for ruby client to display buckets and blobs. Adds blob 'show' operation, buckets 'show' and 'index' with formatting.
Modified:
incubator/deltacloud/trunk/client/bin/deltacloudc
incubator/deltacloud/trunk/client/lib/deltacloud.rb
incubator/deltacloud/trunk/client/lib/plain_formatter.rb
Modified: incubator/deltacloud/trunk/client/bin/deltacloudc
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client/bin/deltacloudc?rev=1080740&r1=1080739&r2=1080740&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client/bin/deltacloudc (original)
+++ incubator/deltacloud/trunk/client/bin/deltacloudc Fri Mar 11 19:47:00 2011
@@ -60,6 +60,7 @@ Options:
BANNER
opts.on( '-i', '--id ID', 'ID for operation') { |id| options[:id] = id }
opts.on( '-d', '--image-id ID', 'Image ID') { |id| options[:image_id] = id }
+ opts.on( '-b', '--bucket-id ID', 'Bucket ID') {|id| options[:bucket_id] = id }
opts.on( '-a', '--arch ARCH', 'Architecture (x86, x86_64)') { |id| options[:architecture] = id }
opts.on( '-p', '--hardware-profile HARDWARE_PROFILE', 'Hardware Profile') { |id| options[:hwp_id] = id }
opts.on( '-n', '--name NAME', 'Name (for instance eg.)') { |name| options[:name] = name }
@@ -102,6 +103,8 @@ collections = client.entry_points.keys
# Exclude collection which don't have methods in client library yet
collections.delete(:instance_states)
+#add blob collection if buckets is present
+collections << :blob if collections.include?(:buckets)
# If list parameter passed print out available collection
# with API documentation
@@ -115,6 +118,11 @@ end
# If collection parameter is present and user requested list
# print all operation defined for collection with API documentation
if options[:list] and options[:collection]
+ #deal with blobs again - bypass 'normal' docs procedure
+ if options[:collection] =~ /blob/i
+ puts "show : Get details of a specified blob in a specified bucket (GET /api/buckets/:bucket/:blob)"
+ exit(0)
+ end
doc = client.documentation(options[:collection])
doc.operations.each do |c|
puts sprintf("%-20s: %s", c.operation, c.description)
@@ -131,6 +139,8 @@ end
# Do same if 'index' operation is set
if options[:collection] and ( options[:operation].nil? or options[:operation].eql?('index') )
invalid_usage("Unknown collection: #{options[:collection]}") unless collections.include?(options[:collection].to_sym)
+#cannot list blobs - can only show a specific blob
+ invalid_usage("You must specify a particular blob with -i and a particular bucket with -b") if options[:collection] =~ (/blob/i)
params = {}
params.merge!(:architecture => options[:architecture]) if options[:architecture]
params.merge!(:id => options[:id]) if options[:id]
@@ -150,6 +160,17 @@ if options[:collection] and options[:ope
# If collection is set and requested operation is 'show' just 'singularize'
# collection name and print item with specified id (-i parameter)
+
+ #Blobs are a special case so deal with first -
+ if options[:operation].eql?('show') && options[:collection] =~ (/blob/i)
+ invalid_usage("Please specify the bucket for this blob using the -b option") unless options[:bucket_id]
+ invalid_usage("Missing blob ID, please specify with -i option") unless options[:id]
+ params = {}
+ params.merge!(:id => options[:id], 'bucket' => options[:bucket_id])
+ puts format(client.send( options[:collection], params))
+ exit(0)
+ end
+
if options[:operation].eql?('show')
invalid_usage("Missing ID, must be provided with --id") unless options[:id]
puts format(client.send(options[:collection].gsub(/s$/, ''), options[:id]))
Modified: incubator/deltacloud/trunk/client/lib/deltacloud.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client/lib/deltacloud.rb?rev=1080740&r1=1080739&r2=1080740&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client/lib/deltacloud.rb (original)
+++ incubator/deltacloud/trunk/client/lib/deltacloud.rb Fri Mar 11 19:47:00 2011
@@ -146,7 +146,6 @@ module DeltaCloud
# Define methods based on 'rel' attribute in entry point
# Two methods are declared: 'images' and 'image'
def declare_entry_points_methods(entry_points)
-
API.instance_eval do
entry_points.keys.select {|k| [:instance_states].include?(k)==false }.each do |model|
@@ -167,8 +166,20 @@ module DeltaCloud
self.send(model.to_s.singularize.to_sym, $1)
end
+ end
+
+ #define methods for blobs:
+ if(entry_points.include?(:buckets))
+ define_method :"blob" do |*args|
+ bucket = args[0]["bucket"]
+ blob = args[0][:id]
+ request(:get, "#{entry_points[:buckets]}/#{bucket}/#{blob}") do |response|
+ base_object("blob", response)
+ end
end
end
+
+ end
end
def base_object_collection(model, response)
@@ -179,7 +190,6 @@ 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
@@ -201,9 +211,10 @@ 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
+ obj.add_link!(attribute.name, attribute['id']) && next unless (attribute.name == 'bucket' && item.name == 'blob')
end
# Do a HWP property for hardware profile properties
@@ -242,7 +253,6 @@ module DeltaCloud
# Anything else is treaten as text object
obj.add_text!(attribute.name, attribute.text.convert)
end
-
return obj
end
Modified: incubator/deltacloud/trunk/client/lib/plain_formatter.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client/lib/plain_formatter.rb?rev=1080740&r1=1080739&r2=1080740&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client/lib/plain_formatter.rb (original)
+++ incubator/deltacloud/trunk/client/lib/plain_formatter.rb Fri Mar 11 19:47:00 2011
@@ -96,11 +96,24 @@ module DeltaCloud
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] : ""
+ sprintf("%-s | %-s | %-s | %-s",
+ @obj.id,
+ @obj.name,
+ @obj.size ? @obj.size : "0",
+ @obj.blob_list ? @obj.blob_list : ""
+ )
+ end
+ end
+
+ class Blob < Base
+ def format
+ sprintf("%-s | %-s | %-d | %-s | %-s | %-s " ,
+ @obj.id,
+ @obj.bucket,
+ @obj.content_length,
+ @obj.content_type,
+ @obj.last_modified,
+ @obj.user_metadata
)
end
end