incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michal Fojtik <mfoj...@redhat.com>
Subject Re: [PATCH] Use user_name length constraints to do length checking.
Date Wed, 08 Jun 2011 09:39:18 GMT
On Jun 7, 2011, at 9:35 PM, Chris Lalancette wrote:

> As pointed out by lutter, we had the same constant for the
> length of the name sprinkled throughout the drivers.
> Since we already need to have it in-place for the constraint,
> just re-use that when we do the checking.

ACK. It works for me, tests are green either.

  -- Michal

> 
> Signed-off-by: Chris Lalancette <clalance@redhat.com>
> ---
> .../lib/deltacloud/drivers/gogrid/gogrid_driver.rb |    8 +++++---
> .../lib/deltacloud/drivers/rhevm/rhevm_driver.rb   |    8 +++++---
> .../drivers/terremark/terremark_driver.rb          |    8 +++++---
> 3 files changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
> index edca242..a747e99 100644
> --- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
> +++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
> @@ -36,9 +36,11 @@ class GogridDriver < Deltacloud::BaseDriver
>   feature :instances, :authentication_password
>   feature :instances, :sandboxing
>   feature :instances, :user_name do
> -    constraint :max_length, "20"
> +    constraint :max_length, 20
>   end
> 
> +  USER_NAME_MAX = feature(:instances, :user_name).constraints[:max_length]
> +
>   def hardware_profiles(credentials, opts={})
>     client = new_client(credentials)
>     safely do
> @@ -103,8 +105,8 @@ class GogridDriver < Deltacloud::BaseDriver
>       name = "Server #{Time.now.to_i.to_s.reverse[0..3]}#{rand(9)}"
>     end
> 
> -    if name.length > 20
> -      raise "Parameter name must be 20 characters or less"
> +    if name.length > USER_NAME_MAX
> +      raise "Parameter name must be #{USER_NAME_MAX} characters or less"
>     end
> 
>     client = new_client(credentials)
> diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
> index 4930f3e..221edc8 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)
> @@ -174,8 +176,8 @@ class RHEVMDriver < Deltacloud::BaseDriver
>     if not name
>       name = Time.now.to_i.to_s
>     end
> -    if name.length > 50
> -      raise "Parameter name must be 50 characters or less"
> +    if name.length > USER_NAME_MAX
> +      raise "Parameter name must be #{USER_NAME_MAX} characters or less"
>     end
>     safely do
>       params[:name] = name
> diff --git a/server/lib/deltacloud/drivers/terremark/terremark_driver.rb b/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
> index 32fceee..ba5209d 100644
> --- a/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
> +++ b/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
> @@ -32,9 +32,11 @@ module Deltacloud
> class TerremarkDriver < Deltacloud::BaseDriver
> 
>   feature :instances, :user_name do
> -    constraint :max_length, "15"
> +    constraint :max_length, 15
>   end
> 
> +  USER_NAME_MAX = feature(:instances, :user_name).constraints[:max_length]
> +
> #--
> # Vapp State Map... for use with convert_instance (get an integer back from terremark)
> #--
> @@ -134,8 +136,8 @@ VAPP_STATE_MAP = { "0" =>  "PENDING", "1" =>  "PENDING", "2"
=>  "STOPPED", "4"
>     if not name
>       name = "inst#{Time.now.to_i}"
>     end
> -    if name.length > 15
> -      raise "Parameter name must be 15 characters or less"
> +    if name.length > USER_NAME_MAX
> +      raise "Parameter name must be #{USER_NAME_MAX} characters or less"
>     end
>     unless ( (terremark_hwp.include?(:cpu, opts[:hwp_cpu].to_i)) &&
>               (terremark_hwp.include?(:memory, opts[:hwp_memory].to_i)) ) then
> -- 
> 1.7.4.4
> 

------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org


Mime
View raw message