From: David Lutterkort <[email protected]>

---
 server/lib/deltacloud/base_driver/base_driver.rb |   21 +++++++++++++++++----
 server/lib/deltacloud/hardware_profile.rb        |   15 +++++++++++++++
 server/server.rb                                 |    2 +-
 3 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/server/lib/deltacloud/base_driver/base_driver.rb 
b/server/lib/deltacloud/base_driver/base_driver.rb
index fc8c835..373d64e 100644
--- a/server/lib/deltacloud/base_driver/base_driver.rb
+++ b/server/lib/deltacloud/base_driver/base_driver.rb
@@ -51,12 +51,25 @@ module Deltacloud
       @hardware_profiles
     end
 
-    def hardware_profiles
-      self.class.hardware_profiles
+    def hardware_profiles(credentials, opts = nil)
+      results = self.class.hardware_profiles
+      filter_hardware_profiles(results, opts)
     end
 
-    def hardware_profile(name)
-      self.class.hardware_profiles.find{|e| e.name == name }
+    def hardware_profile(credentials, name)
+      hardware_profiles(credentials, :name => name).first
+    end
+
+    def filter_hardware_profiles(profiles, opts)
+      if opts
+        if v = opts[:architecture]
+          profiles = profiles.select { |hwp| hwp.include?(:architecture, v) }
+        end
+        if v = opts[:name]
+          profiles = profiles.select { |hwp| hwp.name == v }
+        end
+      end
+      profiles
     end
 
     def self.define_instance_states(&block)
diff --git a/server/lib/deltacloud/hardware_profile.rb 
b/server/lib/deltacloud/hardware_profile.rb
index e7eaf8b..2d791bc 100644
--- a/server/lib/deltacloud/hardware_profile.rb
+++ b/server/lib/deltacloud/hardware_profile.rb
@@ -63,6 +63,16 @@ module Deltacloud
         end
         Validation::Param.new(args)
       end
+
+      def include?(v)
+        if kind == :fixed
+          return v == value
+        elsif kind == :range
+          return v >= first && v <= last
+        else
+          return values.include?(v)
+        end
+      end
     end
 
     class << self
@@ -107,6 +117,11 @@ module Deltacloud
       p && p.default.to_s == v
     end
 
+    def include?(prop, v)
+      p = @properties[prop]
+      p.nil? || p.include?(v)
+    end
+
     def params
       @properties.values.inject([]) { |m, prop|
         m << prop.to_param
diff --git a/server/server.rb b/server/server.rb
index 187aa07..7151f47 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -302,7 +302,7 @@ END
     description "Show specific hardware profile"
     param :id,          :string,    :required
     control do
-      @profile =  driver.hardware_profile(params[:id])
+      @profile =  driver.hardware_profile(credentials, params[:id])
       respond_to do |format|
         format.xml { haml :'hardware_profiles/show', :layout => false }
         format.html { haml :'hardware_profiles/show' }
-- 
1.6.6.1

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to