Dn not update some resource properties for each period
Change-Id: I2f27dd11c516d34d8c914191f72034c91fe7d517 Closes-Bug: #1599308
This commit is contained in:
parent
ab768cf012
commit
834765a2d7
|
@ -138,7 +138,7 @@ class BaseCollector(object):
|
||||||
|
|
||||||
return os_distro
|
return os_distro
|
||||||
|
|
||||||
def _get_resource_info(self, resource_id, resource_type, entry,
|
def _get_resource_info(self, project_id, resource_id, resource_type, entry,
|
||||||
defined_meta):
|
defined_meta):
|
||||||
resource_info = {'type': resource_type}
|
resource_info = {'type': resource_type}
|
||||||
|
|
||||||
|
@ -156,13 +156,15 @@ class BaseCollector(object):
|
||||||
# Or value isn't present.
|
# Or value isn't present.
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if resource_type == 'Virtual Machine':
|
# If the resource is already created, don't update properties below.
|
||||||
resource_info['os_distro'] = self._get_os_distro(entry)
|
if not db_api.resource_get_by_ids(project_id, [resource_id]):
|
||||||
if resource_type == 'Object Storage Container':
|
if resource_type == 'Virtual Machine':
|
||||||
# NOTE(flwang): It's safe to get container name by /, since
|
resource_info['os_distro'] = self._get_os_distro(entry)
|
||||||
# Swift doesn't allow container name with /.
|
if resource_type == 'Object Storage Container':
|
||||||
idx = resource_id.index('/') + 1
|
# NOTE(flwang): It's safe to get container name by /, since
|
||||||
resource_info['name'] = resource_id[idx:]
|
# Swift doesn't allow container name with /.
|
||||||
|
idx = resource_id.index('/') + 1
|
||||||
|
resource_info['name'] = resource_id[idx:]
|
||||||
|
|
||||||
return resource_info
|
return resource_info
|
||||||
|
|
||||||
|
@ -181,19 +183,16 @@ class BaseCollector(object):
|
||||||
if transformed:
|
if transformed:
|
||||||
res_id = mapping.get('res_id_template', '%s') % res_id
|
res_id = mapping.get('res_id_template', '%s') % res_id
|
||||||
res_info = self._get_resource_info(
|
res_info = self._get_resource_info(
|
||||||
|
project_id,
|
||||||
res_id,
|
res_id,
|
||||||
mapping['type'],
|
mapping['type'],
|
||||||
entries[-1],
|
entries[-1],
|
||||||
mapping['metadata']
|
mapping['metadata']
|
||||||
)
|
)
|
||||||
new_res = {
|
|
||||||
'tenant_id': project_id,
|
|
||||||
'info': res_info
|
|
||||||
}
|
|
||||||
|
|
||||||
res = resources.setdefault(res_id, new_res)
|
res = resources.setdefault(res_id, res_info)
|
||||||
res.update({'info': res_info})
|
res.update(res_info)
|
||||||
LOG.debug('resource: %s', res)
|
LOG.debug('resource info: %s', res)
|
||||||
|
|
||||||
for service, volume in transformed.items():
|
for service, volume in transformed.items():
|
||||||
entry = {
|
entry = {
|
||||||
|
|
|
@ -221,14 +221,15 @@ def usages_add(project_id, resources, usage_entries, last_collect):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with session.begin(subtransactions=True):
|
with session.begin(subtransactions=True):
|
||||||
for (id, res) in six.iteritems(resources):
|
for (id, res_info) in six.iteritems(resources):
|
||||||
res_db = _get_resource(session, project_id, id)
|
res_db = _get_resource(session, project_id, id)
|
||||||
if res_db:
|
if res_db:
|
||||||
res_db.info = json.dumps(res['info'])
|
orig_info = json.loads(res_db.info)
|
||||||
|
res_db.info = json.dumps(orig_info.update(res_info))
|
||||||
else:
|
else:
|
||||||
resource_ref = Resource(
|
resource_ref = Resource(
|
||||||
id=id,
|
id=id,
|
||||||
info=json.dumps(res['info']),
|
info=json.dumps(res_info),
|
||||||
tenant_id=project_id,
|
tenant_id=project_id,
|
||||||
created=timestamp
|
created=timestamp
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue