deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core] Added version check from client to core version
Date Mon, 25 Oct 2010 14:35:17 GMT
From: Michal Fojtik <mfojtik@redhat.com>

---
 client/lib/deltacloud.rb       |   16 +++++++++++++---
 server/deltacloud-core.gemspec |    4 ++--
 server/server.rb               |    1 +
 server/views/api/show.xml.haml |    2 +-
 4 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
index 117a04b..71112cf 100644
--- a/client/lib/deltacloud.rb
+++ b/client/lib/deltacloud.rb
@@ -23,6 +23,8 @@ require 'logger'
 
 module DeltaCloud
 
+  REQUIRED_API_VERSION="0.1.0"
+
   # Get a new API client instance
   #
   # @param [String, user_name] API user name
@@ -70,9 +72,11 @@ module DeltaCloud
     @defined_classes || []
   end
 
+  class WrongAPIVersionException < Exception; end
+
   class API
     attr_accessor :logger
-    attr_reader   :api_uri, :driver_name, :api_version, :features, :entry_points
+    attr_reader   :api_uri, :driver_name, :api_version, :features, :entry_points, :server_version
 
     def initialize(user_name, password, api_url, opts={}, &block)
       opts[:version] = true
@@ -82,6 +86,13 @@ module DeltaCloud
       @features, @entry_points = {}, {}
       @verbose = opts[:verbose] || false
       discover_entry_points
+      if discovered?
+        valid_version = Gem::Version.new(REQUIRED_API_VERSION) <=> Gem::Version.new(@server_version)
+        if valid_version > 0
+          warn "[WARNING] API version should be >= #{REQUIRED_API_VERSION} (now using
API version #{@server_version})"
+          raise WrongAPIVersionException.new
+        end
+      end
       yield self if block_given?
     end
 
@@ -149,8 +160,6 @@ module DeltaCloud
         c.instance_eval do
           attr_accessor :id
           attr_accessor :uri
-
-
         end
         obj = xml_to_class(c, item)
       end
@@ -252,6 +261,7 @@ module DeltaCloud
         api_xml = Nokogiri::XML(response)
         @driver_name = api_xml.xpath('/api').first['driver']
         @api_version = api_xml.xpath('/api').first['version']
+        @server_version = api_xml.xpath('/api').first['server_version']
         logger << "[API] Version #{@api_version}\n"
         logger << "[API] Driver #{@driver_name}\n"
         api_xml.css("api > link").each do |entry_point|
diff --git a/server/deltacloud-core.gemspec b/server/deltacloud-core.gemspec
index e6de1bf..4164d19 100644
--- a/server/deltacloud-core.gemspec
+++ b/server/deltacloud-core.gemspec
@@ -18,7 +18,7 @@
 
 require 'rake'
 
-Gem::Specification.new do |s|
+$gem=Gem::Specification.new do |s|
   s.author = 'Red Hat, Inc.'
   s.homepage = "http://www.deltacloud.org"
   s.email = 'deltacloud-users@lists.fedorahosted.org'
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
     which implements the REST interface.
   EOF
 
-  s.version = '0.0.9'
+  s.version = '0.1.0'
   s.date = Time.now
   s.summary = %q{Deltacloud REST API}
   s.files = FileList[
diff --git a/server/server.rb b/server/server.rb
index af8bc09..7d8048f 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -10,6 +10,7 @@ require 'erb'
 require 'haml'
 require 'open3'
 require 'lib/deltacloud/helpers/blob_stream'
+load 'deltacloud-core.gemspec'
 
 configure do
   set :raise_errors => false
diff --git a/server/views/api/show.xml.haml b/server/views/api/show.xml.haml
index 70c26c9..edb748a 100644
--- a/server/views/api/show.xml.haml
+++ b/server/views/api/show.xml.haml
@@ -1,4 +1,4 @@
-%api{ :version=>@version, :driver=>DRIVER }
+%api{ :version=>@version, :server_version => $gem::version, :driver=>DRIVER }
   - for entry_point in entry_points
     %link{ :rel=>entry_point[0], :href=>entry_point[1] }
       - for feature in driver.features(entry_point[0])
-- 
1.7.2.3


Mime
View raw message