Please note, that you will need my XML documentation patches [1] applied in order to get this work.
[1] https://fedorahosted.org/pipermail/deltacloud-devel/2010-February/000464.htm...
--- client/lib/dcloud/flavor.rb | 6 ++++++ client/lib/dcloud/image.rb | 10 ++++++++++ client/lib/dcloud/instance.rb | 11 +++++++++++ client/lib/dcloud/realm.rb | 10 ++++++++++ client/lib/dcloud/storage_snapshot.rb | 9 +++++++++ client/lib/dcloud/storage_volume.rb | 10 ++++++++++ 6 files changed, 56 insertions(+), 0 deletions(-)
diff --git a/client/lib/dcloud/flavor.rb b/client/lib/dcloud/flavor.rb index 4cbba45..7703e77 100644 --- a/client/lib/dcloud/flavor.rb +++ b/client/lib/dcloud/flavor.rb @@ -39,5 +39,11 @@ module DCloud @architecture = xml.text( 'architecture' ) end end + + def to_plain + sprintf("%-15s | %-6s | %10s GB | %10s GB", self.id[0, 15], self.architecture[0,6], + self.memory.to_s[0,10], self.storage.to_s[0,10]) + end + end end diff --git a/client/lib/dcloud/image.rb b/client/lib/dcloud/image.rb index 220de21..c76df8f 100644 --- a/client/lib/dcloud/image.rb +++ b/client/lib/dcloud/image.rb @@ -42,5 +42,15 @@ module DCloud end end
+ def to_plain + sprintf("%-10s | %-20s | %-6s | %-20s | %15s", + self.id[0,10], + self.name ? self.name[0, 20]: 'unknown', + self.architecture[0,6], + self.description[0,20], + self.owner_id[0,15] + ) + end + end end diff --git a/client/lib/dcloud/instance.rb b/client/lib/dcloud/instance.rb index 9115e9a..557b5e8 100644 --- a/client/lib/dcloud/instance.rb +++ b/client/lib/dcloud/instance.rb @@ -39,6 +39,17 @@ module DCloud super( client, uri, xml ) end
+ def to_plain + sprintf("%-15s | %-15s | %-15s | %10s | %32s | %32s", + self.id ? self.id[0,15] : '-', + self.name ? self.name[0,15] : 'unknown', + self.image.name ? self.image.name[0,15] : 'unknown', + self.state ? self.state.to_s[0,10] : 'unknown', + self.public_addresses.join(',')[0,32], + self.private_addresses.join(',')[0,32] + ) + end + def start!() url = action_urls['start'] throw Exception.new( "Unable to start" ) unless url diff --git a/client/lib/dcloud/realm.rb b/client/lib/dcloud/realm.rb index c00d218..0250f48 100644 --- a/client/lib/dcloud/realm.rb +++ b/client/lib/dcloud/realm.rb @@ -43,5 +43,15 @@ module DCloud end end end + + def to_plain + sprintf("%-10s | %-15s | %-5s | %10s GB", + self.id[0, 10], + self.name[0, 15], + self.state[0,5], + self.limit.to_s[0,10] + ) + end + end end diff --git a/client/lib/dcloud/storage_snapshot.rb b/client/lib/dcloud/storage_snapshot.rb index ae60771..2639cea 100644 --- a/client/lib/dcloud/storage_snapshot.rb +++ b/client/lib/dcloud/storage_snapshot.rb @@ -27,6 +27,15 @@ module DCloud attribute :state attribute :storage_volume
+ def to_plain + sprintf("%-10s | %-15s | %-6s | %15s", + self.id[0,10], + self.storage_volume.name ? self.storage_volume.name[0, 15] : 'unknown', + self.state ? self.state[0,6] : 'unknown', + self.created ? self.created[0,15] : 'unknown' + ) + end + def initialize(client, uri, xml=nil) super( client, uri, xml ) end diff --git a/client/lib/dcloud/storage_volume.rb b/client/lib/dcloud/storage_volume.rb index bdb2e3b..b3722a0 100644 --- a/client/lib/dcloud/storage_volume.rb +++ b/client/lib/dcloud/storage_volume.rb @@ -32,6 +32,16 @@ module DCloud super( client, uri, xml ) end
+ def to_plain + sprintf("%-10s | %15s GB | %-10s | %-10s | %-15s", + self.id[0,10], + self.capacity ? self.capacity.to_s[0,15] : 'unknown', + self.device ? self.device[0,10] : 'unknown', + self.state ? self.state[0,10] : 'unknown', + self.instance ? self.instance.name[0,15] : 'unknown' + ) + end + def load_payload(xml=nil) super(xml) unless xml.nil?
--- client/lib/deltacloud.rb | 40 ++++++++++++++++++++++++++++++++++++---- 1 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb index c38eb97..2f9b59d 100644 --- a/client/lib/deltacloud.rb +++ b/client/lib/deltacloud.rb @@ -118,6 +118,38 @@ class DeltaCloud nil end
+ def fetch_documentation(collection, operation=nil) + response = @http["docs/#{collection}#{operation ? "/#{operation}" : ''}"].get(:accept => "application/xml") + doc = REXML::Document.new( response ) + if operation.nil? + docs = { + :name => doc.get_elements('docs/collection/name').first.text, + :description => doc.get_elements('docs/collection/description').first.text, + :operations => [] + } + doc.get_elements('docs/collection/operations/operation').each do |operation| + p = {} + p[:name] = operation.get_elements('name').first.text + p[:description] = operation.get_elements('description').first.text + p[:parameters] = [] + operation.get_elements('parameter').each do |param| + p[:parameters] << param.get_elements('name').first.text + end + docs[:operations] << p + end + else + docs = { + :name => doc.get_elements('docs/operation/name').first.text, + :description => doc.get_elements('docs/operation/description').first.text, + :parameters => [] + } + doc.get_elements('docs/operation/parameter').each do |param| + docs[:parameters] << param.get_elements('name').first.text + end + end + docs + end + def instance_states states = [] request( entry_points[:instance_states] ) do |response| @@ -194,7 +226,7 @@ class DeltaCloud nil end
- def instances + def instances(id=nil) instances = [] request( entry_points[:instances] ) do |response| doc = REXML::Document.new( response.body ) @@ -249,7 +281,7 @@ class DeltaCloud end end
- def storage_volumes + def storage_volumes(id=nil) storage_volumes = [] request( entry_points[:storage_volumes] ) do |response| doc = REXML::Document.new( response.body ) @@ -278,7 +310,7 @@ class DeltaCloud nil end
- def storage_snapshots() + def storage_snapshots(id=nil) storage_snapshots = [] request( entry_points[:storage_snapshots] ) do |response| doc = REXML::Document.new( response.body ) @@ -345,7 +377,7 @@ class DeltaCloud :authorization => "Basic "+Base64.encode64("#{@name}:#{@password}"), :accept => "application/xml" } - logger << "Request [#{method.to_s.upcase}] #{request_path}]\n" + # logger << "Request [#{method.to_s.upcase}] #{request_path}]\n" if method.eql?(:get) RestClient.send(method, request_path, headers, &block) else
--- client/bin/deltacloudc | 177 +++++++++++++++++++++++------------------------- 1 files changed, 84 insertions(+), 93 deletions(-)
diff --git a/client/bin/deltacloudc b/client/bin/deltacloudc index 53df7bb..6450055 100755 --- a/client/bin/deltacloudc +++ b/client/bin/deltacloudc @@ -17,16 +17,14 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
require 'rubygems' -require 'rest_client' require 'optparse' -require 'nokogiri' +require 'rest_client' require 'uri' +require 'deltacloud'
-options = { - :format => :plain -} +options = {}
-@optparse = OptionParser.new do|opts| +@optparse = OptionParser.new do |opts|
opts.banner = <<BANNER Usage: @@ -41,9 +39,9 @@ BANNER opts.on( nil, '--image-id ID', 'Image ID') { |id| options[:image_id] = id } opts.on( nil, '--arch ARCH', 'Architecture (x86, x86_64)') { |id| options[:architecture] = id } opts.on( nil, '--flavor_id FLAVOR', 'Flavor') { |id| options[:flavor_id] = id } + opts.on( nil, '--name NAME', 'Name (for instance eg.)') { |name| options[:name] = name } opts.on( '-l', '--list', 'List collections/operations') { |id| options[:list] = true } opts.on( '-u', '--url', 'API url ($API_URL variable)') { |url| options[:api_url] = url } - opts.on( nil, '--xml', 'XML output') { |format| options[:format] = :xml } opts.on( '-h', '--help', 'Display this screen' ) { puts opts ; exit } opts.on( '-v', '--version', 'Display API version' ) { options[:version]=true } end @@ -53,105 +51,98 @@ def invalid_usage(error_msg='') exit(1) end
-def convert_to_plain(xml) - doc = Nokogiri::XML(xml) - doc.root.traverse do |elem| - yield "-----------------------" if elem.children.size>1 - next unless elem.children.size.eql?(1) - if not elem.eql?(doc.root) and not elem.name.eql?('text') - yield "#{string_to_width(elem.name, 15)}: #{elem.content.strip}" - end - end - return nil -end - -def string_to_width(string, width, options = {}) - options.merge!( - :pad => ' ', :align => :left - ) - new_string = "" - i = 0 - string.each_byte do |c| - break if i == width - new_string += c.chr - i += 1 - end - # add padding - if new_string.length < width - padding = (options[:pad] * (width - new_string.length)) - new_string = options[:align] == :left ? - new_string + padding : padding + new_string - end - new_string -end - @optparse.parse!
# First try to get API_URL from environment options[:api_url] = ENV['API_URL'] if options[:api_url].nil? -options[:collection] = ARGV[0] -options[:operation] = ARGV[1]
-invalid_usage("API_URL is not set") if options[:api_url].nil? +url = URI.parse(options[:api_url]) +api_url = "http://#%7Burl.host%7D#%7Burl.port ? ":#{url.port}" : ''}#{url.path}"
-options[:list]=true if options[:collection].nil? and options[:operation].nil? +options[:collection] = ARGV[0] +options[:operation] = ARGV[1]
-# Default response to XML -params = { :accept => "application/xml" } +# Connect to Deltacloud API and fetch all entry points +client = DeltaCloud.new(url.user, url.password, api_url) +collections = client.entry_points.keys
-operations = {} -operations[:get] = [ 'index', 'show', 'new'] -operations[:post] = [ 'save', 'create' ] -operations[:put] = [ 'update' ] -operations[:delete] = [ 'delete' ] +# Exclude collection which don't have methods in client library yet +collections.delete(:hardware_profiles) +collections.delete(:instance_states)
-rest = RestClient::Resource.new( options[:api_url] , :accept => 'application/xml' ) +# If list parameter passed print out available collection +# with API documentation +if options[:list] and options[:collection].nil? + collections.each do |c| + doc = client.fetch_documentation(c.to_s) + puts sprintf("%-22s: %s", c.to_s[0, 22], doc[:description]) + end + exit(0) +end
-doc = Nokogiri::XML(rest.get(:accept => "application/xml")) -version, driver = doc.xpath('/api/@version'), doc.xpath('/api/@driver') -collections = doc.xpath('/api/link/@rel').collect { |rel| rel.to_s } +# If collection parameter is present and user requested list +# print all operation defined for collection with API documentation +if options[:list] and options[:collection] + doc = client.fetch_documentation(options[:collection]) + doc[:operations].each do |c| + puts sprintf("%-20s: %s", c[:name][0, 20], c[:description]) + end + exit(0) +end
if options[:version] - puts "API [#{version}] Driver: [#{driver}]" - exit + puts "Deltacloud API(#{client.driver_name}) 0.1" + exit(0) end
-# List available collection for driver - -if options[:list] and not options[:collection] - puts "Available collections for driver #{driver} [#{version}]:\n\n" - collections.collect { |c| puts c } -elsif options[:list] and options[:collection] - # TODO: Place here all available collection operations (through /api/docs) -else - options[:params] = {} - options[:params]['image_id'] = options[:image_id] unless options[:image_id].nil? - options[:params]['architecture'] = options[:architecture] unless options[:architecture].nil? - options[:params]['flavor_id'] = options[:flavor_id] unless options[:flavor_id].nil? - options[:operation] = 'index' if options[:operation].nil? - # First guess HTTP method to use - method = operations.keys.select { |k| operations[k].include?(options[:operation]) }.first - - invalid_usage("Unknown operation: #{options[:operation]} ") if method.nil? - invalid_usage("Unknown collection: #{options[:collection]}") unless collections.include?(options[:collection]) - - # 'show' and 'index' is not needed in URI - options[:operation] = nil if ['show', 'index'].include?(options[:operation]) - - # Resource means Rest URI ['/flavors', '/images/:id'] - resource = [options[:collection], options[:operation], options[:id]].compact.join('/') - - if method.eql?(:post) - puts rest[resource].send(method, params, options[:params]) - else - resource += '?'+URI.escape(options[:params].collect{|k,v| "#{k}=#{v}"}.join('&')) if options[:params] - case options[:format] - when :xml - puts rest[resource].send(method, params) - when :plain - convert_to_plain(rest[resource].send(method, params)) do |line| - puts line - end - end +# List items from collection (typically /flavors) +# 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) + params = {} + params.merge!(:architecture => options[:architecture]) if options[:architecture] + params.merge!(:id => options[:id]) if options[:id] + client.send(options[:collection].to_s, params).each do |model| + puts model.to_plain end + exit(0) end + +if options[:collection] and options[:operation] + + invalid_usage("Unknown collection: #{options[:collection]}") unless collections.include?(options[:collection].to_sym) + + params = {} + params.merge!(:id => options[:id]) if options[:id] + + # If collection is set and requested operation is 'show' just 'singularize' + # collection name and print item with specified id (-i parameter) + if options[:operation].eql?('show') + puts client.send(options[:collection].gsub(/s$/, ''), options[:id] ).to_plain + exit(0) + end + + # If collection is set and requested operation is create new instance, + # --image-id, --flavor-id and --name parameters are used + # Returns created instance in plain form + if options[:collection].eql?('instances') and options[:operation].eql?('create') + params.merge!(:name => options[:name]) if options[:name] + params.merge!(:image_id => options[:image_id]) if options[:image_id] + params.merge!(:flavor_id => options[:flavor_id]) if options[:flavor_id] + instance = client.create_instance(options[:image_id], params) + puts instance.to_plain + exit(0) + end + + # All other operations above collections is done there: + if options[:collection].eql?('instances') + instance = client.instance(options[:id]) + instance.send("#{options[:operation]}!".to_s) + instance = client.instance(options[:id]) + puts instance.to_plain + exit(0) + end +end + +# If all above passed (eg. no parameters) +puts @optparse
Sorry, this one. You need to apply first this patch:
https://fedorahosted.org/pipermail/deltacloud-devel/2010-February/000460.htm...
(...which is my 'first' version based on Nokogiri gem. Version above use 'deltacloud-client' gem)
On 18/02/10 15:57 +0100, mfojtik@redhat.com wrote:
client/bin/deltacloudc | 177 +++++++++++++++++++++++------------------------- 1 files changed, 84 insertions(+), 93 deletions(-)
diff --git a/client/bin/deltacloudc b/client/bin/deltacloudc index 53df7bb..6450055 100755 --- a/client/bin/deltacloudc +++ b/client/bin/deltacloudc @@ -17,16 +17,14 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
require 'rubygems' -require 'rest_client' require 'optparse' -require 'nokogiri' +require 'rest_client' require 'uri' +require 'deltacloud'
-options = {
- :format => :plain
-} +options = {}
-@optparse = OptionParser.new do|opts| +@optparse = OptionParser.new do |opts|
opts.banner = <<BANNER Usage: @@ -41,9 +39,9 @@ BANNER opts.on( nil, '--image-id ID', 'Image ID') { |id| options[:image_id] = id } opts.on( nil, '--arch ARCH', 'Architecture (x86, x86_64)') { |id| options[:architecture] = id } opts.on( nil, '--flavor_id FLAVOR', 'Flavor') { |id| options[:flavor_id] = id }
- opts.on( nil, '--name NAME', 'Name (for instance eg.)') { |name| options[:name] = name } opts.on( '-l', '--list', 'List collections/operations') { |id| options[:list] = true } opts.on( '-u', '--url', 'API url ($API_URL variable)') { |url| options[:api_url] = url }
- opts.on( nil, '--xml', 'XML output') { |format| options[:format] = :xml } opts.on( '-h', '--help', 'Display this screen' ) { puts opts ; exit } opts.on( '-v', '--version', 'Display API version' ) { options[:version]=true }
end @@ -53,105 +51,98 @@ def invalid_usage(error_msg='') exit(1) end
-def convert_to_plain(xml)
- doc = Nokogiri::XML(xml)
- doc.root.traverse do |elem|
- yield "-----------------------" if elem.children.size>1
- next unless elem.children.size.eql?(1)
- if not elem.eql?(doc.root) and not elem.name.eql?('text')
yield "#{string_to_width(elem.name, 15)}: #{elem.content.strip}"
- end
- end
- return nil
-end
-def string_to_width(string, width, options = {})
- options.merge!(
- :pad => ' ', :align => :left
- )
- new_string = ""
- i = 0
- string.each_byte do |c|
- break if i == width
- new_string += c.chr
- i += 1
- end
- # add padding
- if new_string.length < width
- padding = (options[:pad] * (width - new_string.length))
- new_string = options[:align] == :left ?
new_string + padding : padding + new_string
- end
- new_string
-end
@optparse.parse!
# First try to get API_URL from environment options[:api_url] = ENV['API_URL'] if options[:api_url].nil? -options[:collection] = ARGV[0] -options[:operation] = ARGV[1]
-invalid_usage("API_URL is not set") if options[:api_url].nil? +url = URI.parse(options[:api_url]) +api_url = "http://#%7Burl.host%7D#%7Burl.port ? ":#{url.port}" : ''}#{url.path}"
-options[:list]=true if options[:collection].nil? and options[:operation].nil? +options[:collection] = ARGV[0] +options[:operation] = ARGV[1]
-# Default response to XML -params = { :accept => "application/xml" } +# Connect to Deltacloud API and fetch all entry points +client = DeltaCloud.new(url.user, url.password, api_url) +collections = client.entry_points.keys
-operations = {} -operations[:get] = [ 'index', 'show', 'new'] -operations[:post] = [ 'save', 'create' ] -operations[:put] = [ 'update' ] -operations[:delete] = [ 'delete' ] +# Exclude collection which don't have methods in client library yet +collections.delete(:hardware_profiles) +collections.delete(:instance_states)
-rest = RestClient::Resource.new( options[:api_url] , :accept => 'application/xml' ) +# If list parameter passed print out available collection +# with API documentation +if options[:list] and options[:collection].nil?
- collections.each do |c|
- doc = client.fetch_documentation(c.to_s)
- puts sprintf("%-22s: %s", c.to_s[0, 22], doc[:description])
- end
- exit(0)
+end
-doc = Nokogiri::XML(rest.get(:accept => "application/xml")) -version, driver = doc.xpath('/api/@version'), doc.xpath('/api/@driver') -collections = doc.xpath('/api/link/@rel').collect { |rel| rel.to_s } +# If collection parameter is present and user requested list +# print all operation defined for collection with API documentation +if options[:list] and options[:collection]
- doc = client.fetch_documentation(options[:collection])
- doc[:operations].each do |c|
- puts sprintf("%-20s: %s", c[:name][0, 20], c[:description])
- end
- exit(0)
+end
if options[:version]
- puts "API [#{version}] Driver: [#{driver}]"
- exit
- puts "Deltacloud API(#{client.driver_name}) 0.1"
- exit(0)
end
-# List available collection for driver
-if options[:list] and not options[:collection]
- puts "Available collections for driver #{driver} [#{version}]:\n\n"
- collections.collect { |c| puts c }
-elsif options[:list] and options[:collection]
- # TODO: Place here all available collection operations (through /api/docs)
-else
- options[:params] = {}
- options[:params]['image_id'] = options[:image_id] unless options[:image_id].nil?
- options[:params]['architecture'] = options[:architecture] unless options[:architecture].nil?
- options[:params]['flavor_id'] = options[:flavor_id] unless options[:flavor_id].nil?
- options[:operation] = 'index' if options[:operation].nil?
- # First guess HTTP method to use
- method = operations.keys.select { |k| operations[k].include?(options[:operation]) }.first
- invalid_usage("Unknown operation: #{options[:operation]} ") if method.nil?
- invalid_usage("Unknown collection: #{options[:collection]}") unless collections.include?(options[:collection])
- # 'show' and 'index' is not needed in URI
- options[:operation] = nil if ['show', 'index'].include?(options[:operation])
- # Resource means Rest URI ['/flavors', '/images/:id']
- resource = [options[:collection], options[:operation], options[:id]].compact.join('/')
- if method.eql?(:post)
- puts rest[resource].send(method, params, options[:params])
- else
- resource += '?'+URI.escape(options[:params].collect{|k,v| "#{k}=#{v}"}.join('&')) if options[:params]
- case options[:format]
when :xml
puts rest[resource].send(method, params)
when :plain
convert_to_plain(rest[resource].send(method, params)) do |line|
puts line
end
- end
+# List items from collection (typically /flavors) +# 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)
- params = {}
- params.merge!(:architecture => options[:architecture]) if options[:architecture]
- params.merge!(:id => options[:id]) if options[:id]
- client.send(options[:collection].to_s, params).each do |model|
- puts model.to_plain end
- exit(0)
end
+if options[:collection] and options[:operation]
- invalid_usage("Unknown collection: #{options[:collection]}") unless collections.include?(options[:collection].to_sym)
- params = {}
- params.merge!(:id => options[:id]) if options[:id]
- # If collection is set and requested operation is 'show' just 'singularize'
- # collection name and print item with specified id (-i parameter)
- if options[:operation].eql?('show')
- puts client.send(options[:collection].gsub(/s$/, ''), options[:id] ).to_plain
- exit(0)
- end
- # If collection is set and requested operation is create new instance,
- # --image-id, --flavor-id and --name parameters are used
- # Returns created instance in plain form
- if options[:collection].eql?('instances') and options[:operation].eql?('create')
- params.merge!(:name => options[:name]) if options[:name]
- params.merge!(:image_id => options[:image_id]) if options[:image_id]
- params.merge!(:flavor_id => options[:flavor_id]) if options[:flavor_id]
- instance = client.create_instance(options[:image_id], params)
- puts instance.to_plain
- exit(0)
- end
- # All other operations above collections is done there:
- if options[:collection].eql?('instances')
- instance = client.instance(options[:id])
- instance.send("#{options[:operation]}!".to_s)
- instance = client.instance(options[:id])
- puts instance.to_plain
- exit(0)
- end
+end
+# If all above passed (eg. no parameters)
+puts @optparse
1.6.4.4
On Thu, 2010-02-18 at 16:02 +0100, Michal Fojtik wrote:
Sorry, this one. You need to apply first this patch:
https://fedorahosted.org/pipermail/deltacloud-devel/2010-February/000460.htm...
(...which is my 'first' version based on Nokogiri gem. Version above use 'deltacloud-client' gem)
I can't get this patch to apply, neither against the first nor the second version of deltacloudc from the other day. Can you just squash all the changes to bin/deltacloudc into one patch and repost ?
On 18/02/10 15:57 +0100, mfojtik@redhat.com wrote:
client/bin/deltacloudc | 177 +++++++++++++++++++++++------------------------- 1 files changed, 84 insertions(+), 93 deletions(-)
opts.banner = <<BANNER Usage: @@ -41,9 +39,9 @@ BANNER opts.on( nil, '--image-id ID', 'Image ID') { |id| options[:image_id] = id } opts.on( nil, '--arch ARCH', 'Architecture (x86, x86_64)') { |id| options[:architecture] = id } opts.on( nil, '--flavor_id FLAVOR', 'Flavor') { |id| options[:flavor_id] = id }
- opts.on( nil, '--name NAME', 'Name (for instance eg.)') { |name| options[:name] = name } opts.on( '-l', '--list', 'List collections/operations') { |id| options[:list] = true } opts.on( '-u', '--url', 'API url ($API_URL variable)') { |url| options[:api_url] = url }
The second arg needs to be '--url URL'
David
On Thu, 2010-02-18 at 15:57 +0100, mfojtik@redhat.com wrote:
- def instances
- def instances(id=nil) instances = [] request( entry_points[:instances] ) do |response| doc = REXML::Document.new( response.body )
@@ -249,7 +281,7 @@ class DeltaCloud end end
- def storage_volumes
- def storage_volumes(id=nil) storage_volumes = [] request( entry_points[:storage_volumes] ) do |response| doc = REXML::Document.new( response.body )
@@ -278,7 +310,7 @@ class DeltaCloud nil end
- def storage_snapshots()
- def storage_snapshots(id=nil) storage_snapshots = [] request( entry_points[:storage_snapshots] ) do |response| doc = REXML::Document.new( response.body )
Why are you adding these id parameters ? They aren't used in the method bodies at all.
@@ -345,7 +377,7 @@ class DeltaCloud :authorization => "Basic "+Base64.encode64("#{@name}:#{@password}"), :accept => "application/xml" }
- logger << "Request [#{method.to_s.upcase}] #{request_path}]\n"
- # logger << "Request [#{method.to_s.upcase}] #{request_path}]\n" if method.eql?(:get) RestClient.send(method, request_path, headers, &block) else
We should find a way to conditionally log this, maybe controlled by some env variable.
David
On 18/02/10 12:23 -0800, David Lutterkort wrote:
On Thu, 2010-02-18 at 15:57 +0100, mfojtik@redhat.com wrote:
- def instances
- def instances(id=nil) instances = [] request( entry_points[:instances] ) do |response| doc = REXML::Document.new( response.body )
@@ -249,7 +281,7 @@ class DeltaCloud end end
- def storage_volumes
- def storage_volumes(id=nil) storage_volumes = [] request( entry_points[:storage_volumes] ) do |response| doc = REXML::Document.new( response.body )
@@ -278,7 +310,7 @@ class DeltaCloud nil end
- def storage_snapshots()
- def storage_snapshots(id=nil) storage_snapshots = [] request( entry_points[:storage_snapshots] ) do |response| doc = REXML::Document.new( response.body )
Why are you adding these id parameters ? They aren't used in the method bodies at all.
Unfortunately, I calling this methods from client (command line):
client.send(options[:collection].to_s, params).each do |model| ...
Without this 'optional' params, this one line of code will expand to couple lines of code ;) (deltacloud.rb: In 'flavors' there are 'opts={}' parameter, but in 'instances' or 'storage_volumes' there are no parameters at all...)
@@ -345,7 +377,7 @@ class DeltaCloud :authorization => "Basic "+Base64.encode64("#{@name}:#{@password}"), :accept => "application/xml" }
- logger << "Request [#{method.to_s.upcase}] #{request_path}]\n"
- # logger << "Request [#{method.to_s.upcase}] #{request_path}]\n" if method.eql?(:get) RestClient.send(method, request_path, headers, &block) else
We should find a way to conditionally log this, maybe controlled by some env variable.
I tried:
attr_accessor :verbose
but unfortunately this method is 'private'...
On Thu, 2010-02-18 at 21:38 +0100, Michal Fojtik wrote:
On 18/02/10 12:23 -0800, David Lutterkort wrote:
On Thu, 2010-02-18 at 15:57 +0100, mfojtik@redhat.com wrote:
- def storage_snapshots()
- def storage_snapshots(id=nil) storage_snapshots = [] request( entry_points[:storage_snapshots] ) do |response| doc = REXML::Document.new( response.body )
Why are you adding these id parameters ? They aren't used in the method bodies at all.
Unfortunately, I calling this methods from client (command line):
client.send(options[:collection].to_s, params).each do |model| ...
Without this 'optional' params, this one line of code will expand to couple lines of code ;) (deltacloud.rb: In 'flavors' there are 'opts={}' parameter, but in 'instances' or 'storage_volumes' there are no parameters at all...)
Makes sense - you should change it to opts or something like that though; I think it's quite likely that we'll allow options to filter the collection in those methods at some point. Less likely that we'll pass in an id.
David
On Thu, 2010-02-18 at 15:57 +0100, mfojtik@redhat.com wrote:
client/lib/dcloud/flavor.rb | 6 ++++++ client/lib/dcloud/image.rb | 10 ++++++++++ client/lib/dcloud/instance.rb | 11 +++++++++++ client/lib/dcloud/realm.rb | 10 ++++++++++ client/lib/dcloud/storage_snapshot.rb | 9 +++++++++ client/lib/dcloud/storage_volume.rb | 10 ++++++++++ 6 files changed, 56 insertions(+), 0 deletions(-)
Looks good.
David
deltacloud-devel@lists.fedorahosted.org