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 2013/02/19 14:00:57 UTC

[6/7] git commit: Mock: Cleanup in how we create mock 'metrics'

Mock: Cleanup in how we create mock 'metrics'

Moved the code to the Metric model to keep MockDriver
clean.


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/3e6721b2
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/3e6721b2
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/3e6721b2

Branch: refs/heads/master
Commit: 3e6721b224cc93ca78f03561a2a1153c6f2fc630
Parents: 65c7855
Author: Michal Fojtik <mf...@redhat.com>
Authored: Mon Feb 18 14:26:53 2013 +0100
Committer: Michal fojtik <mf...@redhat.com>
Committed: Tue Feb 19 13:57:02 2013 +0100

----------------------------------------------------------------------
 server/lib/deltacloud/models/metric.rb |   45 +++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3e6721b2/server/lib/deltacloud/models/metric.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/models/metric.rb b/server/lib/deltacloud/models/metric.rb
index 7970565..1f7f422 100644
--- a/server/lib/deltacloud/models/metric.rb
+++ b/server/lib/deltacloud/models/metric.rb
@@ -18,6 +18,18 @@ class Metric < BaseModel
   attr_accessor :entity
   attr_accessor :properties
 
+  MOCK_METRICS_NAMES = [
+    'cpuUtilization',
+    'diskReadRequestCount',
+    'diskReadSector',
+    'diskWriteRequestCount',
+    'diskWriteSector',
+    'nicInputByte',
+    'nicInputPacket',
+    'nicOutputByte',
+    'nicOutputPacket'
+  ]
+
   def unknown?
     self.entity == :unknown
   end
@@ -51,6 +63,39 @@ class Metric < BaseModel
         :values => values
       }
     end
+
+    def generate_mock_values!
+      generator = lambda { |name, kind|
+        v = {
+          :min => (1+(rand(49))),
+          :max => (50+(rand(50)))
+        }
+        (name == 'cpuUtilization') ? v[kind].to_f/100 : v[kind]
+      }
+      @values = (0..5).map do |v_id|
+        {
+          :minimum => min = generator.call(@name, :min),
+          :maximum => max = generator.call(@name, :max),
+          :average => (min+max)/2,
+          :timestamp => (Time.now-v_id).to_i,
+          :unit => unit_for(@name)
+        }
+      end
+    end
+
+    private
+
+    def unit_for(name)
+      case name
+        when /Utilization/ then 'Percent'
+        when /Byte/ then 'Bytes'
+        when /Sector/ then 'Count'
+        when /Count/ then 'Count'
+        when /Packet/ then 'Count'
+        else 'None'
+      end
+    end
+
   end
 
 end