From: David Lutterkort lutter@redhat.com
--- client/lib/dcloud/base_model.rb | 6 ++-- client/lib/dcloud/image.rb | 2 +- client/lib/dcloud/instance.rb | 2 +- client/lib/dcloud/storage_snapshot.rb | 2 +- client/lib/dcloud/storage_volume.rb | 2 +- client/lib/deltacloud.rb | 20 +++++++++--------- client/specs/flavors_spec.rb | 2 +- client/specs/images_spec.rb | 2 +- client/specs/initialization_spec.rb | 2 +- client/specs/instance_states_spec.rb | 2 +- client/specs/instances_spec.rb | 2 +- client/specs/realms_spec.rb | 2 +- .../app/controllers/application_controller.rb | 2 +- .../libexec/app/controllers/images_controller.rb | 10 ++++---- server/libexec/config/initializers/inflections.rb | 2 +- .../libexec/config/initializers/session_store.rb | 2 +- server/libexec/lib/converters/xml_converter.rb | 2 +- .../lib/deltacloud/drivers/mock/mock_driver.rb | 4 +- .../deltacloud/drivers/opennebula/cloud_client.rb | 22 ++++++++++---------- .../drivers/rackspace/rackspace_client.rb | 12 +++++----- .../lib/deltacloud/drivers/rhevm/rhevm_driver.rb | 2 +- server/libexec/lib/deltacloud/state_machine.rb | 8 +++--- 22 files changed, 56 insertions(+), 56 deletions(-)
diff --git a/client/lib/dcloud/base_model.rb b/client/lib/dcloud/base_model.rb index 8c83fbf..0f210a4 100644 --- a/client/lib/dcloud/base_model.rb +++ b/client/lib/dcloud/base_model.rb @@ -20,7 +20,7 @@ module DCloud class BaseModel
def self.xml_tag_name(name=nil) - unless ( name.nil? ) + unless ( name.nil? ) @xml_tag_name = name end @xml_tag_name || self.class.name.downcase.to_sym @@ -54,7 +54,7 @@ module DCloud @id end
- + protected
attr_reader :client @@ -68,7 +68,7 @@ module DCloud def load_payload(xml=nil) unless ( xml.nil? ) @loaded = true - @id = xml.text( 'id' ) + @id = xml.text( 'id' ) end end
diff --git a/client/lib/dcloud/image.rb b/client/lib/dcloud/image.rb index cba7fc7..220de21 100644 --- a/client/lib/dcloud/image.rb +++ b/client/lib/dcloud/image.rb @@ -37,7 +37,7 @@ module DCloud unless xml.nil? @description = xml.text( 'description' ) @owner_id = xml.text( 'owner_id' ) - @name = xml.text( 'name' ) + @name = xml.text( 'name' ) @architecture = xml.text( 'architecture' ) end end diff --git a/client/lib/dcloud/instance.rb b/client/lib/dcloud/instance.rb index e14dd50..9115e9a 100644 --- a/client/lib/dcloud/instance.rb +++ b/client/lib/dcloud/instance.rb @@ -77,7 +77,7 @@ module DCloud @image = Image.new( @client, image_uri ) flavor_uri = xml.get_elements( 'flavor' )[0].attributes['href'] @flavor = Flavor.new( @client, flavor_uri ) - # Only use realms if they are there + # Only use realms if they are there if (!xml.get_elements( 'realm' ).empty?) realm_uri = xml.get_elements( 'realm' )[0].attributes['href'] @realm = Realm.new( @client, realm_uri ) diff --git a/client/lib/dcloud/storage_snapshot.rb b/client/lib/dcloud/storage_snapshot.rb index 9276fb8..ae60771 100644 --- a/client/lib/dcloud/storage_snapshot.rb +++ b/client/lib/dcloud/storage_snapshot.rb @@ -40,7 +40,7 @@ module DCloud if ( ! storage_volumes.empty? ) storage_volume = storage_volumes.first storage_volume_href = storage_volume.attributes['href'] - if ( storage_volume_href ) + if ( storage_volume_href ) @storage_volume = StorageVolume.new( @client, storage_volume_href ) end end diff --git a/client/lib/dcloud/storage_volume.rb b/client/lib/dcloud/storage_volume.rb index aec2f57..bdb2e3b 100644 --- a/client/lib/dcloud/storage_volume.rb +++ b/client/lib/dcloud/storage_volume.rb @@ -43,7 +43,7 @@ module DCloud if ( ! instances.empty? ) instance = instances.first instance_href = instance.attributes['href'] - if ( instance_href ) + if ( instance_href ) @instance = Instance.new( @client, instance_href ) end end diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb index bae8ff0..5324c79 100644 --- a/client/lib/deltacloud.rb +++ b/client/lib/deltacloud.rb @@ -44,12 +44,12 @@ class DeltaCloud attr_reader :driver_name
def initialize(name, password, api_uri, &block) - @logger = Logger.new( STDERR ) + @logger = Logger.new( STDERR ) @name = name @password = password @api_uri = URI.parse( api_uri ) @entry_points = {} - connect( &block ) + connect( &block ) self end
@@ -71,7 +71,7 @@ class DeltaCloud end end end - flavors + flavors end
def flavor(id) @@ -101,7 +101,7 @@ class DeltaCloud doc.get_elements( 'states/state' ).each do |state_elem| state = DCloud::State.new( state_elem.attributes['name'] ) state_elem.get_elements( 'transition' ).each do |transition_elem| - state.transitions << DCloud::Transition.new( + state.transitions << DCloud::Transition.new( transition_elem.attributes['to'], transition_elem.attributes['action'] ) @@ -245,7 +245,7 @@ class DeltaCloud uri = instance.attributes['href'] return DCloud::Instance.new( self, uri, instance ) end - end + end end
def storage_volumes() @@ -276,7 +276,7 @@ class DeltaCloud end
def fetch_storage_volume(uri) - xml = fetch_resource( :storage_volume, uri ) + xml = fetch_resource( :storage_volume, uri ) return DCloud::StorageVolume.new( self, uri, xml ) if xml nil end @@ -309,7 +309,7 @@ class DeltaCloud end
def fetch_storage_snapshot(uri) - xml = fetch_resource( :storage_snapshot, uri ) + xml = fetch_resource( :storage_snapshot, uri ) return DCloud::StorageSnapshot.new( self, uri, xml ) if xml nil end @@ -324,7 +324,7 @@ class DeltaCloud if ( response.is_a?( Net::HTTPSuccess ) ) doc = REXML::Document.new( response.body ) if ( doc.root && ( doc.root.name == type.to_s.gsub( /_/, '-' ) ) ) - return doc.root + return doc.root end end end @@ -374,7 +374,7 @@ class DeltaCloud end
def request(path='', method=:get, query_args={}, form_data={}, &block) - if ( path =~ /^http/ ) + if ( path =~ /^http/ ) request_path = path else request_path = "#{api_path}#{path}" @@ -383,7 +383,7 @@ class DeltaCloud if ( query_string != '' ) request_path += "?#{query_string}" end - + logger << "Request [#{method.to_s.upcase} #{request_path}]\n" request = eval( "Net::HTTP::#{method.to_s.capitalize}" ).new( request_path ) request.basic_auth( @name, @password ) diff --git a/client/specs/flavors_spec.rb b/client/specs/flavors_spec.rb index 740d7ac..91a063e 100644 --- a/client/specs/flavors_spec.rb +++ b/client/specs/flavors_spec.rb @@ -37,7 +37,7 @@ describe "flavors" do flavor.memory.should be_a(Float) end end - end + end
it "should allow filtering of flavors by architecture" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| diff --git a/client/specs/images_spec.rb b/client/specs/images_spec.rb index 5f508db..704c2ae 100644 --- a/client/specs/images_spec.rb +++ b/client/specs/images_spec.rb @@ -38,7 +38,7 @@ describe "images" do image.owner_id.should be_a(String) end end - end + end
it "should allow retrieval of my own images" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| diff --git a/client/specs/initialization_spec.rb b/client/specs/initialization_spec.rb index 47449dd..386eb9e 100644 --- a/client/specs/initialization_spec.rb +++ b/client/specs/initialization_spec.rb @@ -33,7 +33,7 @@ describe "initializing the client" do client.entry_points[:instances].should eql( "#{API_URL}/instances" ) client.entry_points[:storage_volumes].should eql( "#{API_URL}/storage/volumes" ) client.entry_points[:storage_snapshots].should eql( "#{API_URL}/storage/snapshots" ) - end + end end
it "should provide the current driver name via client" do diff --git a/client/specs/instance_states_spec.rb b/client/specs/instance_states_spec.rb index a80d546..667baf6 100644 --- a/client/specs/instance_states_spec.rb +++ b/client/specs/instance_states_spec.rb @@ -50,7 +50,7 @@ describe "instance-states" do includes_transition( instance_states[2].transitions, :reboot, :running ).should be_true includes_transition( instance_states[2].transitions, :stop, :stopped ).should be_true end - end + end
it "should allow retrieval of a single instance-state blob" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| diff --git a/client/specs/instances_spec.rb b/client/specs/instances_spec.rb index a7d9fdb..b088f74 100644 --- a/client/specs/instances_spec.rb +++ b/client/specs/instances_spec.rb @@ -45,7 +45,7 @@ describe "instances" do instance.private_addresses.should be_a( Array ) end end - end + end
it "should allow navigation from instance to image" do DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client| diff --git a/client/specs/realms_spec.rb b/client/specs/realms_spec.rb index 8b08649..6f5199f 100644 --- a/client/specs/realms_spec.rb +++ b/client/specs/realms_spec.rb @@ -34,7 +34,7 @@ describe "realms" do realm.name.should be_a(String) end end - end + end
it "should allow fetching a realm by id" do diff --git a/server/libexec/app/controllers/application_controller.rb b/server/libexec/app/controllers/application_controller.rb index 76641b6..618a833 100644 --- a/server/libexec/app/controllers/application_controller.rb +++ b/server/libexec/app/controllers/application_controller.rb @@ -26,7 +26,7 @@ class ApplicationController < ActionController::Base # filter_parameter_logging :password
- protected + protected
def credentials creds = {} diff --git a/server/libexec/app/controllers/images_controller.rb b/server/libexec/app/controllers/images_controller.rb index 382b138..92fe73f 100644 --- a/server/libexec/app/controllers/images_controller.rb +++ b/server/libexec/app/controllers/images_controller.rb @@ -29,10 +29,10 @@ class ImagesController < ApplicationController @images = driver.images( credentials, @filter )
respond_to do |format| - format.html + format.html format.json - format.xml { - render :xml=>convert_to_xml( :image, @images ) + format.xml { + render :xml=>convert_to_xml( :image, @images ) } end end @@ -43,8 +43,8 @@ class ImagesController < ApplicationController respond_to do |format| format.html format.json - format.xml { - render :xml=>convert_to_xml( :image, @image ) + format.xml { + render :xml=>convert_to_xml( :image, @image ) } end end diff --git a/server/libexec/config/initializers/inflections.rb b/server/libexec/config/initializers/inflections.rb index d531b8b..9e8b013 100644 --- a/server/libexec/config/initializers/inflections.rb +++ b/server/libexec/config/initializers/inflections.rb @@ -1,6 +1,6 @@ # Be sure to restart your server when you modify this file.
-# Add new inflection rules using the following format +# Add new inflection rules using the following format # (all these examples are active by default): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' diff --git a/server/libexec/config/initializers/session_store.rb b/server/libexec/config/initializers/session_store.rb index bdc56be..9450644 100644 --- a/server/libexec/config/initializers/session_store.rb +++ b/server/libexec/config/initializers/session_store.rb @@ -2,7 +2,7 @@
# Your secret key for verifying cookie session data integrity. # If you change this key, all old sessions will become invalid! -# Make sure the secret is at least 30 characters and all random, +# Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. ActionController::Base.session = { :key => '_deltacloud-framework_session', diff --git a/server/libexec/lib/converters/xml_converter.rb b/server/libexec/lib/converters/xml_converter.rb index a353b75..0b11fd7 100644 --- a/server/libexec/lib/converters/xml_converter.rb +++ b/server/libexec/lib/converters/xml_converter.rb @@ -82,7 +82,7 @@ module Converters builder.owner_id( obj.owner_id ) builder.image( :href=>@link_builder.send( :image_url, obj.image_id ) ) builder.flavor( :href=>@link_builder.send( :flavor_url, obj.flavor_id ) ) - builder.realm( :href=>@link_builder.send( :realm_url, obj.realm_id ) ) if obj.realm_id + builder.realm( :href=>@link_builder.send( :realm_url, obj.realm_id ) ) if obj.realm_id builder.state( obj.state ) builder.actions { if ( obj.actions ) diff --git a/server/libexec/lib/deltacloud/drivers/mock/mock_driver.rb b/server/libexec/lib/deltacloud/drivers/mock/mock_driver.rb index 61f180a..73cdcc4 100644 --- a/server/libexec/lib/deltacloud/drivers/mock/mock_driver.rb +++ b/server/libexec/lib/deltacloud/drivers/mock/mock_driver.rb @@ -192,7 +192,7 @@ class MockDriver < Deltacloud::BaseDriver instance_yml = YAML.load( File.read( instance_file ) ) instance_yml[:state] = 'RUNNING' File.open( instance_file, 'w' ) do |f| - f << YAML.dump( instance_yml ) + f << YAML.dump( instance_yml ) end Instance.new( instance_yml ) end @@ -202,7 +202,7 @@ class MockDriver < Deltacloud::BaseDriver instance_yml = YAML.load( File.read( instance_file ) ) instance_yml[:state] = 'RUNNING' File.open( instance_file, 'w' ) do |f| - f << YAML.dump( instance_yml ) + f << YAML.dump( instance_yml ) end Instance.new( instance_yml ) end diff --git a/server/libexec/lib/deltacloud/drivers/opennebula/cloud_client.rb b/server/libexec/lib/deltacloud/drivers/opennebula/cloud_client.rb index 10b34d5..19f989d 100644 --- a/server/libexec/lib/deltacloud/drivers/opennebula/cloud_client.rb +++ b/server/libexec/lib/deltacloud/drivers/opennebula/cloud_client.rb @@ -35,7 +35,7 @@ rescue LoadError end
############################################################################### -# The CloudClient module contains general functionality to implement a +# The CloudClient module contains general functionality to implement a # Cloud Client ############################################################################### module CloudClient @@ -43,7 +43,7 @@ module CloudClient # Default location for the authentication file # ######################################################################### DEFAULT_AUTH_FILE = ENV["HOME"]+"/.one/one_auth" - + # ######################################################################### # Gets authorization credentials from ONE_AUTH or default # auth file. @@ -51,7 +51,7 @@ module CloudClient # Raises an error if authorization is not found # ######################################################################### def self.get_one_auth - if ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and + if ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and File.file?(ENV["ONE_AUTH"]) one_auth=File.read(ENV["ONE_AUTH"]).strip.split(':') elsif File.file?(DEFAULT_AUTH_FILE) @@ -59,12 +59,12 @@ module CloudClient else raise "No authorization data present" end - + raise "Authorization data malformed" if one_auth.length < 2 - + one_auth end - + # ######################################################################### # Starts an http connection and calls the block provided. SSL flag # is set if needed. @@ -75,7 +75,7 @@ module CloudClient http.use_ssl = true http.verify_mode=OpenSSL::SSL::VERIFY_NONE end - + begin http.start do |connection| block.call(connection) @@ -83,7 +83,7 @@ module CloudClient rescue Errno::ECONNREFUSED => e str = "Error connecting to server (#{e.to_s})." str << "Server: #{url.host}:#{url.port}" - + return CloudClient::Error.new(str) end end @@ -94,7 +94,7 @@ module CloudClient # ######################################################################### class Error attr_reader :message - + # +message+ a description of the error def initialize(message=nil) @message=message @@ -105,7 +105,7 @@ module CloudClient end end
- # ######################################################################### + # ######################################################################### # Returns true if the object returned by a method of the OpenNebula # library is an Error # ######################################################################### @@ -113,7 +113,7 @@ module CloudClient value.class==CloudClient::Error end end - + # Command line help functions module CloudCLI # Returns the command name diff --git a/server/libexec/lib/deltacloud/drivers/rackspace/rackspace_client.rb b/server/libexec/lib/deltacloud/drivers/rackspace/rackspace_client.rb index 09b71c6..d01d8d3 100644 --- a/server/libexec/lib/deltacloud/drivers/rackspace/rackspace_client.rb +++ b/server/libexec/lib/deltacloud/drivers/rackspace/rackspace_client.rb @@ -31,7 +31,7 @@ module Deltacloud class RackspaceClient
@@AUTH_API = URI.parse('https://auth.api.rackspacecloud.com/v1.0') - + def initialize(username, auth_key) http = Net::HTTP.new(@@AUTH_API.host,@@AUTH_API.port) http.use_ssl = true @@ -42,7 +42,7 @@ class RackspaceClient @service.use_ssl = true end
- def get(path) + def get(path) @service.get(@service_uri.path + path, {"Accept" => "application/json", "X-Auth-Token" => @auth_token}).body end
@@ -50,16 +50,16 @@ class RackspaceClient JSON.parse(get('/flavors/detail'))['flavors'] end
- def list_images + def list_images JSON.parse(get('/images/detail'))['images'] end
- def list_servers + def list_servers JSON.parse(get('/servers/detail'))['servers'] end
- def load_server_details( server_id ) + def load_server_details( server_id ) JSON.parse(get("/servers/#{server_id}"))['server'] end
@@ -79,7 +79,7 @@ class RackspaceClient end
- def headers + def headers {"Accept" => "application/json", "X-Auth-Token" => @auth_token, "Content-Type" => "application/json"} end
diff --git a/server/libexec/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/libexec/lib/deltacloud/drivers/rhevm/rhevm_driver.rb index eaf008a..d026852 100644 --- a/server/libexec/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +++ b/server/libexec/lib/deltacloud/drivers/rhevm/rhevm_driver.rb @@ -162,7 +162,7 @@ class RHEVMDriver < Deltacloud::BaseDriver # # Instances # - + define_instance_states do start.to(:stopped) .on( :create )
diff --git a/server/libexec/lib/deltacloud/state_machine.rb b/server/libexec/lib/deltacloud/state_machine.rb index f624f09..9c4f7ba 100644 --- a/server/libexec/lib/deltacloud/state_machine.rb +++ b/server/libexec/lib/deltacloud/state_machine.rb @@ -27,7 +27,7 @@ module Deltacloud
def method_missing(sym,*args) return state( sym ) if ( args.empty? ) - super( sym, *args ) + super( sym, *args ) end
class State @@ -40,13 +40,13 @@ module Deltacloud @name = name @transitions = [] end - + def to_s self.name.to_s end
def to(destination_name) - destination = @machine.state(destination_name) + destination = @machine.state(destination_name) transition = Transition.new( @machine, destination ) @transitions << transition transition @@ -77,7 +77,7 @@ module Deltacloud def on(action) @action = action end - + end
end
From: David Lutterkort lutter@redhat.com
Before, the code would only run on Sinatra 0.10 --- server/libexec/lib/sinatra/respond_to.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/server/libexec/lib/sinatra/respond_to.rb b/server/libexec/lib/sinatra/respond_to.rb index fa975cd..8e54bda 100644 --- a/server/libexec/lib/sinatra/respond_to.rb +++ b/server/libexec/lib/sinatra/respond_to.rb @@ -188,7 +188,7 @@ module Sinatra end
def self.mime_type(sym) - ::Sinatra::Base.respond_to?(:mime_type) && ::Sinatra::Base.mime_type(sym) || ::Sinatra::Base.mime_type(sym) + ::Sinatra::Base.respond_to?(:mime_type) && ::Sinatra::Base.mime_type(sym) || ::Sinatra::Base.media_type(sym) end
def format(val=nil)
On Wed, 2010-02-17 at 09:00 -0800, lutter@redhat.com wrote:
From: David Lutterkort lutter@redhat.com
Before, the code would only run on Sinatra 0.10
This is the one actual patch I meant to send. Sorry about the confusion.
David
On 17/02/10 09:00 -0800, lutter@redhat.com wrote:
From: David Lutterkort lutter@redhat.com
Before, the code would only run on Sinatra 0.10
server/libexec/lib/sinatra/respond_to.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/server/libexec/lib/sinatra/respond_to.rb b/server/libexec/lib/sinatra/respond_to.rb index fa975cd..8e54bda 100644 --- a/server/libexec/lib/sinatra/respond_to.rb +++ b/server/libexec/lib/sinatra/respond_to.rb @@ -188,7 +188,7 @@ module Sinatra end
def self.mime_type(sym)
::Sinatra::Base.respond_to?(:mime_type) && ::Sinatra::Base.mime_type(sym) || ::Sinatra::Base.mime_type(sym)
::Sinatra::Base.respond_to?(:mime_type) && ::Sinatra::Base.mime_type(sym) || ::Sinatra::Base.media_type(sym) end def format(val=nil)
-- 1.6.6
deltacloud-devel mailing list deltacloud-devel@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/deltacloud-devel
On 17/02/10 18:09 +0100, Michal Fojtik wrote:
Sorry, this mean ACK ;-)
On 17/02/10 09:00 -0800, lutter@redhat.com wrote:
From: David Lutterkort lutter@redhat.com
Before, the code would only run on Sinatra 0.10
server/libexec/lib/sinatra/respond_to.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/server/libexec/lib/sinatra/respond_to.rb b/server/libexec/lib/sinatra/respond_to.rb index fa975cd..8e54bda 100644 --- a/server/libexec/lib/sinatra/respond_to.rb +++ b/server/libexec/lib/sinatra/respond_to.rb @@ -188,7 +188,7 @@ module Sinatra end
def self.mime_type(sym)
::Sinatra::Base.respond_to?(:mime_type) && ::Sinatra::Base.mime_type(sym) || ::Sinatra::Base.mime_type(sym)
::Sinatra::Base.respond_to?(:mime_type) && ::Sinatra::Base.mime_type(sym) || ::Sinatra::Base.media_type(sym) end def format(val=nil)
-- 1.6.6
deltacloud-devel mailing list deltacloud-devel@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/deltacloud-devel
--
- Michal
deltacloud-devel mailing list deltacloud-devel@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/deltacloud-devel
ACK, Scott already verified this fixes 0.9.x, I just tested against 0.10, and it continues to work with this patch applied.
On Wed, Feb 17, 2010 at 12:00 PM, lutter@redhat.com wrote:
From: David Lutterkort lutter@redhat.com
Before, the code would only run on Sinatra 0.10
server/libexec/lib/sinatra/respond_to.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/server/libexec/lib/sinatra/respond_to.rb b/server/libexec/lib/sinatra/respond_to.rb index fa975cd..8e54bda 100644 --- a/server/libexec/lib/sinatra/respond_to.rb +++ b/server/libexec/lib/sinatra/respond_to.rb @@ -188,7 +188,7 @@ module Sinatra end
def self.mime_type(sym)
- ::Sinatra::Base.respond_to?(:mime_type) && ::Sinatra::Base.mime_type(sym) || ::Sinatra::Base.mime_type(sym)
- ::Sinatra::Base.respond_to?(:mime_type) && ::Sinatra::Base.mime_type(sym) || ::Sinatra::Base.media_type(sym)
end
def format(val=nil)
1.6.6
deltacloud-devel mailing list deltacloud-devel@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/deltacloud-devel
From: Michal Fojtik mfojtik@redhat.com
You now need the rest-client gem
See http://rdoc.info/projects/archiloque/rest-client --- client/lib/deltacloud.rb | 307 +++++++++++++++++++------------------------ client/specs/spec_helper.rb | 1 + 2 files changed, 134 insertions(+), 174 deletions(-)
diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb index 5324c79..c38eb97 100644 --- a/client/lib/deltacloud.rb +++ b/client/lib/deltacloud.rb @@ -15,60 +15,78 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-require 'uri' -require 'net/http' -require 'logger' +require 'rest_client' require 'rexml/document' - +require 'logger' require 'dcloud/flavor' require 'dcloud/realm' require 'dcloud/image' require 'dcloud/instance' require 'dcloud/storage_volume' require 'dcloud/storage_snapshot' - require 'dcloud/state' require 'dcloud/transition' +require 'base64' + +module RestClient + class Response + def body + self.to_s + end + end +end
class DeltaCloud
+ attr_accessor :logger + attr_reader :api_uri + attr_reader :entry_points + attr_reader :driver_name + def self.driver_name(url) DeltaCloud.new( nil, nil, url) do |client| return client.driver_name end end
- attr_accessor :logger - attr_reader :api_uri - attr_reader :entry_points - attr_reader :driver_name - def initialize(name, password, api_uri, &block) @logger = Logger.new( STDERR ) @name = name @password = password @api_uri = URI.parse( api_uri ) @entry_points = {} + discover_entry_points connect( &block ) self end
+ def connect(&block) - @http = Net::HTTP.new( api_host, api_port ) + @http = RestClient::Resource.new( api_uri.to_s , :accept => 'application/xml' ) discover_entry_points block.call( self ) if block self end
+ def api_host + @api_uri.host + end + + def api_port + @api_uri.port + end + + def api_path + @api_uri.path + end + def flavors(opts={}) flavors = [] - request( entry_points[:flavors], :get, opts ) do |response| - if ( response.is_a?( Net::HTTPSuccess ) ) - doc = REXML::Document.new( response.body ) - doc.get_elements( 'flavors/flavor' ).each do |flavor| - uri = flavor.attributes['href'] - flavors << DCloud::Flavor.new( self, uri, flavor ) - end + request(entry_points[:flavors], :get, opts) do |response| + doc = REXML::Document.new( response ) + doc.get_elements( 'flavors/flavor' ).each do |flavor| + uri = flavor.attributes['href'] + flavors << DCloud::Flavor.new( self, uri, flavor ) end end flavors @@ -76,15 +94,12 @@ class DeltaCloud
def flavor(id) request( entry_points[:flavors], :get, {:id=>id } ) do |response| - if ( response.is_a?( Net::HTTPSuccess ) ) - doc = REXML::Document.new( response.body ) - doc.get_elements( 'flavors/flavor' ).each do |flavor| - uri = flavor.attributes['href'] - return DCloud::Flavor.new( self, uri, flavor ) - end + doc = REXML::Document.new( response.body ) + doc.get_elements( '/flavor' ).each do |flavor| + uri = flavor.attributes['href'] + return DCloud::Flavor.new( self, uri, flavor ) end end - nil end
def fetch_flavor(uri) @@ -93,21 +108,29 @@ class DeltaCloud nil end
- def instance_states() + def fetch_resource(type, uri) + request( uri ) do |response| + doc = REXML::Document.new( response.body ) + if ( doc.root && ( doc.root.name == type.to_s.gsub( /_/, '-' ) ) ) + return doc.root + end + end + nil + end + + def instance_states states = [] request( entry_points[:instance_states] ) do |response| - if ( response.is_a?( Net::HTTPSuccess ) ) - doc = REXML::Document.new( response.body ) - doc.get_elements( 'states/state' ).each do |state_elem| - state = DCloud::State.new( state_elem.attributes['name'] ) - state_elem.get_elements( 'transition' ).each do |transition_elem| - state.transitions << DCloud::Transition.new( - transition_elem.attributes['to'], - transition_elem.attributes['action'] - ) - end - states << state + doc = REXML::Document.new( response.body ) + doc.get_elements( 'states/state' ).each do |state_elem| + state = DCloud::State.new( state_elem.attributes['name'] ) + state_elem.get_elements( 'transition' ).each do |transition_elem| + state.transitions << DCloud::Transition.new( + transition_elem.attributes['to'], + transition_elem.attributes['action'] + ) end + states << state end end states @@ -121,12 +144,10 @@ class DeltaCloud def realms(opts={}) realms = [] request( entry_points[:realms], :get, opts ) do |response| - if ( response.is_a?( Net::HTTPSuccess ) ) - doc = REXML::Document.new( response.body ) - doc.get_elements( 'realms/realm' ).each do |realm| - uri = realm.attributes['href'] - realms << DCloud::Realm.new( self, uri, realm ) - end + doc = REXML::Document.new( response.body ) + doc.get_elements( 'realms/realm' ).each do |realm| + uri = realm.attributes['href'] + realms << DCloud::Realm.new( self, uri, realm ) end end realms @@ -134,12 +155,10 @@ class DeltaCloud
def realm(id) request( entry_points[:realms], :get, {:id=>id } ) do |response| - if ( response.is_a?( Net::HTTPSuccess ) ) - doc = REXML::Document.new( response.body ) - doc.get_elements( 'realms/realm' ).each do |realm| - uri = realm.attributes['href'] - return DCloud::Realm.new( self, uri, realm ) - end + doc = REXML::Document.new( response.body ) + doc.get_elements( 'realm' ).each do |realm| + uri = realm.attributes['href'] + return DCloud::Realm.new( self, uri, realm ) end end nil @@ -155,12 +174,10 @@ class DeltaCloud images = [] request_path = entry_points[:images] request( request_path, :get, opts ) do |response| - if ( response.is_a?( Net::HTTPSuccess ) ) - doc = REXML::Document.new( response.body ) - doc.get_elements( 'images/image' ).each do |image| - uri = image.attributes['href'] - images << DCloud::Image.new( self, uri, image ) - end + doc = REXML::Document.new( response.body ) + doc.get_elements( 'images/image' ).each do |image| + uri = image.attributes['href'] + images << DCloud::Image.new( self, uri, image ) end end images @@ -168,32 +185,22 @@ class DeltaCloud
def image(id) request( entry_points[:images], :get, {:id=>id } ) do |response| - if ( response.is_a?( Net::HTTPSuccess ) ) - doc = REXML::Document.new( response.body ) - doc.get_elements( 'images/image' ).each do |instance| - uri = instance.attributes['href'] - return DCloud::Image.new( self, uri, instance ) - end + doc = REXML::Document.new( response.body ) + doc.get_elements( 'image' ).each do |instance| + uri = instance.attributes['href'] + return DCloud::Image.new( self, uri, instance ) end end nil end
- def fetch_image(uri) - xml = fetch_resource( :image, uri ) - return DCloud::Image.new( self, uri, xml ) if xml - nil - end - - def instances() + def instances instances = [] request( entry_points[:instances] ) do |response| - if ( response.is_a?( Net::HTTPSuccess ) ) - doc = REXML::Document.new( response.body ) - doc.get_elements( 'instances/instance' ).each do |instance| - uri = instance.attributes['href'] - instances << DCloud::Instance.new( self, uri, instance ) - end + doc = REXML::Document.new( response.body ) + doc.get_elements( 'instances/instance' ).each do |instance| + uri = instance.attributes['href'] + instances << DCloud::Instance.new( self, uri, instance ) end end instances @@ -201,12 +208,10 @@ class DeltaCloud
def instance(id) request( entry_points[:instances], :get, {:id=>id } ) do |response| - if ( response.is_a?( Net::HTTPSuccess ) ) - doc = REXML::Document.new( response.body ) - doc.get_elements( 'instances/instance' ).each do |instance| - uri = instance.attributes['href'] - return DCloud::Instance.new( self, uri, instance ) - end + doc = REXML::Document.new( response.body ) + doc.get_elements( 'instance' ).each do |instance| + uri = instance.attributes['href'] + return DCloud::Instance.new( self, uri, instance ) end end nil @@ -214,9 +219,7 @@ class DeltaCloud
def post_instance(uri) request( uri, :post ) do |response| - if ( response.is_a?( Net::HTTPSuccess ) ) - return true - end + return true end return false end @@ -239,24 +242,20 @@ class DeltaCloud
params[:image_id] = image_id request( entry_points[:instances], :post, {}, params ) do |response| - if ( response.is_a?( Net::HTTPSuccess ) ) - doc = REXML::Document.new( response.body ) - instance = doc.root - uri = instance.attributes['href'] - return DCloud::Instance.new( self, uri, instance ) - end + doc = REXML::Document.new( response.body ) + instance = doc.root + uri = instance.attributes['href'] + return DCloud::Instance.new( self, uri, instance ) end end
- def storage_volumes() + def storage_volumes storage_volumes = [] request( entry_points[:storage_volumes] ) do |response| - if ( response.is_a?( Net::HTTPSuccess ) ) - doc = REXML::Document.new( response.body ) - doc.get_elements( 'storage-volumes/storage-volume' ).each do |instance| - uri = instance.attributes['href'] - storage_volumes << DCloud::StorageVolume.new( self, uri, instance ) - end + doc = REXML::Document.new( response.body ) + doc.get_elements( 'storage-volumes/storage-volume' ).each do |instance| + uri = instance.attributes['href'] + storage_volumes << DCloud::StorageVolume.new( self, uri, instance ) end end storage_volumes @@ -264,12 +263,10 @@ class DeltaCloud
def storage_volume(id) request( entry_points[:storage_volumes], :get, {:id=>id } ) do |response| - if ( response.is_a?( Net::HTTPSuccess ) ) - doc = REXML::Document.new( response.body ) - doc.get_elements( 'storage-volumes/storage-volume' ).each do |storage_volume| - uri = storage_volume.attributes['href'] - return DCloud::StorageVolume.new( self, uri, storage_volume ) - end + doc = REXML::Document.new( response.body ) + doc.get_elements( 'storage-volume' ).each do |storage_volume| + uri = storage_volume.attributes['href'] + return DCloud::StorageVolume.new( self, uri, storage_volume ) end end nil @@ -284,12 +281,10 @@ class DeltaCloud def storage_snapshots() storage_snapshots = [] request( entry_points[:storage_snapshots] ) do |response| - if ( response.is_a?( Net::HTTPSuccess ) ) - doc = REXML::Document.new( response.body ) - doc.get_elements( 'storage-snapshots/storage-snapshot' ).each do |instance| - uri = instance.attributes['href'] - storage_snapshots << DCloud::StorageSnapshot.new( self, uri, instance ) - end + doc = REXML::Document.new( response.body ) + doc.get_elements( 'storage-snapshots/storage-snapshot' ).each do |instance| + uri = instance.attributes['href'] + storage_snapshots << DCloud::StorageSnapshot.new( self, uri, instance ) end end storage_snapshots @@ -297,12 +292,10 @@ class DeltaCloud
def storage_snapshot(id) request( entry_points[:storage_snapshots], :get, {:id=>id } ) do |response| - if ( response.is_a?( Net::HTTPSuccess ) ) - doc = REXML::Document.new( response.body ) - doc.get_elements( 'storage-snapshots/storage-snapshot' ).each do |storage_snapshot| - uri = storage_snapshot.attributes['href'] - return DCloud::StorageSnapshot.new( self, uri, storage_snapshot ) - end + doc = REXML::Document.new( response.body ) + doc.get_elements( 'storage-snapshot' ).each do |storage_snapshot| + uri = storage_snapshot.attributes['href'] + return DCloud::StorageSnapshot.new( self, uri, storage_snapshot ) end end nil @@ -314,61 +307,24 @@ class DeltaCloud nil end
- ## - ## - ## - ## - - def fetch_resource(type, uri) - request( uri ) do |response| - if ( response.is_a?( Net::HTTPSuccess ) ) - doc = REXML::Document.new( response.body ) - if ( doc.root && ( doc.root.name == type.to_s.gsub( /_/, '-' ) ) ) - return doc.root - end - end - end + def fetch_image(uri) + xml = fetch_resource( :image, uri ) + return DCloud::Image.new( self, uri, xml ) if xml nil end
- def api_host - @api_uri.host - end - - def api_port - @api_uri.port - end - - def api_path - @api_uri.path - end - private
attr_reader :http
- def build_hash(elem) - hash = {} - elem.elements.each do |element| - key = element.name.gsub( /-/, '_' ).to_sym - value = element.text || element.attributes['href'] - hash[key] = value - end - hash - end - - def discover_entry_points() - @entry_points = {} - logger << "Discoverying entry points at #{@api_uri}\n" - request do |response| - if ( response.is_a?( Net::HTTPSuccess ) ) - doc = REXML::Document.new( response.body ) - @driver_name = doc.root.attributes['driver'] - doc.get_elements( 'api/link' ).each do |link| - rel = link.attributes['rel'] - uri = link.attributes['href'] - @entry_points[rel.to_sym] = uri - end + def discover_entry_points + request(api_uri.to_s) do |response| + doc = REXML::Document.new( response.body ) + @driver_name = doc.root.attributes['driver'] + doc.get_elements( 'api/link' ).each do |link| + rel = link.attributes['rel'] + uri = link.attributes['href'] + @entry_points[rel.to_sym] = uri end end end @@ -377,21 +333,24 @@ class DeltaCloud if ( path =~ /^http/ ) request_path = path else - request_path = "#{api_path}#{path}" + request_path = "#{api_uri.to_s}#{path}" end - query_string = query_args.keys.collect{|key| "#{key}=#{query_args[key]}"}.join("&") - if ( query_string != '' ) - request_path += "?#{query_string}" + if query_args[:id] + request_path += "/#{query_args[:id]}" + query_args.delete(:id) end - - logger << "Request [#{method.to_s.upcase} #{request_path}]\n" - request = eval( "Net::HTTP::#{method.to_s.capitalize}" ).new( request_path ) - request.basic_auth( @name, @password ) - if ( method == :post ) - request.set_form_data( form_data ) + query_string = URI.escape(query_args.collect{|k,v| "#{k}=#{v}"}.join('&')) + request_path += "?#{query_string}" unless query_string=='' + headers = { + :authorization => "Basic "+Base64.encode64("#{@name}:#{@password}"), + :accept => "application/xml" + } + logger << "Request [#{method.to_s.upcase}] #{request_path}]\n" + if method.eql?(:get) + RestClient.send(method, request_path, headers, &block) + else + RestClient.send(method, request_path, form_data, headers, &block) end - request['Accept'] = 'text/xml' - http.request( request, &block ) end
end diff --git a/client/specs/spec_helper.rb b/client/specs/spec_helper.rb index 071b0bc..b9f9992 100644 --- a/client/specs/spec_helper.rb +++ b/client/specs/spec_helper.rb @@ -15,6 +15,7 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+require 'rubygems' require 'yaml' require 'fileutils'
On Wed, 2010-02-17 at 09:00 -0800, lutter@redhat.com wrote:
From: Michal Fojtik mfojtik@redhat.com
You now need the rest-client gem
Ignore this - a git send-email gone very wrong.
David
From: David Lutterkort lutter@redhat.com
We changed storage/snapshots and storage/volumes to storage_snapshots and storage_volumes respectively. --- client/specs/initialization_spec.rb | 4 ++-- client/specs/storage_snapshot_spec.rb | 4 ++-- client/specs/storage_volume_spec.rb | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/client/specs/initialization_spec.rb b/client/specs/initialization_spec.rb index 386eb9e..6fcf1a4 100644 --- a/client/specs/initialization_spec.rb +++ b/client/specs/initialization_spec.rb @@ -31,8 +31,8 @@ describe "initializing the client" do client.entry_points[:flavors].should eql( "#{API_URL}/flavors" ) client.entry_points[:images].should eql( "#{API_URL}/images" ) client.entry_points[:instances].should eql( "#{API_URL}/instances" ) - client.entry_points[:storage_volumes].should eql( "#{API_URL}/storage/volumes" ) - client.entry_points[:storage_snapshots].should eql( "#{API_URL}/storage/snapshots" ) + client.entry_points[:storage_volumes].should eql( "#{API_URL}/storage_volumes" ) + client.entry_points[:storage_snapshots].should eql( "#{API_URL}/storage_snapshots" ) end end
diff --git a/client/specs/storage_snapshot_spec.rb b/client/specs/storage_snapshot_spec.rb index 7a9eb40..cba5351 100644 --- a/client/specs/storage_snapshot_spec.rb +++ b/client/specs/storage_snapshot_spec.rb @@ -49,7 +49,7 @@ describe "storage snapshot" do it "should allow fetching of storage volume by URI" do client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) client.connect do |client| - storage_snapshot = client.fetch_storage_snapshot( API_URL + '/storage/snapshots/snap2' ) + storage_snapshot = client.fetch_storage_snapshot( API_URL + '/storage_snapshots/snap2' ) storage_snapshot.should_not be_nil storage_snapshot.id.should eql( 'snap2' ) storage_snapshot.storage_volume.capacity.should eql( 1.0 ) @@ -68,7 +68,7 @@ describe "storage snapshot" do it "should return nil for unknown storage volume by URI" do client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) client.connect do |client| - storage_snapshot = client.fetch_storage_snapshot( API_URL + '/storage/snapshots/bogus' ) + storage_snapshot = client.fetch_storage_snapshot( API_URL + '/storage_snapshots/bogus' ) storage_snapshot.should be_nil end end diff --git a/client/specs/storage_volume_spec.rb b/client/specs/storage_volume_spec.rb index 7c5ced1..204e2b7 100644 --- a/client/specs/storage_volume_spec.rb +++ b/client/specs/storage_volume_spec.rb @@ -40,7 +40,7 @@ describe "storage volumes" do client.connect do |client| storage_volume = client.storage_volume( 'vol3' ) storage_volume.id.should eql( 'vol3' ) - storage_volume.uri.should eql( API_URL + '/storage/volumes/vol3' ) + storage_volume.uri.should eql( API_URL + '/storage_volumes/vol3' ) storage_volume.state.should eql( 'IN-USE' ) storage_volume.capacity.should eql( 1.0 ) storage_volume.device.should eql( '/dev/sda1' ) @@ -53,10 +53,10 @@ describe "storage volumes" do it "should allow fetching of storage volume by URI" do client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) client.connect do |client| - storage_volume = client.fetch_storage_volume( API_URL + '/storage/volumes/vol3' ) + storage_volume = client.fetch_storage_volume( API_URL + '/storage_volumes/vol3' ) storage_volume.should_not be_nil storage_volume.id.should eql( 'vol3' ) - storage_volume.uri.should eql( API_URL + '/storage/volumes/vol3' ) + storage_volume.uri.should eql( API_URL + '/storage_volumes/vol3' ) storage_volume.state.should eql( 'IN-USE' ) storage_volume.capacity.should eql( 1.0 ) storage_volume.device.should eql( '/dev/sda1' ) @@ -77,7 +77,7 @@ describe "storage volumes" do it "should return nil for unknown storage volume by URI" do client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) client.connect do |client| - storage_volume = client.fetch_storage_volume( API_URL + '/storage/volumes/bogus' ) + storage_volume = client.fetch_storage_volume( API_URL + '/storage_volumes/bogus' ) storage_volume.should be_nil end end
On Wed, 2010-02-17 at 09:00 -0800, lutter@redhat.com wrote:
From: David Lutterkort lutter@redhat.com
Ignore this.
David
On Wed, 2010-02-17 at 09:00 -0800, lutter@redhat.com wrote:
From: David Lutterkort lutter@redhat.com
Ignore this.
David
deltacloud-devel@lists.fedorahosted.org