Class: Fog::Metering::HuaweiCloud::Real
- Inherits:
-
Object
- Object
- Fog::Metering::HuaweiCloud::Real
- Includes:
- HuaweiCloud::Core
- Defined in:
- lib/fog/metering/huaweicloud.rb,
lib/fog/metering/huaweicloud/requests/get_event.rb,
lib/fog/metering/huaweicloud/requests/get_samples.rb,
lib/fog/metering/huaweicloud/requests/list_events.rb,
lib/fog/metering/huaweicloud/requests/list_meters.rb,
lib/fog/metering/huaweicloud/requests/get_resource.rb,
lib/fog/metering/huaweicloud/requests/get_statistics.rb,
lib/fog/metering/huaweicloud/requests/list_resources.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get_event(message_id) ⇒ Object
- #get_resource(resource_id) ⇒ Object
- #get_samples(meter_id, options = [], limit = 10000000) ⇒ Object
- #get_statistics(meter_id, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #list_events(options = []) ⇒ Object
- #list_meters(options = []) ⇒ Object
- #list_resources(_options = {}) ⇒ Object
- #set_api_path ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/fog/metering/huaweicloud.rb', line 103 def initialize( = {}) initialize_identity @huaweicloud_service_type = [:huaweicloud_service_type] || ['metering'] @huaweicloud_service_name = [:huaweicloud_service_name] @huaweicloud_endpoint_type = [:huaweicloud_endpoint_type] || 'adminURL' = [:connection_options] || {} authenticate set_api_path @persistent = [:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, ) end |
Class Method Details
.not_found_class ⇒ Object
99 100 101 |
# File 'lib/fog/metering/huaweicloud.rb', line 99 def self.not_found_class Fog::Metering::HuaweiCloud::NotFound end |
Instance Method Details
#get_event(message_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/metering/huaweicloud/requests/get_event.rb', line 5 def get_event() 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/huaweicloud/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/huaweicloud/requests/get_samples.rb', line 5 def get_samples(meter_id, = [], limit = 10000000) data = { '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? 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/huaweicloud/requests/get_statistics.rb', line 5 def get_statistics(meter_id, = {}) data = { 'period' => ['period'], 'q' => [] } ['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 ['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/huaweicloud/requests/list_events.rb', line 5 def list_events( = []) data = { '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 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/huaweicloud/requests/list_meters.rb', line 5 def list_meters( = []) data = { '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 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/huaweicloud/requests/list_resources.rb', line 5 def list_resources( = {}) request( :expects => 200, :method => 'GET', :path => 'resources' ) end |
#set_api_path ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/fog/metering/huaweicloud.rb', line 119 def set_api_path unless @path.match(SUPPORTED_VERSIONS) @path = "/" + Fog::HuaweiCloud.get_supported_version( SUPPORTED_VERSIONS, @huaweicloud_management_uri, @auth_token, ) end end |