incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject svn commit: r962279 - in /incubator/deltacloud/trunk/server/lib/deltacloud: hardware_profile.rb helpers/hardware_profiles_helper.rb
Date Thu, 08 Jul 2010 23:43:00 GMT
Author: lutter
Date: Thu Jul  8 23:43:00 2010
New Revision: 962279

URL: http://svn.apache.org/viewvc?rev=962279&view=rev
Log:
Hardware profiles: add defaults, param name and units to properties

Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/hardware_profile.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/helpers/hardware_profiles_helper.rb

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/hardware_profile.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/hardware_profile.rb?rev=962279&r1=962278&r2=962279&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/hardware_profile.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/hardware_profile.rb Thu Jul  8 23:43:00
2010
@@ -2,8 +2,19 @@
 module Deltacloud
   class HardwareProfile
 
+    UNITS = {
+      :memory => "MB",
+      :storage => "GB",
+      :architecture => "label",
+      :cpu => "count"
+    }
+
+    def self.unit(name)
+      UNITS[name]
+    end
+
     class Property
-      attr_reader :name, :kind
+      attr_reader :name, :kind, :default
       # kind == :range
       attr_reader :first, :last
       # kind == :enum
@@ -11,29 +22,45 @@ module Deltacloud
       # kind == :fixed
       attr_reader :value
 
-      def initialize(name, values)
+      def initialize(name, values, opts = {})
         @name = name
         if values.is_a?(Range)
           @kind = :range
           @first = values.first
           @last = values.last
+          @default = values.first
         elsif values.is_a?(Array)
           @kind = :enum
           @values = values
+          @default = values.first
         else
           @kind = :fixed
           @value = values
+          @default = @value
         end
+        @default = opts[:default] if opts[:default]
+      end
+
+      def unit
+        HardwareProfile.unit(name)
+      end
+
+      def param
+        "hwp_#{name}"
+      end
+
+      def fixed?
+        kind == :fixed
       end
     end
 
     class << self
       def property(prop)
         define_method(prop) do |*args|
-          values, *ignored = *args
+          values, opts, *ignored = *args
           instvar = :"@#{prop}"
           unless values.nil?
-            @properties[prop] = Property.new(prop, values)
+            @properties[prop] = Property.new(prop, values, opts || {})
           end
           @properties[prop]
         end
@@ -55,5 +82,18 @@ module Deltacloud
     def each_property(&block)
       @properties.each_value { |prop| yield prop }
     end
+
+    def properties
+      @properties.values
+    end
+
+    def property(name)
+      @properties[name.to_sym]
+    end
+
+    def default?(prop, v)
+      p = @properties[prop.to_sym]
+      p && p.default.to_s == v
+    end
   end
 end

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/helpers/hardware_profiles_helper.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/helpers/hardware_profiles_helper.rb?rev=962279&r1=962278&r2=962279&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/helpers/hardware_profiles_helper.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/helpers/hardware_profiles_helper.rb Thu
Jul  8 23:43:00 2010
@@ -4,9 +4,9 @@ module HardwareProfilesHelper
     return "&empty;" unless prop
     case prop.kind
       when :range
-        "#{prop.first} - #{prop.last}"
+      "#{prop.first} - #{prop.last} (default: #{prop.default})"
       when :enum
-        prop.values.join(', ')
+      prop.values.join(', ') + " (default: #{prop.default})"
       else
         prop.value.to_s
     end



Mime
View raw message