You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2012/05/22 22:19:37 UTC
[25/50] [abbrv] git commit: Core: Driver constraints,
like :max_length are now advertised correctly
Core: Driver constraints, like :max_length are now advertised correctly
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/cd83a417
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/cd83a417
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/cd83a417
Branch: refs/heads/master
Commit: cd83a41759d3732bd3155d2c3ad58d9267c65bbe
Parents: 543f6a8
Author: Michal Fojtik <mf...@redhat.com>
Authored: Thu May 17 13:24:18 2012 +0200
Committer: Michal fojtik <mf...@redhat.com>
Committed: Tue May 22 22:17:37 2012 +0200
----------------------------------------------------------------------
server/lib/deltacloud/drivers/base_driver.rb | 11 +++++++++++
.../lib/deltacloud/drivers/gogrid/gogrid_driver.rb | 11 +++++++----
.../lib/deltacloud/drivers/rhevm/rhevm_driver.rb | 12 ++++--------
server/views/api/show.xml.haml | 2 ++
4 files changed, 24 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/cd83a417/server/lib/deltacloud/drivers/base_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/base_driver.rb b/server/lib/deltacloud/drivers/base_driver.rb
index 3d4c75d..9913c27 100644
--- a/server/lib/deltacloud/drivers/base_driver.rb
+++ b/server/lib/deltacloud/drivers/base_driver.rb
@@ -42,9 +42,20 @@ module Deltacloud
def self.feature(collection, feature_name)
return if has_feature?(collection, feature_name)
+ constraints[collection] ||= {}
+ constraints[collection][feature_name] ||= {}
+ constraints[collection][feature_name].merge!(yield) if block_given?
features << { collection => feature_name }
end
+ def self.constraints(opts={})
+ if opts[:collection] and opts[:feature]
+ return [] unless @constraints.has_key? opts[:collection]
+ return @constraints[opts[:collection]][opts[:feature]]
+ end
+ @constraints ||= {}
+ end
+
def self.has_feature?(collection, feature_name)
features.any? { |f| (f.values.first == feature_name) && (f.keys.first == collection) }
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/cd83a417/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
index ee08afe..6469312 100644
--- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
+++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
@@ -32,13 +32,16 @@ module Deltacloud
class GogridDriver < Deltacloud::BaseDriver
- feature :instances, :authentication_password
- feature :instances, :sandboxing
feature :instances, :user_name do
- constraint :max_length, 20
+ { :max_length => 20 }
end
- USER_NAME_MAX = feature(:instances, :user_name).constraints[:max_length]
+ feature :instances, :authentication_password
+ feature :instances, :sandboxing
+
+ define_hardware_profile 'default'
+
+ USER_NAME_MAX = constraints(:collection => :instances, :feature => :user_name)[:max_length]
def hardware_profiles(credentials, opts={})
client = new_client(credentials)
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/cd83a417/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
index f138f03..e93c631 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
@@ -22,16 +22,12 @@ module Deltacloud
class RhevmDriver < Deltacloud::BaseDriver
- Sinatra::Rabbit::InstancesCollection.features do
- feature :user_name, :for => :instances do
- constrain :max_length, 50
- end
- end
-
feature :instances, :user_data
- feature :images, :user_name
+ feature :instances, :user_name do
+ { :max_length => 50 }
+ end
- USER_NAME_MAX = Sinatra::Rabbit::InstancesCollection.feature(:user_name).constraints[:max_length]
+ USER_NAME_MAX = constraints(:collection => :instances, :feature => :user_name)[:max_length]
# FIXME: These values are just for ilustration
# Also I choosed 'SERVER' and 'DESKTOP' names
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/cd83a417/server/views/api/show.xml.haml
----------------------------------------------------------------------
diff --git a/server/views/api/show.xml.haml b/server/views/api/show.xml.haml
index ad2df09..4ba8168 100644
--- a/server/views/api/show.xml.haml
+++ b/server/views/api/show.xml.haml
@@ -4,3 +4,5 @@
%link{ :rel => c.collection_name, :href => self.send(:"#{c.collection_name}_url")}
- c.features.select { |f| driver.class.has_feature?(c.collection_name, f.name) }.each do |f|
%feature{ :name => f.name }
+ - driver.class.constraints(:collection => c.collection_name, :feature => f.name).each do |name, value|
+ %constraint{ :name => name }=value