Batch process records and fixups

This commit is contained in:
Endre Karlson 2012-11-04 21:45:35 +01:00
parent 7d324da36c
commit a79482fa2d
3 changed files with 9 additions and 4 deletions

View File

@ -47,7 +47,7 @@ class RecorderEngine(object):
"metadata": "{'test': 1}",
"start_timestamp": "2012-10-31T08:29:29.574000",
"end_timestamp": "2012-10-31T08:29:45.574000",
"customer_system_id": "c97027dd880d4c129ae7a4ba7edade05"
"system_account_id": "c97027dd880d4c129ae7a4ba7edade05"
}
resource_id: The ID of the resource that's billed
@ -57,5 +57,5 @@ class RecorderEngine(object):
metadata: JSON
start_timestamp: Start of the pulling period
end_timestamp: End of the pulling period
customer_system_id: The customer id in the external system
system_account_id: The account id in the external system
"""

View File

@ -71,7 +71,8 @@ class RecordEngine(OpenstackEngine):
meters = [item.get('counter_name') for item in resource['meter']]
for meter in meters:
record = self.get_record_between(
resource, meter,
resource,
meter,
start_timestamp=start_timestamp,
end_timestamp=end_timestamp)
if record is not None:
@ -98,6 +99,8 @@ class RecordEngine(OpenstackEngine):
start_timestamp=start_timestamp, end_timestamp=end_timestamp
)
volume = volume or duration_info.get('duration')
# NOTE: Not sure on this but I think we can skip returning events that
# don't have volume or duration
if not volume and not duration_info.get('duration'):
@ -105,6 +108,7 @@ class RecordEngine(OpenstackEngine):
record = dict(
resource_id=resource['resource_id'],
account_id=resource['project_id'],
type=type_,
volume=volume,
extra=metadata,

View File

@ -17,9 +17,9 @@ import os
from bufunfa.openstack.common import cfg
from bufunfa.openstack.common import log
from bufunfa.openstack.common.context import get_admin_context
from bufunfa.service import PeriodicService
from bufunfa.recorder import get_plugin
from bufunfa.central import api as central_api
LOG = log.getLogger(__name__)
@ -57,3 +57,4 @@ class Service(PeriodicService):
def periodic_tasks(self, context, raise_on_error=False):
records = self.plugin.get_records()
central_api.process_records(context, records)