class Fog::Metering::OpenStack::Real

Public Class Methods

new(options = {}) click to toggle source
# File lib/fog/metering/openstack.rb, line 102
def initialize(options = {})
  initialize_identity options

  @openstack_service_type           = options[:openstack_service_type] || ['metering']
  @openstack_service_name           = options[:openstack_service_name]
  @openstack_endpoint_type          = options[:openstack_endpoint_type] || 'adminURL'

  @connection_options               = options[:connection_options] || {}

  authenticate
  set_api_path

  @persistent = options[:persistent] || false
  @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end
not_found_class() click to toggle source
# File lib/fog/metering/openstack.rb, line 98
def self.not_found_class
  Fog::Metering::OpenStack::NotFound
end

Public Instance Methods

get_event(message_id) click to toggle source
# 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) click to toggle source
# 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 = []) click to toggle source
# File lib/fog/metering/openstack/requests/get_samples.rb, line 5
def get_samples(meter_id, 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/#{meter_id}"
  )
end
get_statistics(meter_id, options = {}) click to toggle source
# 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 = []) click to toggle source
# 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 = []) click to toggle source
# 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 = {}) click to toggle source
# File lib/fog/metering/openstack/requests/list_resources.rb, line 5
def list_resources(_options = {})
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => 'resources'
  )
end
set_api_path() click to toggle source
# File lib/fog/metering/openstack.rb, line 118
def set_api_path
  unless @path.match(SUPPORTED_VERSIONS)
    @path = "/" + Fog::OpenStack.get_supported_version(
      SUPPORTED_VERSIONS,
      @openstack_management_uri,
      @auth_token,
      @connection_options
    )
  end
end