incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Lutterkort <lut...@redhat.com>
Subject Re: [PATCH] Add max_length constraints to the user_name for various drivers.
Date Mon, 06 Jun 2011 13:40:52 GMT
On Fri, 2011-06-03 at 09:38 -0400, Chris Lalancette wrote:
> Signed-off-by: Chris Lalancette <clalance@redhat.com>
> ---
>  .../lib/deltacloud/drivers/gogrid/gogrid_driver.rb |    3 +++
>  .../lib/deltacloud/drivers/rhevm/rhevm_driver.rb   |    4 +++-
>  .../drivers/terremark/terremark_driver.rb          |    4 +++-
>  3 files changed, 9 insertions(+), 2 deletions(-)

ACK, though I would be marginally happier if we used a constant in the
driver code to check for max_length violation; otherwise, if RHEV-M
decides to go to max_length 52, we'll have to scour the code carefully
to do that. What I have in mind is sth like the patch below, plus
analogous changes to the other drivers:

diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
index f8ce8a6..00d3f3b 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
@@ -34,9 +34,11 @@ module Deltacloud
 class RHEVMDriver < Deltacloud::BaseDriver
 
   feature :instances, :user_name do
-    constraint :max_length, "50"
+    constraint :max_length, 50
   end
 
+  USER_NAME_MAX = feature(:instances, :user_name).constraints[:max_length]
+
   # FIXME: These values are just for ilustration
   # Also I choosed 'SERVER' and 'DESKTOP' names
   # because they are referred by VM (API type)
@@ -170,8 +172,8 @@ class RHEVMDriver < Deltacloud::BaseDriver
   def create_instance(credentials, image_id, opts={})
     client = new_client(credentials)
     params = {}
-    if opts[:name] && opts[:name].length > 50
-      raise "Parameter name must be shorter than 50 characters"
+    if opts[:name] && opts[:name].length > USER_NAME_MAX
+      raise "Parameter name must be shorter than #{USER_NAME_MAX} characters"
     end
     safely do
       params[:name] = opts[:name] if opts[:name]



Mime
View raw message