File: get_statistics.rb

package info (click to toggle)
ruby-fog-openstack 1.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,784 kB
  • sloc: ruby: 47,937; makefile: 5; sh: 4
file content (52 lines) | stat: -rw-r--r-- 1,445 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
module Fog
  module OpenStack
    class Metering
      class Real
        def get_statistics(meter_id, options = {})
          data = {
            'period' => options['period'],
            'q'      => []
          }

          options['q'].each do |opt|
            filter = {}

            ['field', 'op', 'value'].each do |key|
              filter[key] = opt[key] if opt[key]
            end

            data['q'] << filter unless filter.empty?
          end if options['q'].kind_of? Array

          request(
            :body    => Fog::JSON.encode(data),
            :expects => 200,
            :method  => 'GET',
            :path    => "meters/#{meter_id}/statistics"
          )
        end
      end

      class Mock
        def get_statistics(_meter_id, _options = {})
          response = Excon::Response.new
          response.status = 200
          response.body = [{
            'count'          => 143,
            'duration_start' => '2013-04-03T23:44:21',
            'min'            => 10.0,
            'max'            => 10.0,
            'duration_end'   => '2013-04-04T23:24:21',
            'period'         => 0,
            'period_end'     => '2013-04-04T23:24:21',
            'duration'       => 85200.0,
            'period_start'   => '2013-04-03T23:44:21',
            'avg'            => 10.0,
            'sum'            => 1430.0
          }]
          response
        end
      end
    end
  end
end