Ceilo transformer: handle multiple metadata keys
The keys for data collected through ceilometer changes from one release/setup to another. This patch handles multiple keys for the ceilometer transformer (flavor, image and AZ are managed). Change-Id: I40045223e85024bd8009bb1a6dd2337dd88c8d69
This commit is contained in:
parent
59f6d327f3
commit
5eec82f0e8
@ -15,6 +15,8 @@
|
||||
#
|
||||
# @author: Stéphane Albert
|
||||
#
|
||||
import six
|
||||
|
||||
from cloudkitty import transformer
|
||||
|
||||
|
||||
@ -23,20 +25,26 @@ class CeilometerTransformer(transformer.BaseTransformer):
|
||||
pass
|
||||
|
||||
def _strip_compute(self, data):
|
||||
res_data = {}
|
||||
res_data['name'] = data.metadata.get('display_name')
|
||||
res_data['flavor'] = data.metadata.get('flavor.name')
|
||||
res_data['vcpus'] = data.metadata.get('vcpus')
|
||||
res_data['memory'] = data.metadata.get('memory_mb')
|
||||
res_data['image_id'] = data.metadata.get('image.id')
|
||||
res_data['availability_zone'] = (
|
||||
data.metadata.get('OS-EXT-AZ.availability_zone')
|
||||
)
|
||||
metadata_map = {
|
||||
'name': ['display_name'],
|
||||
'flavor': ['flavor.name', 'instance_type'],
|
||||
'vcpus': ['vcpus'],
|
||||
'memory': ['memory_mb'],
|
||||
'image_id': ['image.id', 'image_meta.base_image_ref'],
|
||||
'availability_zone': ['availability_zone',
|
||||
'OS-EXT-AZ.availability_zone'],
|
||||
}
|
||||
|
||||
res_data = {}
|
||||
res_data['instance_id'] = data.resource_id
|
||||
res_data['project_id'] = data.project_id
|
||||
res_data['user_id'] = data.user_id
|
||||
|
||||
for key, meta_keys in six.iteritems(metadata_map):
|
||||
for meta_key in meta_keys:
|
||||
if key not in res_data or res_data[key] is None:
|
||||
res_data[key] = data.metadata.get(meta_key)
|
||||
|
||||
res_data['metadata'] = {}
|
||||
for field in data.metadata:
|
||||
if field.startswith('user_metadata'):
|
||||
|
Loading…
Reference in New Issue
Block a user