Class: Fog::Radosgw::Usage::Real

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/fog/radosgw/usage.rb,
lib/fog/radosgw/requests/usage/get_usage.rb

Instance Method Summary collapse

Methods included from Utils

#sanitize_and_convert_time

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



41
42
43
44
45
46
47
# File 'lib/fog/radosgw/usage.rb', line 41

def initialize(options = {})
  configure_uri_options(options)
  @radosgw_access_key_id     = options[:radosgw_access_key_id]
  @radosgw_secret_access_key = options[:radosgw_secret_access_key]
  @connection_options       = options[:connection_options] || {}
  @persistent               = options[:persistent]         || false
end

Instance Method Details

#get_usage(access_key_id, options = {}) ⇒ Object



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
# File 'lib/fog/radosgw/requests/usage/get_usage.rb', line 16

def get_usage(access_key_id, options = {})
  path = "admin/usage"
  t_now = Fog::Time.now
  start_time  = sanitize_and_convert_time(options[:start_time] || t_now - 86400)
  end_time    = sanitize_and_convert_time(options[:end_time]   || t_now)

  query = "?format=json&start=#{start_time}&end=#{end_time}"
  params = { 
    :method => 'GET',
    :path => path,
  }

  begin
    response = Excon.get("#{@scheme}://#{@host}/#{path}#{query}",
                         :headers => signed_headers(params))
    if !response.body.empty?
      case response.headers['Content-Type']
      when 'application/json'
        response.body = Fog::JSON.decode(response.body)
      end
    end
    response
  rescue Excon::Errors::BadRequest => e
    raise Fog::Radosgw::Provisioning::ServiceUnavailable.new
  end
end