Class: Fog::Metering::OpenStack::Real

Inherits:
Object
  • Object
show all
Includes:
OpenStack::Core
Defined in:
lib/fog/metering/openstack.rb,
lib/fog/metering/openstack/requests/get_event.rb,
lib/fog/metering/openstack/requests/get_samples.rb,
lib/fog/metering/openstack/requests/list_events.rb,
lib/fog/metering/openstack/requests/list_meters.rb,
lib/fog/metering/openstack/requests/get_resource.rb,
lib/fog/metering/openstack/requests/get_statistics.rb,
lib/fog/metering/openstack/requests/list_resources.rb

Instance Attribute Summary

Attributes included from OpenStack::Core

#auth_token, #auth_token_expiration, #current_tenant, #current_user, #current_user_id, #openstack_cache_ttl, #openstack_domain_id, #openstack_domain_name, #openstack_identity_api_version, #openstack_project_domain, #openstack_project_domain_id, #openstack_project_id, #openstack_user_domain, #openstack_user_domain_id, #unscoped_token

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OpenStack::Core

#credentials, #initialize, #reload

Class Method Details

.not_found_classObject



99
100
101
# File 'lib/fog/metering/openstack.rb', line 99

def self.not_found_class
  Fog::Metering::OpenStack::NotFound
end

Instance Method Details

#default_endpoint_typeObject



103
104
105
# File 'lib/fog/metering/openstack.rb', line 103

def default_endpoint_type
  'admin'
end

#default_path_prefixObject



107
108
109
# File 'lib/fog/metering/openstack.rb', line 107

def default_path_prefix
  'v2'
end

#default_service_typeObject



111
112
113
# File 'lib/fog/metering/openstack.rb', line 111

def default_service_type
  %w[metering]
end

#get_event(message_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/metering/openstack/requests/get_event.rb', line 5

def get_event(message_id)
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => "events/#{message_id}"
  )
end

#get_resource(resource_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/metering/openstack/requests/get_resource.rb', line 5

def get_resource(resource_id)
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => "resources/#{resource_id}"
  )
end

#get_samples(meter_id, options = [], limit = 10000000) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/metering/openstack/requests/get_samples.rb', line 5

def get_samples(meter_id, options = [], limit = 10000000)
  data = {
    'q' => []
  }

  options.each do |opt|
    filter = {}

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

    data['q'] << filter unless filter.empty?
    data['limit'] = limit
  end

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

#get_statistics(meter_id, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/metering/openstack/requests/get_statistics.rb', line 5

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

#list_events(options = []) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fog/metering/openstack/requests/list_events.rb', line 5

def list_events(options = [])
  data = {
    'q' => []
  }

  options.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

  request(
    :body    => Fog::JSON.encode(data),
    :expects => 200,
    :method  => 'GET',
    :path    => 'events'
  )
end

#list_meters(options = []) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fog/metering/openstack/requests/list_meters.rb', line 5

def list_meters(options = [])
  data = {
    'q' => []
  }

  options.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

  request(
    :body    => Fog::JSON.encode(data),
    :expects => 200,
    :method  => 'GET',
    :path    => 'meters'
  )
end

#list_resources(_options = {}) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/metering/openstack/requests/list_resources.rb', line 5

def list_resources(_options = {})
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => 'resources'
  )
end