Skip to content
Browse files

Adds ordering of hardware profiles returned from the Provider. Orderi…

…ng is

first by cpu and then by memory. Addresses JIRA DTACLOUD_208

https://issues.apache.org/jira/browse/DTACLOUD-208
  • Loading branch information...
1 parent 862c7cb commit ef31a07e467ffae110b1c1d68580a88cdad8d6ce @marios marios committed
Showing with 13 additions and 0 deletions.
  1. +12 −0 server/lib/deltacloud/helpers/hardware_profiles_helper.rb
  2. +1 −0 server/lib/deltacloud/server.rb
View
12 server/lib/deltacloud/helpers/hardware_profiles_helper.rb
@@ -40,7 +40,19 @@ def format_instance_profile(ip)
end
end
+ #first by cpu - then by memory
+ def order_hardware_profiles(profiles)
+ #have to deal with opaque hardware profiles
+ uncomparables = profiles.select{|x| x.cpu.nil? or x.memory.nil? }
+ if uncomparables.empty?
+ profiles.sort_by{|a| [a.cpu.default, a.memory.default] }
+ else
+ (profiles - uncomparables).sort_by{|a| [a.cpu.default, a.memory.default] } + uncomparables
+ end
+ end
+
private
+
def hardware_property_unit(prop)
u = ::Deltacloud::HardwareProfile::unit(prop)
u = "" if ["label", "count"].include?(u)
View
1 server/lib/deltacloud/server.rb
@@ -590,6 +590,7 @@
param :architecture, :string, :optional, [ 'i386', 'x86_64' ]
control do
@profiles = driver.hardware_profiles(credentials, params)
+ @profiles = order_hardware_profiles(@profiles)
respond_to do |format|
format.xml { haml :'hardware_profiles/index' }
format.html { haml :'hardware_profiles/index' }

0 comments on commit ef31a07

Please sign in to comment.
Something went wrong with that request. Please try again.