You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by Chris Lalancette <cl...@redhat.com> on 2011/06/03 15:38:00 UTC
[PATCH] Rationalize param declarations.
It seems pretty odd that param initialization can do
different things depending on the type of the 3rd argument.
I think it is easier to understand if the 3rd argument always
means 'options', and the 4th argument always means 'description'.
Luckily most of the callers were already conforming to this
pattern; just a few of them had to be changed to add an additional
argument between the [:required, :optional] declaration and
the description.
Along with this, rationalize the param declarations in features.rb
so that the options are set to [], instead of nil. This matches
what param declarations do by default.
Signed-off-by: Chris Lalancette <cl...@redhat.com>
---
server/lib/deltacloud/base_driver/features.rb | 14 ++++++--------
server/lib/deltacloud/validation.rb | 8 ++------
server/server.rb | 6 +++---
3 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/server/lib/deltacloud/base_driver/features.rb b/server/lib/deltacloud/base_driver/features.rb
index 65c4cba..4d557e6 100644
--- a/server/lib/deltacloud/base_driver/features.rb
+++ b/server/lib/deltacloud/base_driver/features.rb
@@ -151,22 +151,21 @@ module Deltacloud
declare_feature :images, :owner_id do
description "Filter images using owner id"
operation :index do
- param :owner_id, :string, :optional, nil, "Owner ID"
+ param :owner_id, :string, :optional, [], "Owner ID"
end
end
declare_feature :instances, :user_name do
description "Accept a user-defined name on instance creation"
operation :create do
- param :name, :string, :optional, nil,
- "The user-defined name"
+ param :name, :string, :optional, [], "The user-defined name"
end
end
declare_feature :instances, :user_data do
description "Make user-defined data available on a special webserver"
operation :create do
- param :user_data, :string, :optional, nil,
+ param :user_data, :string, :optional, [],
"Base64 encoded user data will be published to internal webserver"
end
end
@@ -175,7 +174,7 @@ module Deltacloud
description "Accept up to 5 files to be placed into the instance before launch."
operation :create do
1.upto(5) do |i|
- param :"path#{i}", :string, :optional, nil,
+ param :"path#{i}", :string, :optional, [],
"Path where to place the #{i.ordinalize} file, up to 255 characters"
param :"content#{i}", :string, :optional, nil,
"Contents for the #{i.ordinalize} file, up to 10 kB, Base64 encoded"
@@ -186,15 +185,14 @@ module Deltacloud
declare_feature :instances, :security_group do
description "Put instance in one or more security groups on launch"
operation :create do
- param :security_group, :array, :optional, nil,
+ param :security_group, :array, :optional, [],
"Array of security group names"
end
end
declare_feature :instances, :authentication_key do
operation :create do
- param :keyname, :string, :optional, nil
- "EC2 key authentification method"
+ param :keyname, :string, :optional, [], "Key authentification method"
end
operation :show do
end
diff --git a/server/lib/deltacloud/validation.rb b/server/lib/deltacloud/validation.rb
index 0375c29..5c75d18 100644
--- a/server/lib/deltacloud/validation.rb
+++ b/server/lib/deltacloud/validation.rb
@@ -35,12 +35,8 @@ module Deltacloud::Validation
@name = args[0]
@klass = args[1] || :string
@type = args[2] || :optional
- if args[3] and args[3].class.eql?(String)
- @description = args[3]
- @options = []
- end
- @options ||= args[3] || []
- @description ||= args[4] || ''
+ @options = args[3] || []
+ @description = args[4] || ''
end
def required?
diff --git a/server/server.rb b/server/server.rb
index a27b7ef..07ccc9b 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -437,9 +437,9 @@ END
END
with_capability :run_on_instance
param :id, :string, :required
- param :cmd, :string, :required, "Shell command to run on instance"
- param :private_key, :string, :optional, "Private key in PEM format for authentication"
- param :password, :string, :optional, "Password used for authentication"
+ param :cmd, :string, :required, [], "Shell command to run on instance"
+ param :private_key, :string, :optional, [], "Private key in PEM format for authentication"
+ param :password, :string, :optional, [], "Password used for authentication"
control do
@output = driver.run_on_instance(credentials, params)
respond_to do |format|
--
1.7.4.4
Re: [PATCH] Rationalize param declarations.
Posted by David Lutterkort <lu...@redhat.com>.
On Fri, 2011-06-03 at 09:38 -0400, Chris Lalancette wrote:
> It seems pretty odd that param initialization can do
> different things depending on the type of the 3rd argument.
> I think it is easier to understand if the 3rd argument always
> means 'options', and the 4th argument always means 'description'.
>
> Luckily most of the callers were already conforming to this
> pattern; just a few of them had to be changed to add an additional
> argument between the [:required, :optional] declaration and
> the description.
>
> Along with this, rationalize the param declarations in features.rb
> so that the options are set to [], instead of nil. This matches
> what param declarations do by default.
>
> Signed-off-by: Chris Lalancette <cl...@redhat.com>
ACK. It would have been cleaner to pass the description and default
value in as a hash from the get-go, but this is good enough as a code
clarification.
What I mean with the hash is sth like
param :name, :string, :optional, :default => "foo", :descr => "The user-defined name"
but that can be fixed up at some later point.
David