From: Michal Fojtik <[email protected]>
Signed-off-by: Michal fojtik <[email protected]> --- server/lib/deltacloud/drivers/base_driver.rb | 11 +++++++++++ server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb | 11 +++++++---- server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb | 12 ++++-------- server/views/api/show.xml.haml | 2 ++ 4 files changed, 24 insertions(+), 12 deletions(-) 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 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) 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 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 -- 1.7.10.1
