Class: OpenStack::Nova::Compute::SimpleTenantUsage
- Inherits:
-
Base
- Object
- ActiveResource::Base
- Base
- Common
- Base
- OpenStack::Nova::Compute::SimpleTenantUsage
- Defined in:
- lib/open_stack/nova/compute/simple_tenant_usage.rb
Overview
Server usages for a tenant
Attributes
-
total_hours
- Amount of hour the SimpleTenantUsage instance is related to -
total_vcpus_usage
- Aggregated virtual cpu usage -
total_memory_mb_usage
- Aggregated memory usage (MBytes) -
total_local_gb_usage
- Aggregated storage usage (GBytes)
Class Method Summary collapse
-
.find(*arguments) ⇒ Object
Redefine the find method to add the detailed flag.
-
.find_between_dates(scope, from_date, to_date) ⇒ Object
Find all server usage between the given dates.
-
.find_from_date(scope, from_date) ⇒ Object
Find all server usage from a given date to the current one.
Instance Method Summary collapse
-
#server_usages ⇒ Object
OpenStack::Nova::Compute::ServerUsage instances.
-
#start ⇒ Object
The start date for the ServerUsage set.
-
#stop ⇒ Object
The stop date for the ServerUsage set.
Methods inherited from Base
Methods inherited from Common
collection_path, custom_method_collection_url, element_path
Methods inherited from Base
Methods inherited from ActiveResource::Base
Class Method Details
.find(*arguments) ⇒ Object
Redefine the find method to add the detailed flag
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/open_stack/nova/compute/simple_tenant_usage.rb', line 43 def self.find(*arguments) # :nodoc: scope = arguments.slice!(0) = arguments.slice!(0) || {} # Add "detailed => 1" to the query_options because of broken RESTful # (see: http://api.openstack.org @"Simple Usage") - DG - 09/07/2012 if [:params].nil? [:params] = {:detailed => 1} else [:params].merge! :detailed => 1 end # If there is no data for the given date intervals, an empty usage will be returned. # we "filter out" these entries case scope when :all then find_every().select { |su| su.attributes[:tenant_id].present? } when :first then su = find_every().first su && su.attributes[:tenant_id].present? ? su : nil when :last then su = find_every().last su && su.attributes[:tenant_id].present? ? su : nil when :one then su = find_one() su && su.attributes[:tenant_id].present? ? su : nil else su = find_single(scope, ) su && su.attributes[:tenant_id].present? ? su : nil end end |
.find_between_dates(scope, from_date, to_date) ⇒ Object
Find all server usage between the given dates
Attributes
-
scope
- ActiveResource scope (:all, :first, :last, :one or an id) -
from_date
- Initial date -
to_date
- Final date
96 97 98 99 100 101 102 |
# File 'lib/open_stack/nova/compute/simple_tenant_usage.rb', line 96 def self.find_between_dates(scope, from_date, to_date) find(scope, :params => { :start => from_date.utc.strftime(OpenStack::DATETIME_FORMAT), :end => to_date.utc.strftime(OpenStack::DATETIME_FORMAT) }) end |
.find_from_date(scope, from_date) ⇒ Object
Find all server usage from a given date to the current one
Attributes
-
scope
- ActiveResource scope (:all, :first, :last, :one or an id) -
from_date
- Initial date
80 81 82 83 84 85 86 87 88 |
# File 'lib/open_stack/nova/compute/simple_tenant_usage.rb', line 80 def self.find_from_date(scope, from_date) now = Time.now.utc find(scope, :params => { :start => from_date.utc.strftime(OpenStack::DATETIME_FORMAT), :end => now.strftime(OpenStack::DATETIME_FORMAT) }) end |
Instance Method Details
#server_usages ⇒ Object
OpenStack::Nova::Compute::ServerUsage instances
105 106 107 |
# File 'lib/open_stack/nova/compute/simple_tenant_usage.rb', line 105 def server_usages @attributes[:server_usages].present? ? @attributes[:server_usages] : [] end |
#start ⇒ Object
The start date for the ServerUsage set
110 111 112 |
# File 'lib/open_stack/nova/compute/simple_tenant_usage.rb', line 110 def start DateTime.parse(@attributes[:start] + ' UTC') end |
#stop ⇒ Object
The stop date for the ServerUsage set
115 116 117 |
# File 'lib/open_stack/nova/compute/simple_tenant_usage.rb', line 115 def stop DateTime.parse(@attributes[:stop] + ' UTC') end |